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

Function stream_parse

modules/event_stream/event_stream.c:169–284  ·  view source on GitHub ↗

* This is the parsing function * The socket grammar should be: * ip ':' port ['/'method] */

Source from the content-addressed store, hash-verified

167 * ip ':' port ['/'method]
168 */
169static evi_reply_sock* stream_parse(str socket)
170{
171 evi_reply_sock *sock = NULL;
172 unsigned short port = 0;
173 char *p = NULL;
174 str *method;
175 str host;
176 struct hostent *hentity;
177 int len, err;
178
179 if (!socket.len || !socket.s) {
180 LM_ERR("no socket specified\n");
181 return NULL;
182 }
183
184 /* extract host */
185 host.s = socket.s;
186 p = memchr(socket.s, COLON_C, socket.len);
187 if (!p || p == socket.s) {
188 LM_ERR("port not specified <%.*s>\n", socket.len, socket.s);
189 return NULL;
190 }
191 host.len = p - socket.s;
192
193 /* used to resolve host */
194 *p = '\0';
195 /* skip colon */
196 socket.s += host.len + 1;
197 socket.len -= host.len + 1;
198
199 LM_DBG("host is %.*s - remaining <%.*s>[%d]\n", host.len, host.s,
200 socket.len, socket.s, socket.len);
201
202 if (!socket.len || *socket.s == '\0') {
203 LM_ERR("invalid port number\n");
204 return NULL;
205 }
206
207 p = memchr(socket.s, SLASH_C, socket.len);
208 if (!p) {
209 /* if we do not have a method, we use the event's name */
210 p = socket.s + socket.len;
211 }
212
213 port = str2s(socket.s, p - socket.s, &err);
214 if (port == 0 || err != 0) {
215 LM_ERR("malformed port: %.*s\n",(int)(p - socket.s), socket.s);
216 return NULL;
217 }
218
219 /* jump over ':' */
220 socket.len = socket.len - (p - socket.s);
221 socket.s = p;
222
223 LM_DBG("port is %hu - remains <%.*s>[%d]\n",
224 port, socket.len, socket.s, socket.len);
225
226 if (socket.len) {

Callers

nothing calls this directly

Calls 5

str2sFunction · 0.85
shm_mallocFunction · 0.85
resolvehostFunction · 0.85
hostent2suFunction · 0.85
shm_freeFunction · 0.85

Tested by

no test coverage detected