FreeCalypso > hg > themwi-system-sw
annotate smpp-trx-sa/log.c @ 247:c6a3fb913c53
top Makefile: mtctest changed to use libnumdb2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 22:39:28 -0800 |
parents | 9d6e8d99d2b1 |
children | a375639e4190 |
rev | line source |
---|---|
222
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements smpp-trx-sa log file output. |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <time.h> |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern FILE *logF; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern time_t curtime; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int init_done; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static char fmt_time[32]; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static void |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 format_time() |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 struct tm *tm; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 tm = gmtime(&curtime); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 sprintf(fmt_time, "%d-%02d-%02dT%02d:%02d:%02dZ", |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 tm->tm_hour, tm->tm_min, tm->tm_sec); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 void |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 log_fatal_error(cause) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 char *cause; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (!init_done) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 format_time(); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fprintf(logF, "\n%s %s\n", fmt_time, cause); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 static void |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 pdu_hexdump(pdu, pdulen) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 u_char *pdu; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 unsigned pdulen; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 unsigned off, chunk; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 int i, c; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 for (off = 0; off < pdulen; off += chunk) { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fprintf(logF, "%04X: ", off); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 chunk = pdulen - off; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (chunk > 16) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 chunk = 16; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 for (i = 0; i < 16; i++) { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (i < chunk) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(logF, "%02X ", pdu[off + i]); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 else |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 fputs(" ", logF); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (i == 7 || i == 15) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 putc(' ', logF); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 for (i = 0; i < chunk; i++) { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 c = pdu[off + i]; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (c < ' ' || c > '~') |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 c = '.'; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 putc(c, logF); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 putc('\n', logF); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 void |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 log_rx_pdu(pdu, pdulen) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 u_char *pdu; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 unsigned pdulen; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 format_time(); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 fprintf(logF, "\n%s Received PDU:\n", fmt_time); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 pdu_hexdump(pdu, pdulen); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 void |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 log_sent_pdu(pdu, pdulen) |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 u_char *pdu; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 unsigned pdulen; |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 { |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 format_time(); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 fprintf(logF, "\n%s Sent PDU:\n", fmt_time); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 pdu_hexdump(pdu, pdulen); |
9d6e8d99d2b1
smpp-trx-sa: new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |