annotate test-v22/sip_log.c @ 10:3c5734b88c20

sipout-test-v22 put together
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 07 Mar 2024 02:33:49 -0800
parents test-fsk/sip_log.c@26383ed8b79f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement debug logging of SIP Rx & Tx messages.
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/time.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <arpa/inet.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern struct timeval cur_event_time;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static FILE *logfile;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 open_sip_log_file(filename)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *filename;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 logfile = fopen(filename, "a");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (!logfile) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 perror(filename);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(-1);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(0);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 log_common(msg, msglen, sin, dir)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 char *msg, *dir;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 unsigned msglen;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 struct sockaddr_in *sin;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 unsigned sec, ms;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 sec = cur_event_time.tv_sec % 86400;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 ms = cur_event_time.tv_usec / 1000;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 fprintf(logfile, "Msg %s %s:%u %u bytes %02u:%02u:%02u.%03u\n", dir,
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 inet_ntoa(sin->sin_addr), ntohs(sin->sin_port), msglen,
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 sec / 3600, (sec / 60) % 60, sec % 60, ms);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fwrite(msg, 1, msglen, logfile);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 putc('\n', logfile);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fflush(logfile);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 log_sip_msg_rx(msg, msglen, sin)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 char *msg;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 unsigned msglen;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 struct sockaddr_in *sin;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (!logfile)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 log_common(msg, msglen, sin, "from");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 log_sip_msg_tx(msg, msglen, sin)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 char *msg;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 unsigned msglen;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 struct sockaddr_in *sin;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (!logfile)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 log_common(msg, msglen, sin, "to");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }