diff smsc-daemon/send_mt.c @ 14:d9db8661d9f3

smsc-daemon: add local socket for sendmt
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Aug 2023 17:15:30 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/smsc-daemon/send_mt.c	Sun Aug 27 17:15:30 2023 -0800
@@ -0,0 +1,58 @@
+/*
+ * This module holds the code for the local socket: receiving MT-forwardSM.req
+ * messages from proto-smsc-sendmt and forwarding them to our GSUP connection.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/socket.h>
+#include <osmocom/core/select.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/logging.h>
+
+#include <osmocom/gsupclient/gsup_client.h>
+
+#include "logging.h"
+
+extern struct osmo_gsup_client *g_gc;
+
+static struct osmo_fd socket_ofd;
+
+static int localsock_cb(struct osmo_fd *bfd, unsigned int what)
+{
+	struct msgb *msg;
+	int rc;
+
+	msg = osmo_gsup_client_msgb_alloc();
+	rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0);
+	if (rc <= 0) {
+		LOGP(DMAIN, LOGL_ERROR,
+		     "recv from local socket returned %d\n", rc);
+		return -1;
+	}
+	msgb_put(msg, rc);
+	LOGP(DMAIN, LOGL_INFO,
+	     "forwarding msg of %d bytes from local socket\n", rc);
+	osmo_gsup_client_send(g_gc, msg);
+	return 0;
+}
+
+void setup_local_socket(const char *pathname)
+{
+	int rc;
+
+	socket_ofd.cb = localsock_cb;
+	rc = osmo_sock_unix_init_ofd(&socket_ofd, SOCK_DGRAM, 0, pathname,
+				     OSMO_SOCK_F_BIND);
+	if (rc < 0) {
+		fprintf(stderr, "error: unable to set up local socket\n");
+		exit(1);
+	}
+}