annotate smsc-daemon/send_mt.c @ 15:ce6bcb84ca30

doc/Proto-SMSC-testing: document written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Aug 2023 21:47:19 -0800
parents d9db8661d9f3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module holds the code for the local socket: receiving MT-forwardSM.req
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * messages from proto-smsc-sendmt and forwarding them to our GSUP connection.
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <errno.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <osmocom/core/msgb.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <osmocom/core/socket.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <osmocom/core/select.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <osmocom/core/utils.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include <osmocom/core/logging.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include <osmocom/gsupclient/gsup_client.h>
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "logging.h"
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern struct osmo_gsup_client *g_gc;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static struct osmo_fd socket_ofd;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static int localsock_cb(struct osmo_fd *bfd, unsigned int what)
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 struct msgb *msg;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 int rc;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 msg = osmo_gsup_client_msgb_alloc();
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0);
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (rc <= 0) {
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 LOGP(DMAIN, LOGL_ERROR,
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 "recv from local socket returned %d\n", rc);
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return -1;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 msgb_put(msg, rc);
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 LOGP(DMAIN, LOGL_INFO,
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 "forwarding msg of %d bytes from local socket\n", rc);
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 osmo_gsup_client_send(g_gc, msg);
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return 0;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 void setup_local_socket(const char *pathname)
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 int rc;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 socket_ofd.cb = localsock_cb;
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 rc = osmo_sock_unix_init_ofd(&socket_ofd, SOCK_DGRAM, 0, pathname,
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 OSMO_SOCK_F_BIND);
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (rc < 0) {
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 fprintf(stderr, "error: unable to set up local socket\n");
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 exit(1);
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
d9db8661d9f3 smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }