comparison extensions/dbg_msg_dumps/dbg_msg_dumps.c @ 1245:4b511d9b3def

Change default dump of peer connection, add more options to the dbg_msg_dumps extensions
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 11 Nov 2013 15:30:26 +0800
parents 24a03140a6aa
children 2c09e2545188
comparison
equal deleted inserted replaced
1244:24a03140a6aa 1245:4b511d9b3def
50 #define HK_SNDRCV_FULL 0x0040 /* send+rcv in full mode */ 50 #define HK_SNDRCV_FULL 0x0040 /* send+rcv in full mode */
51 #define HK_SNDRCV_TREE 0x0080 /* send+rcv in tree mode */ 51 #define HK_SNDRCV_TREE 0x0080 /* send+rcv in tree mode */
52 52
53 #define HK_ROUTING_QUIET 0x0100 /* routing decisions are not dumped -- removes the default handling as well */ 53 #define HK_ROUTING_QUIET 0x0100 /* routing decisions are not dumped -- removes the default handling as well */
54 #define HK_ROUTING_COMPACT 0x0200 /* routing decisions in compact mode */ 54 #define HK_ROUTING_COMPACT 0x0200 /* routing decisions in compact mode */
55 #define HK_ROUTING_FULL 0x0400 /* routing decisions in full mode */
56 #define HK_ROUTING_TREE 0x0800 /* routing decisions in tree mode */
55 57
56 #define HK_PEERS_QUIET 0x1000 /* peers connections events are not dumped -- removes the default handling as well */ 58 #define HK_PEERS_QUIET 0x1000 /* peers connections events are not dumped -- removes the default handling as well */
57 #define HK_PEERS_COMPACT 0x2000 /* peers connections events in compact mode */ 59 #define HK_PEERS_COMPACT 0x2000 /* peers connections events in compact mode */
60 #define HK_PEERS_FULL 0x4000 /* peers connections events in full mode */
61 #define HK_PEERS_TREE 0x8000 /* peers connections events in tree mode */
58 /* 62 /*
59 Default value is HK_ERRORS_DETAIL + HK_SNDRCV_DETAIL + HK_PEERS_COMPACT 63 Default value is HK_ERRORS_TREE + HK_SNDRCV_TREE + HK_PEERS_TREE
60 */ 64 */
61 65
62 #include <freeDiameter/extension.h> 66 #include <freeDiameter/extension.h>
63 67
64 static struct fd_hook_hdl *md_hdl[4] = {NULL,NULL,NULL,NULL}; 68 static struct fd_hook_hdl *md_hdl[4] = {NULL,NULL,NULL,NULL};
65 static uint32_t dump_level = HK_ERRORS_TREE | HK_SNDRCV_TREE | HK_PEERS_COMPACT; /* default */ 69 static uint32_t dump_level = HK_ERRORS_TREE | HK_SNDRCV_TREE | HK_PEERS_TREE; /* default */
66 static char * buf = NULL; 70 static char * buf = NULL;
67 static size_t len; 71 static size_t len;
68 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; 72 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
69 73
70 /* The callback called when messages are received and sent */ 74 /* The callback called when messages are received and sent */
117 case HOOK_MESSAGE_SENT: 121 case HOOK_MESSAGE_SENT:
118 LOG_N("SND to '%s':", peer_name); 122 LOG_N("SND to '%s':", peer_name);
119 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL); 123 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL);
120 break; 124 break;
121 125
122 /* The following are not received in this hook */ 126 /* routing */
123 case HOOK_MESSAGE_LOCAL: 127 case HOOK_MESSAGE_LOCAL:
128 LOG_N("ISSUED:");
129 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL);
130 break;
124 case HOOK_MESSAGE_ROUTING_FORWARD: 131 case HOOK_MESSAGE_ROUTING_FORWARD:
132 LOG_N("FORWARDING: %s", buf);
133 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL);
134 break;
125 case HOOK_MESSAGE_ROUTING_LOCAL: 135 case HOOK_MESSAGE_ROUTING_LOCAL:
126 136 LOG_N("DISPATCHING: %s", buf);
137 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL);
138 break;
139
140 /* peers */
127 case HOOK_PEER_CONNECT_FAILED: 141 case HOOK_PEER_CONNECT_FAILED:
142 LOG_N("CONNECT FAILED to %s: %s", peer_name, (char *)other);
143 break;
128 case HOOK_PEER_CONNECT_SUCCESS: 144 case HOOK_PEER_CONNECT_SUCCESS:
129 145 {
146 char protobuf[40];
147 if (peer) {
148 CHECK_FCT_DO(fd_peer_cnx_proto_info(peer, protobuf, sizeof(protobuf)), break );
149 } else {
150 protobuf[0] = '-';
151 protobuf[1] = '\0';
152 }
153 LOG_N("CONNECTED TO '%s' (%s):", peer_name, protobuf);
154 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL);
155 }
156 break;
157
158 /* Not handled */
130 case HOOK_DATA_RECEIVED: 159 case HOOK_DATA_RECEIVED:
131 break; 160 break;
132 } 161 }
133 162
134 CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), ); 163 CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), );
177 break; 206 break;
178 case HOOK_MESSAGE_SENT: 207 case HOOK_MESSAGE_SENT:
179 LOG_N("SND to '%s': %s", peer_name, buf); 208 LOG_N("SND to '%s': %s", peer_name, buf);
180 break; 209 break;
181 210
182 /* The following are not received in this hook */ 211 /* routing */
183 case HOOK_MESSAGE_LOCAL: 212 case HOOK_MESSAGE_LOCAL:
213 LOG_N("ISSUED: %s", buf);
214 break;
184 case HOOK_MESSAGE_ROUTING_FORWARD: 215 case HOOK_MESSAGE_ROUTING_FORWARD:
216 LOG_N("FORWARDING: %s", buf);
217 break;
185 case HOOK_MESSAGE_ROUTING_LOCAL: 218 case HOOK_MESSAGE_ROUTING_LOCAL:
186 219 LOG_N("DISPATCHING: %s", buf);
220 break;
221
222 /* peers */
187 case HOOK_PEER_CONNECT_FAILED: 223 case HOOK_PEER_CONNECT_FAILED:
188 case HOOK_PEER_CONNECT_SUCCESS: 224 LOG_N("CONNECT FAILED to %s: %s", peer_name, (char *)other);
189 225 break;
226 case HOOK_PEER_CONNECT_SUCCESS: {
227 char protobuf[40];
228 if (peer) {
229 CHECK_FCT_DO(fd_peer_cnx_proto_info(peer, protobuf, sizeof(protobuf)), break );
230 } else {
231 protobuf[0] = '-';
232 protobuf[1] = '\0';
233 }
234 LOG_N("CONNECTED TO '%s' (%s): %s", peer_name, protobuf, buf);
235 }
236 break;
237 /* Not handled */
190 case HOOK_DATA_RECEIVED: 238 case HOOK_DATA_RECEIVED:
191 break; 239 break;
192 } 240 }
193 241
194 CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), ); 242 CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), );
307 mask_compact |= (dump_level & HK_ROUTING_COMPACT) ? mask_routing : 0; 355 mask_compact |= (dump_level & HK_ROUTING_COMPACT) ? mask_routing : 0;
308 mask_compact |= (dump_level & HK_PEERS_COMPACT) ? mask_peers : 0; 356 mask_compact |= (dump_level & HK_PEERS_COMPACT) ? mask_peers : 0;
309 357
310 mask_full = (dump_level & HK_ERRORS_FULL) ? mask_errors : 0; 358 mask_full = (dump_level & HK_ERRORS_FULL) ? mask_errors : 0;
311 mask_full |= (dump_level & HK_SNDRCV_FULL) ? mask_sndrcv : 0; 359 mask_full |= (dump_level & HK_SNDRCV_FULL) ? mask_sndrcv : 0;
360 mask_full |= (dump_level & HK_ROUTING_FULL) ? mask_routing : 0;
361 mask_full |= (dump_level & HK_PEERS_FULL) ? mask_peers : 0;
312 362
313 mask_tree = (dump_level & HK_ERRORS_TREE) ? mask_errors : 0; 363 mask_tree = (dump_level & HK_ERRORS_TREE) ? mask_errors : 0;
314 mask_tree |= (dump_level & HK_SNDRCV_TREE) ? mask_sndrcv : 0; 364 mask_tree |= (dump_level & HK_SNDRCV_TREE) ? mask_sndrcv : 0;
365 mask_tree |= (dump_level & HK_ROUTING_TREE) ? mask_routing : 0;
366 mask_tree |= (dump_level & HK_PEERS_TREE) ? mask_peers : 0;
315 367
316 if (mask_quiet) { 368 if (mask_quiet) {
317 CHECK_FCT( fd_hook_register( mask_quiet, md_hook_cb_quiet, NULL, NULL, &md_hdl[0]) ); 369 CHECK_FCT( fd_hook_register( mask_quiet, md_hook_cb_quiet, NULL, NULL, &md_hdl[0]) );
318 } 370 }
319 if (mask_compact) { 371 if (mask_compact) {
"Welcome to our mercurial repository"