* This is the parsing function * The socket grammar should be: * ip ':' port ['/'method] */
| 167 | * ip ':' port ['/'method] |
| 168 | */ |
| 169 | static 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) { |
nothing calls this directly
no test coverage detected