Browse code

lwsc: added inter-module api

- exported lwsc request function to send data to a ws target and proto,
then wait for response data for a specific time interval

Daniel-Constantin Mierla authored on 24/03/2021 15:45:39
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,65 @@
1
+/*
2
+ * Copyright (C) 2021 Daniel-Constantin Mierla (asipto.com)
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ */
20
+
21
+/**
22
+ * @file
23
+ * @brief LWSC - API definitions
24
+ * @ingroup lwsc
25
+ * Module: @ref lwsc
26
+ */
27
+
28
+#ifndef _LWSC_API_H_
29
+#define _LWSC_API_H_
30
+
31
+#include "../../core/str.h"
32
+
33
+typedef int (*lwsc_api_request_f)(str *wsurl, str *wsproto, str *sdata,
34
+		str *rdata, int rtimeout);
35
+
36
+/**
37
+ * @brief Stateless (sl) API structure
38
+ */
39
+typedef struct lwsc_api {
40
+	lwsc_api_request_f  request; /* send and receice data */
41
+} lwsc_api_t;
42
+
43
+typedef int (*bind_lwsc_f)(lwsc_api_t* api);
44
+
45
+/**
46
+ * @brief Load the LWSX API
47
+ */
48
+static inline int lwsc_load_api(lwsc_api_t *lwscb)
49
+{
50
+	bind_lwsc_f bindlwsc;
51
+
52
+	bindlwsc = (bind_lwsc_f)find_export("bind_lwsc", 0, 0);
53
+	if ( bindlwsc == 0) {
54
+		LM_ERR("cannot find bind_lwsc exported function\n");
55
+		return -1;
56
+	}
57
+	if (bindlwsc(lwscb)==-1)
58
+	{
59
+		LM_ERR("cannot bind lwsc api\n");
60
+		return -1;
61
+	}
62
+	return 0;
63
+}
64
+
65
+#endif
... ...
@@ -36,12 +36,15 @@
36 36
 #include "../../core/kemi.h"
37 37
 #include "../../core/parser/parse_param.h"
38 38
 
39
+#include "api.h"
40
+
39 41
 
40 42
 MODULE_VERSION
41 43
 
42 44
 static int  mod_init(void);
43 45
 static int  child_init(int);
44 46
 static void mod_destroy(void);
47
+static int bind_lwsc(lwsc_api_t* api);
45 48
 
46 49
 static int w_lwsc_request(sip_msg_t* msg, char* pwsurl, char* pdata);
47 50
 static int w_lwsc_notify(sip_msg_t* msg, char* pwsurl, char* pdata);
... ...
@@ -57,6 +60,8 @@ static cmd_export_t cmds[]={
57 60
 		fixup_spve_all, 0, ANY_ROUTE},
58 61
 	{"lwsc_notify", (cmd_function)w_lwsc_notify, 2,
59 62
 		fixup_spve_all, 0, ANY_ROUTE},
63
+	{"bind_lwsc",   (cmd_function)bind_lwsc, 0,
64
+		0, 0, 0},
60 65
 	{0, 0, 0, 0, 0, 0}
61 66
 };
62 67
 
... ...
@@ -759,6 +764,20 @@ static int lwsc_pv_parse_name(pv_spec_t *sp, str *in)
759 764
 	return 0;
760 765
 }
761 766
 
767
+/**
768
+ * @brief bind functions to LWSC API structure
769
+ */
770
+static int bind_lwsc(lwsc_api_t* api)
771
+{
772
+	if (!api) {
773
+		LM_ERR("invalid parameter value\n");
774
+		return -1;
775
+	}
776
+	api->request = lwsc_api_request;
777
+
778
+	return 0;
779
+}
780
+
762 781
 /**
763 782
  *
764 783
  */