Browse code

Unix domain socket interface

Jan Janak authored on 05/03/2004 19:27:23
Showing 4 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #include "../../sr_module.h"
42 42
 #include "domain.h"
43 43
 #include "fifo.h"
44
+#include "unixsock.h"
44 45
 
45 46
 /*
46 47
  * Module management function prototypes
... ...
@@ -157,6 +158,12 @@ static int mod_init(void)
157 158
 		/* Initialize fifo interface */
158 159
 		(void)init_domain_fifo();
159 160
 
161
+		if (init_domain_unixsock() < 0) {
162
+			LOG(L_ERR, "domain:mod_init(): Error while initializing unix socket interface\n");
163
+			db_close(db_handle);
164
+			return -1;
165
+		}
166
+
160 167
 		/* Initializing hash tables and hash table variable */
161 168
 		hash_table_1 = (struct domain_list **)shm_malloc(sizeof(struct domain_list *) * HASH_SIZE);
162 169
 		if (hash_table_1 == 0) {
... ...
@@ -32,6 +32,7 @@
32 32
 #define _HASH_H
33 33
 
34 34
 #include <stdio.h>
35
+#include "domain_mod.h"
35 36
 
36 37
 extern int hash_table_install (struct domain_list **hash_table, char *domain);
37 38
 int hash_table_lookup (str *domain);
38 39
new file mode 100644
... ...
@@ -0,0 +1,108 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * UNIX Socket Interface
5
+ *
6
+ * Copyright (C) 2002-2004 FhG FOKUS
7
+ *
8
+ * This file is part of ser, a free SIP server.
9
+ *
10
+ * ser 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
+ * For a license to use the ser software under conditions
16
+ * other than those described here, or to purchase support for this
17
+ * software, please contact iptel.org by e-mail at the following addresses:
18
+ *    info@iptel.org
19
+ *
20
+ * ser is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License 
26
+ * along with this program; if not, write to the Free Software 
27
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ */
29
+
30
+#include "hash.h"
31
+#include "../../unixsock_server.h"
32
+#include "../../dprint.h"
33
+#include "../../db/db.h"
34
+#include "../../ut.h"
35
+#include "unixsock.h"
36
+#include "fifo.h" /* Because of reload_domain_table */
37
+
38
+
39
+/*
40
+ * Fifo function to reload domain table
41
+ */
42
+static int domain_reload(str* msg)
43
+{
44
+	if (reload_domain_table () == 1) {
45
+		unixsock_reply_asciiz("200 OK\n");
46
+		unixsock_reply_send();
47
+		return 0;
48
+	} else {
49
+		unixsock_reply_asciiz("400 Domain table reload failed\n");
50
+		unixsock_reply_send();
51
+		return -1;
52
+	}
53
+}
54
+
55
+
56
+/* Print domains stored in hash table */
57
+static int hash_table_print_unixsock(struct domain_list **hash_table)
58
+{
59
+	int i;
60
+	struct domain_list *np;
61
+
62
+	for (i = 0; i < HASH_SIZE; i++) {
63
+		np = hash_table[i];
64
+		while (np) {
65
+			if (unixsock_reply_printf("%4d %.*s\n", i, np->domain.len, ZSW(np->domain.s)) < 0) {
66
+				return -1;
67
+			}
68
+			np = np->next;
69
+		}
70
+	}
71
+	return 0;
72
+}
73
+
74
+
75
+/*
76
+ * Fifo function to print domains from current hash table
77
+ */
78
+static int domain_dump(str* msg)
79
+{
80
+	unixsock_reply_asciiz("200 OK\n");
81
+	if (hash_table_print_unixsock(*hash_table) < 0) {
82
+		unixsock_reply_reset();
83
+		unixsock_reply_asciiz("500 Could not print the contents\n");
84
+		unixsock_reply_send();
85
+		return -1;
86
+	}
87
+	unixsock_reply_send();
88
+	return 0;
89
+}
90
+
91
+
92
+/*
93
+ * Register domain unixsock functions
94
+ */
95
+int init_domain_unixsock(void) 
96
+{
97
+	if (unixsock_register_cmd("domain_reload", domain_reload) < 0) {
98
+		LOG(L_ERR, "init_domain_unixsock: Cannot register domain_reload\n");
99
+		return -1;
100
+	}
101
+
102
+	if (unixsock_register_cmd("domain_dump", domain_dump) < 0) {
103
+		LOG(L_ERR, "init_domain_unixsock: Cannot register domain_dump\n");
104
+		return -1;
105
+	}
106
+
107
+	return 0;
108
+}
0 109
new file mode 100644
... ...
@@ -0,0 +1,39 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * UNIX Socket Interface
5
+ *
6
+ * Copyright (C) 2002-2004 FhG FOKUS
7
+ *
8
+ * This file is part of ser, a free SIP server.
9
+ *
10
+ * ser 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
+ * For a license to use the ser software under conditions
16
+ * other than those described here, or to purchase support for this
17
+ * software, please contact iptel.org by e-mail at the following addresses:
18
+ *    info@iptel.org
19
+ *
20
+ * ser is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License 
26
+ * along with this program; if not, write to the Free Software 
27
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
+ */
29
+
30
+#ifndef _UNIXSOCK_H
31
+#define _UNIXSOCK_H 1
32
+
33
+/*
34
+ * Register domain unixsock functions
35
+ */
36
+int init_domain_unixsock(void);
37
+
38
+
39
+#endif /* _UNIXSOCK_H */