Browse code

- module migrated to the new interface for creating additional processes - fixed bug in creating the communication pipe between SIP workers and XMPP processes

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

Bogdan-Andrei Iancu authored on 21/08/2007 16:11:14
Showing 1 changed files
... ...
@@ -108,12 +108,12 @@ MODULE_VERSION
108 108
 
109 109
 struct tm_binds tmb;
110 110
 
111
-static int mod_init(void);
112
-static int child_init(int rank);
113
-static int cmd_send_message(struct sip_msg* msg, char* _foo, char* _bar);
111
+static int  mod_init(void);
112
+static void xmpp_process(int rank);
113
+static int  cmd_send_message(struct sip_msg* msg, char* _foo, char* _bar);
114 114
 void destroy(void);
115 115
 
116
-static int pipe_fd = -1;
116
+static int pipe_fds[2] = {-1,-1};
117 117
 
118 118
 /*
119 119
  * Configuration
... ...
@@ -130,13 +130,18 @@ char *xmpp_password = "secret";
130 130
 #define DEFAULT_COMPONENT_PORT 5347
131 131
 #define DEFAULT_SERVER_PORT 5269
132 132
 
133
+static proc_export_t procs[] = {
134
+	{"XMPP receiver",  0,  0, xmpp_process, 1 },
135
+	{0,0,0}
136
+};
137
+
138
+
133 139
 /*
134 140
  * Exported functions
135 141
  */
136 142
 static cmd_export_t cmds[] = {
137 143
 	{"xmpp_send_message", (cmd_function)cmd_send_message, 0, 0, REQUEST_ROUTE},
138 144
 	{"bind_xmpp",         (cmd_function)bind_xmpp,        0, 0, 0},
139
-
140 145
 	{0, 0, 0, 0}
141 146
 };
142 147
 
... ...
@@ -165,11 +170,11 @@ struct module_exports exports = {
165 170
 	0,               /* exported statistics */
166 171
 	0,               /* exported MI functions */
167 172
 	0,               /* exported pseudo-variables */
168
-	0,               /* extra processes */
173
+	procs,           /* extra processes */
169 174
 	mod_init,        /* Initialization function */
170 175
 	0,               /* Response function */
171 176
 	destroy,         /* Destroy function */
172
-	child_init,      /* Child init function */
177
+	0,               /* Child init function */
173 178
 };
174 179
 
175 180
 /*
... ...
@@ -205,48 +210,30 @@ static int mod_init(void) {
205 210
 		return -1;
206 211
 	}
207 212
 
213
+	if (pipe(pipe_fds) < 0) {
214
+		LOG(L_ERR, "xmpp: cannot pipe()\n");
215
+		return -1;
216
+	}
217
+
208 218
 	return 0;
209 219
 }
210 220
 
211
-static int child_init(int rank)
212
-{
213
-	int pid;
214
-	int fds[2];
215 221
 
222
+static void xmpp_process(int rank)
223
+{
216 224
 	/* if this blasted server had a decent I/O loop, we'd
217 225
 	 * just add our socket to it and connect().
218 226
 	 */
219
-	
220
-	DBG("xmpp: child_init: initializing child <%d>\n", rank);
221
-	if (rank == 1) {
222
-		if (pipe(fds) < 0) {
223
-			LOG(L_ERR, "xmpp: cannot pipe()\n");
224
-			return -1;
225
-		}
226
-		if ((pid = fork()) < 0) {
227
-			LOG(L_ERR, "xmpp: cannot fork()\n");
228
-			return -1;
229
-		}
230
-
231
-		if (pid) {
232
-			/* parent */
233
-			close(fds[0]);
234
-			pipe_fd = fds[1];
235
-		} else {
236
-			/* child */
237
-			close(fds[1]);
238
-			
239
-			DBG("xmpp: started child connection process\n");
240
-			if (!strcmp(backend, "component"))
241
-				xmpp_component_child_process(fds[0]);
242
-			else if (!strcmp(backend, "server"))
243
-				xmpp_server_child_process(fds[0]);
244
-			_exit(127);
245
-		}
246
-	}
247
-	return 0;
227
+	close(pipe_fds[1]);
228
+
229
+	DBG("xmpp: started child connection process\n");
230
+	if (!strcmp(backend, "component"))
231
+		xmpp_component_child_process(pipe_fds[0]);
232
+	else if (!strcmp(backend, "server"))
233
+		xmpp_server_child_process(pipe_fds[0]);
248 234
 }
249 235
 
236
+
250 237
 /* to be done */
251 238
 void destroy(void)
252 239
 {
... ...
@@ -321,7 +308,7 @@ static int xmpp_send_pipe_cmd(enum xmpp_pipe_cmd_type type, str *from, str *to,
321 308
 	cmd->body = shm_strdup(body);
322 309
 	cmd->id = shm_strdup(id);
323 310
 
324
-	if (write(pipe_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) {
311
+	if (write(pipe_fds[1], &cmd, sizeof(cmd)) != sizeof(cmd)) {
325 312
 		LOG(L_ERR, "xmpp: unable to write to command pipe: %s\n", strerror(errno));
326 313
 		xmpp_free_pipe_cmd(cmd);
327 314
 		return -1;