Browse code

- new files containing xmpp api

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1436 689a6050-402a-0410-94f2-e92a70836424

Daniel-Constantin Mierla authored on 20/12/2006 09:50:35
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,118 @@
1
+
2
+/*
3
+ * $Id$
4
+ *
5
+ * XMPP Module
6
+ * This file is part of openser, a free SIP server.
7
+ *
8
+ * Copyright (C) 2006 Voice Sistem S.R.L.
9
+ *
10
+ * openser is free software; you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation; either version 2 of the License, or
13
+ * (at your option) any later version
14
+ *
15
+ * openser is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with this program; if not, write to the Free Software
22
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
+ *
24
+ * 
25
+ */
26
+
27
+
28
+#include <stdlib.h>
29
+#include <string.h>
30
+
31
+#include "../../dprint.h"
32
+#include "../../error.h"
33
+#include "../../mem/shm_mem.h"
34
+#include "xmpp_api.h"
35
+
36
+
37
+xmpp_cb_list_t *_xmpp_cb_list = 0;
38
+
39
+
40
+
41
+int init_xmpp_cb_list()
42
+{
43
+	_xmpp_cb_list = (xmpp_cb_list_t*)shm_malloc(sizeof(xmpp_cb_list_t));
44
+	if (_xmpp_cb_list==0) {
45
+		LOG(L_CRIT,"ERROR:xmpp:init_xmpp_cb_list: no more shared mem\n");
46
+		return -1;
47
+	}
48
+	memset(_xmpp_cb_list, 0, sizeof(xmpp_cb_list_t));
49
+	return 1;
50
+}
51
+
52
+
53
+void destroy_xmpp_cb_list()
54
+{
55
+	xmpp_callback_t *it, *it1;
56
+
57
+	if (_xmpp_cb_list==0)
58
+		return;
59
+
60
+	for(it=_xmpp_cb_list->first; it; ) {
61
+		it1 = it;
62
+		it = it->next;
63
+		shm_free(it1);
64
+	}
65
+
66
+	shm_free(_xmpp_cb_list);
67
+	_xmpp_cb_list = 0;
68
+}
69
+
70
+
71
+
72
+/* register a callback function 'f' for 'types' mask of events;
73
+*/
74
+int register_xmpp_cb( int types, xmpp_cb_f f, void *param )
75
+{
76
+	xmpp_callback_t *it;
77
+
78
+	/* check null functions */
79
+	if (f==0) {
80
+		LOG(L_CRIT, "BUG:register_xmpp_cb: null callback function\n");
81
+		return E_BUG;
82
+	}
83
+
84
+	/* build callback structure */
85
+	if (!(it=(xmpp_callback_t*)shm_malloc(sizeof(xmpp_callback_t))))
86
+	{
87
+		LOG(L_ERR, "ERROR:register_xmpp_cb: out of shm. mem\n");
88
+		return E_OUT_OF_MEM;
89
+	}
90
+
91
+	memset(it, 0, sizeof(xmpp_callback_t));
92
+	it->next = _xmpp_cb_list->first;
93
+	_xmpp_cb_list->first = it;
94
+	_xmpp_cb_list->types |= types;
95
+
96
+	it->cbf = f;
97
+	it->cbp = param;
98
+	it->types = types;
99
+
100
+	return 1;
101
+}
102
+
103
+
104
+int bind_xmpp(xmpp_api_t* api)
105
+{
106
+	if (api==NULL)
107
+	{
108
+		LOG(L_ERR, "bind_xmpp: Invalid parameter value\n");
109
+		return -1;
110
+	}
111
+	api->xpacket    = xmpp_send_xpacket;
112
+	api->xmessage   = xmpp_send_xmessage;
113
+	api->xsubscribe = xmpp_send_xsubscribe;
114
+	api->xnotify    = xmpp_send_xnotify;
115
+
116
+	return 0;
117
+}
118
+
0 119
new file mode 100644
... ...
@@ -0,0 +1,104 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * XMPP Module
5
+ * This file is part of openser, a free SIP server.
6
+ *
7
+ * Copyright (C) 2006 Voice Sistem S.R.L.
8
+ *
9
+ * openser is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version
13
+ *
14
+ * openser is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program; if not, write to the Free Software
21
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+ *
23
+ * 
24
+ */
25
+
26
+#ifndef _XMPP_API_H_
27
+#define _XMPP_API_H_
28
+
29
+#define XMPP_RCV_MESSAGE      (1<<0)
30
+#define XMPP_RCV_PSUBSCRIBE   (1<<1)
31
+#define XMPP_RCV_PNOTIFY      (1<<2)
32
+
33
+typedef void (xmpp_cb_f) (void *msg, int type, void *param);
34
+typedef int (*register_xmpp_cb_t)(int types, xmpp_cb_f f, void *param);
35
+
36
+
37
+typedef struct xmpp_callback_
38
+{
39
+	int types;                   /* types of events that trigger the callback*/
40
+	xmpp_cb_f *cbf;              /* callback function */
41
+	void *cbp;                   /* param to be passed to callback function */
42
+	struct xmpp_callback_ *next;
43
+} xmpp_callback_t;
44
+
45
+typedef struct xmpp_cb_list_
46
+{
47
+	xmpp_callback_t *first;
48
+	int types;
49
+} xmpp_cb_list_t;
50
+
51
+
52
+extern xmpp_cb_list_t*  _xmpp_cb_list;
53
+
54
+
55
+#define xmpp_isset_cb_type(_types_) \
56
+	((_xmpp_cb_list->types)|(_types_) )
57
+
58
+
59
+int init_xmpp_cb_list();
60
+
61
+void destroy_xmpp_cb_list();
62
+
63
+
64
+int register_xmpp_cb( int types, xmpp_cb_f f, void *param );
65
+
66
+/* run all transaction callbacks for an event type */
67
+static inline void run_xmpp_callbacks( int type, void *msg)
68
+{
69
+	xmpp_callback_t *it;
70
+
71
+	for (it=_xmpp_cb_list->first; it; it=it->next)  {
72
+		if(it->types&type) {
73
+			DBG("DBG:xmpp:cb: msg=%p, callback type %d/%d fired\n",
74
+				msg, type, it->types );
75
+			it->cbf( msg, type, it->cbp );
76
+		}
77
+	}
78
+}
79
+
80
+typedef int (*xmpp_send_xpacket_f)(str *from, str *to, str *msg, str *id);
81
+int xmpp_send_xpacket(str *from, str *to, str *msg, str *id);
82
+
83
+typedef int (*xmpp_send_xmessage_f)(str *from, str *to, str *msg, str *id);
84
+int xmpp_send_xmessage(str *from, str *to, str *msg, str *id);
85
+
86
+typedef int (*xmpp_send_xsubscribe_f)(str *from, str *to, str *msg, str *id);
87
+int xmpp_send_xsubscribe(str *from, str *to, str *msg, str *id);
88
+
89
+typedef int (*xmpp_send_xnotify_f)(str *from, str *to, str *msg, str *id);
90
+int xmpp_send_xnotify(str *from, str *to, str *msg, str *id);
91
+
92
+typedef struct xmpp_api_
93
+{
94
+	xmpp_send_xpacket_f xpacket;
95
+	xmpp_send_xmessage_f xmessage;
96
+	xmpp_send_xsubscribe_f xsubscribe;
97
+	xmpp_send_xnotify_f xnotify;
98
+} xmpp_api_t;
99
+
100
+typedef int (*bind_xmpp_t)(xmpp_api_t* api);
101
+int bind_xmpp(xmpp_api_t* api);
102
+
103
+#endif
104
+