comparison libfdproto/messages.c @ 895:fbf77629cb7b

Added received and sent timestamps in the messages; added logs on emission and reception
author Sebastien Decugis <sdecugis@freediameter.net>
date Fri, 30 Nov 2012 00:44:10 +0100
parents 43fb27a9037f
children 4382d7420e65
comparison
equal deleted inserted replaced
894:43fb27a9037f 895:fbf77629cb7b
125 void * data; 125 void * data;
126 struct timespec timeout; 126 struct timespec timeout;
127 } msg_cb; /* Callback to be called when an answer is received, if not NULL */ 127 } msg_cb; /* Callback to be called when an answer is received, if not NULL */
128 DiamId_t msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */ 128 DiamId_t msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */
129 size_t msg_src_id_len; /* cached length of this string */ 129 size_t msg_src_id_len; /* cached length of this string */
130 struct timespec msg_ts; /* Timestamp associated with the message */ 130 struct timespec msg_ts_rcv; /* Timestamp when this message was received from the network */
131 struct timespec msg_ts_sent; /* Timestamp when this message was sent to the network */
131 132
132 }; 133 };
133 134
134 /* Macro to compute the message header size */ 135 /* Macro to compute the message header size */
135 #define GETMSGHDRSZ() 20 136 #define GETMSGHDRSZ() 20
675 676
676 /* Dump a msg_t object */ 677 /* Dump a msg_t object */
677 static int obj_dump_msg (struct msg * msg, int indent, char **outstr, size_t *offset, size_t *outlen ) 678 static int obj_dump_msg (struct msg * msg, int indent, char **outstr, size_t *offset, size_t *outlen )
678 { 679 {
679 int ret = 0; 680 int ret = 0;
681 char buftime[256];
682 size_t tsoffset = 0;
683 struct tm tm;
680 684
681 CHECK_FCT( dump_add_str(outstr, offset, outlen, "%*sMSG: %p\n", INOBJHDRVAL, msg) ); 685 CHECK_FCT( dump_add_str(outstr, offset, outlen, "%*sMSG: %p\n", INOBJHDRVAL, msg) );
682 686
683 if (!CHECK_MSG(msg)) { 687 if (!CHECK_MSG(msg)) {
684 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID!\n", INOBJHDRVAL) ); 688 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID!\n", INOBJHDRVAL) );
685 return 0; 689 return 0;
690 }
691
692 if ((msg->msg_ts_rcv.tv_sec != 0) || (msg->msg_ts_rcv.tv_nsec != 0)) {
693 tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_rcv.tv_sec , &tm ));
694 tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_rcv.tv_nsec / 1000);
695 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Received: %s\n", INOBJHDRVAL, buftime) );
696 }
697 if ((msg->msg_ts_sent.tv_sec != 0) || (msg->msg_ts_sent.tv_nsec != 0)) {
698 tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_sent.tv_sec , &tm ));
699 tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_sent.tv_nsec / 1000);
700 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Sent : %s\n", INOBJHDRVAL, buftime) );
686 } 701 }
687 702
688 if (!msg->msg_model) { 703 if (!msg->msg_model) {
689 704
690 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model)\n", INOBJHDRVAL) ); 705 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model)\n", INOBJHDRVAL) );
731 return 0; 746 return 0;
732 } 747 }
733 748
734 if (!avp->avp_model) { 749 if (!avp->avp_model) {
735 750
736 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model)\n", INOBJHDRVAL) ); 751 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model resolved)\n", INOBJHDRVAL) );
737 752
738 } else { 753 } else {
739 754
740 enum dict_object_type dicttype; 755 enum dict_object_type dicttype;
741 struct dict_avp_data dictdata; 756 struct dict_avp_data dictdata;
823 838
824 /* dump next object */ 839 /* dump next object */
825 } while (ref); 840 } while (ref);
826 841
827 /* now really output this in one shot, so it is not interrupted */ 842 /* now really output this in one shot, so it is not interrupted */
828 fd_log_debug_fstr(fstr, "%s", outstr); 843 fd_log_debug_fstr(fstr, "%s\n", outstr);
829 844
830 free(outstr); 845 free(outstr);
831 } 846 }
832 void fd_msg_dump_fstr_one ( struct msg * msg, FILE * fstr ) /* just the header */ 847 void fd_msg_dump_fstr_one ( struct msg * msg, FILE * fstr ) /* just the header */
833 { 848 {
835 size_t offset, outlen; 850 size_t offset, outlen;
836 CHECK_FCT_DO( dump_init_str(&outstr, &offset, &outlen), { fd_log_debug_fstr(fstr, "Error initializing string for dumping %p\n", msg); return; } ); 851 CHECK_FCT_DO( dump_init_str(&outstr, &offset, &outlen), { fd_log_debug_fstr(fstr, "Error initializing string for dumping %p\n", msg); return; } );
837 CHECK_FCT_DO( msg_dump_intern ( NONE, msg, 2, &outstr, &offset, &outlen ), 852 CHECK_FCT_DO( msg_dump_intern ( NONE, msg, 2, &outstr, &offset, &outlen ),
838 fd_log_debug_fstr(fstr, "Error while dumping %p\n", msg) ); 853 fd_log_debug_fstr(fstr, "Error while dumping %p\n", msg) );
839 /* now really output this in one shot, so it is not interrupted */ 854 /* now really output this in one shot, so it is not interrupted */
840 fd_log_debug_fstr(fstr, "%s", outstr); 855 fd_log_debug_fstr(fstr, "%s\n", outstr);
841 856
842 free(outstr); 857 free(outstr);
843 } 858 }
844 859
845 /* Dump a message content -- for debug mostly */ 860 /* Dump a message content -- for debug mostly */
1149 *diamidlen = msg->msg_src_id_len; 1164 *diamidlen = msg->msg_src_id_len;
1150 1165
1151 /* done */ 1166 /* done */
1152 return 0; 1167 return 0;
1153 } 1168 }
1169
1170 int fd_msg_ts_set_recv( struct msg * msg, struct timespec * ts )
1171 {
1172 TRACE_ENTRY("%p %p", msg, ts);
1173
1174 /* Check we received valid parameters */
1175 CHECK_PARAMS( CHECK_MSG(msg) );
1176 CHECK_PARAMS( ts );
1177
1178 memcpy(&msg->msg_ts_rcv, ts, sizeof(struct timespec));
1179 return 0;
1180 }
1181
1182 int fd_msg_ts_get_recv( struct msg * msg, struct timespec * ts )
1183 {
1184 TRACE_ENTRY("%p %p", msg, ts);
1185
1186 /* Check we received valid parameters */
1187 CHECK_PARAMS( CHECK_MSG(msg) );
1188 CHECK_PARAMS( ts );
1189
1190 memcpy(ts, &msg->msg_ts_rcv, sizeof(struct timespec));
1191 return 0;
1192 }
1193
1194 int fd_msg_ts_set_sent( struct msg * msg, struct timespec * ts )
1195 {
1196 TRACE_ENTRY("%p %p", msg, ts);
1197
1198 /* Check we received valid parameters */
1199 CHECK_PARAMS( CHECK_MSG(msg) );
1200 CHECK_PARAMS( ts );
1201
1202 memcpy(&msg->msg_ts_sent, ts, sizeof(struct timespec));
1203 return 0;
1204 }
1205
1206 int fd_msg_ts_get_sent( struct msg * msg, struct timespec * ts )
1207 {
1208 TRACE_ENTRY("%p %p", msg, ts);
1209
1210 /* Check we received valid parameters */
1211 CHECK_PARAMS( CHECK_MSG(msg) );
1212 CHECK_PARAMS( ts );
1213
1214 memcpy(ts, &msg->msg_ts_sent, sizeof(struct timespec));
1215 return 0;
1216 }
1217
1154 1218
1155 /* Retrieve the session of the message */ 1219 /* Retrieve the session of the message */
1156 int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * new) 1220 int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * new)
1157 { 1221 {
1158 struct avp * avp; 1222 struct avp * avp;
"Welcome to our mercurial repository"