* This is the parsing function * The socket grammar should be: * ip ':' port '/optional/path' ':' method */
| 170 | * ip ':' port '/optional/path' ':' method |
| 171 | */ |
| 172 | static evi_reply_sock* xmlrpc_parse(str socket) |
| 173 | { |
| 174 | evi_reply_sock *sock = NULL; |
| 175 | unsigned short port = 0; |
| 176 | char *p = NULL; |
| 177 | str host, path=str_init(NULL); |
| 178 | struct hostent *hentity; |
| 179 | int len; |
| 180 | struct xmlrpc_sock_param *params; |
| 181 | |
| 182 | int http_buf_len=0; |
| 183 | |
| 184 | if (!socket.len || !socket.s) { |
| 185 | LM_ERR("no socket specified\n"); |
| 186 | return NULL; |
| 187 | } |
| 188 | |
| 189 | if (!(params=shm_malloc(sizeof(struct xmlrpc_sock_param)))) { |
| 190 | LM_ERR("no more pkg mem!\n"); |
| 191 | return NULL; |
| 192 | } |
| 193 | memset(params, 0, sizeof(struct xmlrpc_sock_param)); |
| 194 | |
| 195 | /* extract host */ |
| 196 | host.s = socket.s; |
| 197 | p = memchr(socket.s, COLON_C, socket.len); |
| 198 | if (!p || p == socket.s) { |
| 199 | LM_ERR("port not specified <%.*s>\n", socket.len, socket.s); |
| 200 | return NULL; |
| 201 | } |
| 202 | host.len = p - socket.s; |
| 203 | |
| 204 | /* used to resolve host */ |
| 205 | *p = '\0'; |
| 206 | /* skip colon */ |
| 207 | socket.s += host.len + 1; |
| 208 | socket.len -= host.len + 1; |
| 209 | |
| 210 | LM_DBG("host is %.*s - remains <%.*s>[%d]\n", host.len, host.s, |
| 211 | socket.len, socket.s, socket.len); |
| 212 | |
| 213 | if (!socket.len || *socket.s == '\0') { |
| 214 | LM_ERR("invalid port number\n"); |
| 215 | return NULL; |
| 216 | } |
| 217 | |
| 218 | p = memchr(socket.s, COLON_C, socket.len); |
| 219 | if (!p || p == socket.s) { |
| 220 | LM_ERR("method not specified <%.*s>\n", socket.len, socket.s); |
| 221 | return NULL; |
| 222 | } |
| 223 | |
| 224 | port = str2s(socket.s, p - socket.s, 0); |
| 225 | if (port == 0) { |
| 226 | /* most probably we've got path */ |
| 227 | if ((path.s=(q_memchr(socket.s, SLASH_C, p-socket.s)))==NULL) { |
| 228 | LM_ERR("malformed port: %.*s\n",(int)(p - socket.s), socket.s); |
| 229 | return NULL; |
nothing calls this directly
no test coverage detected