Browse Source

implement fallback pcre for unparsable udp commands

git.mgm/mediaproxy-ng/2.0
Richard Fuchs 14 years ago
parent
commit
d6c60a8c3b
2 changed files with 28 additions and 1 deletions
  1. +27
    -1
      daemon/control_udp.c
  2. +1
    -0
      daemon/control_udp.h

+ 27
- 1
daemon/control_udp.c View File

@ -48,7 +48,31 @@ static void control_udp_incoming(int fd, void *p) {
ret = pcre_exec(u->parse_re, u->parse_ree, buf, ret, 0, 0, ovec, G_N_ELEMENTS(ovec));
if (ret <= 0) {
mylog(LOG_WARNING, "Unable to parse command line from udp:" DF ": %s", DP(sin), buf);
ret = pcre_exec(u->fallback_re, NULL, buf, ret, 0, 0, ovec, G_N_ELEMENTS(ovec));
if (ret <= 0) {
mylog(LOG_WARNING, "Unable to parse command line from udp:" DF ": %s", DP(sin), buf);
return;
}
mylog(LOG_WARNING, "Failed to properly parse UDP command line '%s' from "DF", using fallback RE", buf, DP(sin));
ZERO(mh);
mh.msg_name = &sin;
mh.msg_namelen = sizeof(sin);
mh.msg_iov = iov;
mh.msg_iovlen = 4;
iov[0].iov_base = (void *) out[1];
iov[0].iov_len = strlen(out[1]);
iov[1].iov_base = (void *) out[3];
iov[1].iov_len = strlen(out[3]);
iov[2].iov_base = (void *) out[2];
iov[2].iov_len = strlen(out[2]);
iov[3].iov_base = "\n";
iov[3].iov_len = 1;
sendmsg(fd, &mh, 0);
return;
}
@ -165,6 +189,8 @@ struct control_udp *control_udp_new(struct poller *p, u_int32_t ip, u_int16_t po
"^(\\S+)\\s+(?:([ul])(\\S*)\\s+(\\S+)\\s+([\\d.]+)\\s+(\\d+)\\s+(\\S+?)(?:;\\S+)?(?:\\s+(\\S+?)(?:;\\S+)?(?:\\s+.*)?)?\r?\n?$|(d)(\\S*)\\s+(\\S+)|(v)(\\S*)(?:\\s+(\\S+))?)",
PCRE_DOLLAR_ENDONLY | PCRE_DOTALL | PCRE_CASELESS, &errptr, &erroff, NULL);
c->parse_ree = pcre_study(c->parse_re, 0, &errptr);
/* cookie cmd flags callid addr port */
c->fallback_re = pcre_compile("^(\\S+)\\s+[ul]\\S*\\s+\\S+(\\s+\\S+)(\\s+\\S+)", PCRE_DOLLAR_ENDONLY | PCRE_DOTALL | PCRE_CASELESS, &errptr, &erroff, NULL);
ZERO(i);
i.fd = fd;


+ 1
- 0
daemon/control_udp.h View File

@ -26,6 +26,7 @@ struct control_udp {
pcre *parse_re;
pcre_extra *parse_ree;
pcre *fallback_re;
GHashTable *fresh_cookies, *stale_cookies;
GStringChunk *fresh_chunks, *stale_chunks;
time_t oven_time;


Loading…
Cancel
Save