FreeCalypso > hg > themwi-system-sw
annotate sip-in/mgw_sock.c @ 94:2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 24 Sep 2022 15:14:50 -0800 |
parents | 02761f1ae5e5 |
children | 372209628038 |
rev | line source |
---|---|
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement our local socket interface to themwi-mgw. |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/un.h> |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <syslog.h> |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "../include/tmgw_ctrl.h" |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket"; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 int mgw_socket; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 open_tmgw_socket() |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 struct sockaddr_un sa; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned sa_len; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int rc; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 mgw_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (mgw_socket < 0) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m"); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return(-1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rc = connect(mgw_socket, (struct sockaddr *) &sa, sa_len); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (rc < 0) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 syslog(LOG_ERR, "connect to %s: %m", tmgw_socket_pathname); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return(-1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 update_max_fd(mgw_socket); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(0); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 void |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 mgw_socket_select() |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 struct tmgw_ctrl_resp msg; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int rc; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 rc = recv(mgw_socket, &msg, sizeof msg, 0); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (rc < 0) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 syslog(LOG_CRIT, "error reading from TMGW socket: %m"); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc != sizeof(struct tmgw_ctrl_resp)) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 syslog(LOG_CRIT, |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 "response packet from TMGW has wrong length: %d bytes", |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 rc); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
56 process_tmgw_response(&msg); |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
58 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
59 send_req_to_tmgw(msg) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
60 struct tmgw_ctrl_req *msg; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
61 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
62 return send(mgw_socket, msg, sizeof(struct tmgw_ctrl_req), 0); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
63 } |