| 1 | /* | |
| 2 | * Copyright 1999-2006 University of Chicago | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | ||
| 17 | ||
| 18 | #include "globus_handler.h" | |
| 19 | #include "globus_soap_message.h" | |
| 20 | #include "globus_soap_message_handle.h" | |
| 21 | #include "version.h" | |
| 22 | ||
| 23 | static | |
| 24 | globus_result_t | |
| 25 | globus_handler_debug_request_invoke( | |
| 26 | globus_soap_message_handle_t message_handle, | |
| 27 | globus_result_t result) | |
| 28 | 0 | { |
| 29 | char * buffer; | |
| 30 | size_t length; | |
| 31 | globus_abstime_t current_time; | |
| 32 | char buf[256]; | |
| 33 | ||
| 34 | 0 | result = globus_soap_message_get_marked_buffers( |
| 35 | message_handle, | |
| 36 | NULL, NULL, | |
| 37 | &buffer, | |
| 38 | &length); | |
| 39 | 0 | if(result == GLOBUS_SUCCESS) |
| 40 | { | |
| 41 | 0 | GlobusTimeAbstimeGetCurrent(current_time); |
| 42 | 0 | sprintf(buf, "%lu.%.9lu", |
| 43 | (unsigned long) current_time.tv_sec, | |
| 44 | (unsigned long) current_time.tv_nsec); | |
| 45 | 0 | fprintf(stderr, |
| 46 | "\n=== REQUEST MESSAGE (length %lu) (time %s) ===\n", | |
| 47 | (unsigned long) length, buf); | |
| 48 | 0 | fwrite(buffer, length, 1, stderr); |
| 49 | 0 | fprintf(stderr, |
| 50 | "\n----------------------------------------------\n"); | |
| 51 | } | |
| 52 | ||
| 53 | 0 | return result; |
| 54 | } | |
| 55 | ||
| 56 | static | |
| 57 | globus_result_t | |
| 58 | globus_handler_debug_response_invoke( | |
| 59 | globus_soap_message_handle_t message_handle, | |
| 60 | globus_result_t result) | |
| 61 | 0 | { |
| 62 | char * buffer; | |
| 63 | size_t length; | |
| 64 | globus_abstime_t current_time; | |
| 65 | char buf[256]; | |
| 66 | ||
| 67 | 0 | result = globus_soap_message_get_marked_buffers( |
| 68 | message_handle, | |
| 69 | NULL, NULL, | |
| 70 | &buffer, | |
| 71 | &length); | |
| 72 | 0 | if(result == GLOBUS_SUCCESS) |
| 73 | { | |
| 74 | 0 | GlobusTimeAbstimeGetCurrent(current_time); |
| 75 | 0 | sprintf(buf, "%lu.%.9lu", |
| 76 | (unsigned long) current_time.tv_sec, | |
| 77 | (unsigned long) current_time.tv_nsec); | |
| 78 | 0 | fprintf(stderr, |
| 79 | "\n=== RESPONSE MESSAGE (length %lu) (time %s) ===\n", | |
| 80 | (unsigned long) length, buf); | |
| 81 | 0 | fwrite(buffer, length, 1, stderr); |
| 82 | 0 | fprintf(stderr, |
| 83 | "\n----------------------------------------------\n"); | |
| 84 | } | |
| 85 | ||
| 86 | 0 | return result; |
| 87 | } | |
| 88 | ||
| 89 | globus_handler_descriptor_t globus_l_handler_debug_descriptor = | |
| 90 | { | |
| 91 | NULL, | |
| 92 | globus_handler_debug_request_invoke, | |
| 93 | NULL, NULL, | |
| 94 | globus_handler_debug_response_invoke, | |
| 95 | NULL, NULL, NULL | |
| 96 | }; | |
| 97 | ||
| 98 | static | |
| 99 | int | |
| 100 | globus_l_handler_debug_activate(void); | |
| 101 | ||
| 102 | static | |
| 103 | int | |
| 104 | globus_l_handler_debug_deactivate(void); | |
| 105 | ||
| 106 | GlobusExtensionDefineModule(globus_handler_debug) = | |
| 107 | { | |
| 108 | "debug", | |
| 109 | globus_l_handler_debug_activate, | |
| 110 | globus_l_handler_debug_deactivate, | |
| 111 | NULL, | |
| 112 | NULL, | |
| 113 | &local_version | |
| 114 | }; | |
| 115 | ||
| 116 | static | |
| 117 | int | |
| 118 | globus_l_handler_debug_activate(void) | |
| 119 | 0 | { |
| 120 | 0 | int res = 0; |
| 121 | ||
| 122 | 0 | res = globus_extension_registry_add( |
| 123 | GLOBUS_HANDLER_REGISTRY, | |
| 124 | "globus_handler_debug", | |
| 125 | GlobusExtensionMyModule(globus_handler_debug), | |
| 126 | &globus_l_handler_debug_descriptor); | |
| 127 | if(res != GLOBUS_SUCCESS) | |
| 128 | { | |
| 129 | 0 | goto exit; |
| 130 | } | |
| 131 | ||
| 132 | 0 | exit: |
| 133 | 0 | return res; |
| 134 | } | |
| 135 | ||
| 136 | static | |
| 137 | int | |
| 138 | globus_l_handler_debug_deactivate(void) | |
| 139 | 0 | { |
| 140 | 0 | globus_extension_registry_remove( |
| 141 | GLOBUS_HANDLER_REGISTRY, | |
| 142 | "globus_handler_debug"); | |
| 143 | ||
| 144 | 0 | return 0; |