MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / xmpp_component_child_process

Function xmpp_component_child_process

modules/xmpp/xmpp_component.c:178–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176}
177
178int xmpp_component_child_process(int data_pipe)
179{
180 int fd, maxfd, rv;
181 fd_set fdset;
182 xode_pool pool;
183 xode_stream stream;
184 struct xmpp_private_data priv;
185 struct xmpp_pipe_cmd *cmd;
186
187 while (1) {
188 fd = net_connect(xmpp_host, xmpp_port);
189 if (fd < 0) {
190 sleep(3);
191 continue;
192 }
193 curr_fd = fd;
194
195 priv.fd = fd;
196 priv.running = 1;
197
198 pool = xode_pool_new();
199 stream = xode_stream_new(pool, stream_node_callback, &priv);
200
201 net_printf(fd,
202 "<?xml version='1.0'?>"
203 "<stream:stream xmlns='jabber:component:accept' to='%s' "
204 "version='1.0' xmlns:stream='http://etherx.jabber.org/streams'>",
205 xmpp_domain);
206
207 while (priv.running) {
208 FD_ZERO(&fdset);
209 FD_SET(data_pipe, &fdset);
210 FD_SET(fd, &fdset);
211 maxfd = fd > data_pipe ? fd : data_pipe;
212 rv = select(maxfd + 1, &fdset, NULL, NULL, NULL);
213
214 if (rv < 0) {
215 if (errno == EINTR) {
216 continue;
217 }
218 LM_ERR("select() failed: %s\n", strerror(errno));
219 } else if (!rv) {
220 /* timeout */
221 } else if (FD_ISSET(fd, &fdset)) {
222 char *buf = net_read_static(fd);
223
224 if (!buf)
225 /* connection closed */
226 break;
227
228 LM_DBG("server read\n[%s]\n", buf);
229 xode_stream_eat(stream, buf, strlen(buf));
230 } else if (FD_ISSET(data_pipe, &fdset)) {
231 if (read(data_pipe, &cmd, sizeof(cmd)) != sizeof(cmd)) {
232 LM_ERR("failed to read from command pipe: %s\n",
233 strerror(errno));
234 } else {
235 xmpp_component_net_send(cmd, &priv);

Callers 1

xmpp_processFunction · 0.85

Calls 8

net_connectFunction · 0.85
net_printfFunction · 0.85
net_read_staticFunction · 0.85
xmpp_component_net_sendFunction · 0.85
xode_pool_newFunction · 0.70
xode_stream_newFunction · 0.70
xode_stream_eatFunction · 0.70
xode_pool_freeFunction · 0.70

Tested by

no test coverage detected