Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nathelper: contact_only option #31

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions modules/nathelper/nathelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,8 @@ nh_timer(unsigned int ticks, void *timer_idx)
int rval;
void *buf, *cp;
str c;
str recv;
str *dst_uri;
str opt;
str path;
str ruid;
Expand Down Expand Up @@ -2111,6 +2113,9 @@ nh_timer(unsigned int ticks, void *timer_idx)
break;
c.s = (char*)cp + sizeof(c.len);
cp = (char*)cp + sizeof(c.len) + c.len;
memcpy(&(recv.len), cp, sizeof(recv.len));
recv.s = (char*)cp + sizeof(recv.len);
cp = (char*)cp + sizeof(recv.len) + recv.len;
memcpy( &send_sock, cp, sizeof(send_sock));
cp = (char*)cp + sizeof(send_sock);
memcpy( &flags, cp, sizeof(flags));
Expand All @@ -2127,6 +2132,9 @@ nh_timer(unsigned int ticks, void *timer_idx)
if ((flags & natping_disable_flag)) /* always 0 if natping_disable_flag not set */
continue;

if(recv.len>0) dst_uri = &recv;
else dst_uri = &c;

/* determin the destination */
if ( path.len && (flags&sipping_flag)!=0 ) {
/* send to first URI in path */
Expand All @@ -2149,14 +2157,14 @@ nh_timer(unsigned int ticks, void *timer_idx)
LM_ERR("could not parse path host for udpping_from_path\n");
continue;
}
if (parse_uri(c.s, c.len, &curi) < 0) {
LM_ERR("can't parse contact uri\n");
if (parse_uri(dst_uri->s, dst_uri->len, &curi) < 0) {
LM_ERR("can't parse contact/received uri\n");
continue;
}
} else {
/* send to the contact/received */
if (parse_uri(c.s, c.len, &curi) < 0) {
LM_ERR("can't parse contact uri\n");
if (parse_uri(dst_uri->s, dst_uri->len, &curi) < 0) {
LM_ERR("can't parse contact/received uri\n");
continue;
}
}
Expand Down
123 changes: 58 additions & 65 deletions modules/usrloc/dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
int port, proto;
char *p;
str addr;
str recv;
str path;
str ruid;
str host;
Expand Down Expand Up @@ -163,17 +164,26 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
for(i = 0; i < RES_ROW_N(res); i++) {
row = RES_ROWS(res) + i;


/* received */
addr.s = (char*)VAL_STRING(ROW_VALUES(row));
if ( VAL_NULL(ROW_VALUES(row)) || addr.s==0 || addr.s[0]==0 ) {
/* contact */
addr.s = (char*)VAL_STRING(ROW_VALUES(row)+1);
if (VAL_NULL(ROW_VALUES(row)+1) || addr.s==0 || addr.s[0]==0) {
LM_ERR("empty contact -> skipping\n");
continue;
}
recv.s = (char*)VAL_STRING(ROW_VALUES(row));
if ( VAL_NULL(ROW_VALUES(row)) || recv.s==0 || recv.s[0]==0 ) {
recv.s = NULL;
recv.len = 0;
}
else {
recv.len = strlen(recv.s);
}

/* contact */
addr.s = (char*)VAL_STRING(ROW_VALUES(row)+1);
if (VAL_NULL(ROW_VALUES(row)+1) || addr.s==0 || addr.s[0]==0) {
LM_ERR("empty contact -> skipping\n");
continue;
}
else {
addr.len = strlen(addr.s);
}
addr.len = strlen(addr.s);

/* path */
path.s = (char*)VAL_STRING(ROW_VALUES(row)+4);
Expand All @@ -194,6 +204,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
}

needed = (int)(sizeof(addr.len) + addr.len
+ sizeof(recv.len) + recv.len
+ sizeof(sock) + sizeof(dbflags)
+ sizeof(path.len) + path.len
+ sizeof(ruid.len) + ruid.len
Expand All @@ -203,12 +214,21 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
continue;
}

/* write received/contact */
/* write contact */
memcpy(cp, &addr.len, sizeof(addr.len));
cp = (char*)cp + sizeof(addr.len);
memcpy(cp, addr.s, addr.len);
cp = (char*)cp + addr.len;

/* write received */
memcpy(cp, &recv.len, sizeof(recv.len));
cp = (char*)cp + sizeof(recv.len);
/* copy received only if exist */
if(recv.len){
memcpy(cp, recv.s, recv.len);
cp = (char*)cp + recv.len;
}

/* sock */
p = (char*)VAL_STRING(ROW_VALUES(row) + 2);
if (VAL_NULL(ROW_VALUES(row)+2) || p==0 || p[0]==0){
Expand Down Expand Up @@ -347,65 +367,38 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
}
}

if (c->received.s) {
needed = (int)(sizeof(c->received.len)
+ c->received.len
+ sizeof(c->sock) + sizeof(c->cflags)
+ sizeof(c->path.len) + c->path.len
+ sizeof(c->ruid.len) + c->ruid.len
+ sizeof(r->aorhash));
if (len >= needed) {
memcpy(cp,&c->received.len,sizeof(c->received.len));
cp = (char*)cp + sizeof(c->received.len);
memcpy(cp, c->received.s, c->received.len);
cp = (char*)cp + c->received.len;
memcpy(cp, &c->sock, sizeof(c->sock));
cp = (char*)cp + sizeof(c->sock);
memcpy(cp, &c->cflags, sizeof(c->cflags));
cp = (char*)cp + sizeof(c->cflags);
memcpy(cp, &c->path.len, sizeof(c->path.len));
cp = (char*)cp + sizeof(c->path.len);
memcpy(cp, c->path.s, c->path.len);
cp = (char*)cp + c->path.len;
memcpy(cp, &c->ruid.len, sizeof(c->ruid.len));
cp = (char*)cp + sizeof(c->ruid.len);
memcpy(cp, c->ruid.s, c->ruid.len);
cp = (char*)cp + c->ruid.len;
memcpy(cp, &r->aorhash, sizeof(r->aorhash));
cp = (char*)cp + sizeof(r->aorhash);
len -= needed;
} else {
shortage += needed;
}
} else {
needed = (int)(sizeof(c->c.len) + c->c.len
needed = (int)(sizeof(c->c.len) + c->c.len
+ sizeof(c->received.len) + c->received.len
+ sizeof(c->sock) + sizeof(c->cflags)
+ sizeof(c->path.len) + c->path.len
+ sizeof(c->ruid.len) + c->ruid.len
+ sizeof(r->aorhash));
if (len >= needed) {
memcpy(cp, &c->c.len, sizeof(c->c.len));
cp = (char*)cp + sizeof(c->c.len);
memcpy(cp, c->c.s, c->c.len);
cp = (char*)cp + c->c.len;
memcpy(cp, &c->sock, sizeof(c->sock));
cp = (char*)cp + sizeof(c->sock);
memcpy(cp, &c->cflags, sizeof(c->cflags));
cp = (char*)cp + sizeof(c->cflags);
memcpy(cp, &c->path.len, sizeof(c->path.len));
cp = (char*)cp + sizeof(c->path.len);
memcpy(cp, c->path.s, c->path.len);
cp = (char*)cp + c->path.len;
memcpy(cp, &c->ruid.len, sizeof(c->ruid.len));
cp = (char*)cp + sizeof(c->ruid.len);
memcpy(cp, c->ruid.s, c->ruid.len);
cp = (char*)cp + c->ruid.len;
memcpy(cp, &r->aorhash, sizeof(r->aorhash));
cp = (char*)cp + sizeof(r->aorhash);
len -= needed;
} else {
shortage += needed;
}
if (len >= needed) {
memcpy(cp, &c->c.len, sizeof(c->c.len));
cp = (char*)cp + sizeof(c->c.len);
memcpy(cp, c->c.s, c->c.len);
cp = (char*)cp + c->c.len;
memcpy(cp,&c->received.len,sizeof(c->received.len));
cp = (char*)cp + sizeof(c->received.len);
memcpy(cp, c->received.s, c->received.len);
cp = (char*)cp + c->received.len;
memcpy(cp, &c->sock, sizeof(c->sock));
cp = (char*)cp + sizeof(c->sock);
memcpy(cp, &c->cflags, sizeof(c->cflags));
cp = (char*)cp + sizeof(c->cflags);
memcpy(cp, &c->path.len, sizeof(c->path.len));
cp = (char*)cp + sizeof(c->path.len);
memcpy(cp, c->path.s, c->path.len);
cp = (char*)cp + c->path.len;
memcpy(cp, &c->ruid.len, sizeof(c->ruid.len));
cp = (char*)cp + sizeof(c->ruid.len);
memcpy(cp, c->ruid.s, c->ruid.len);
cp = (char*)cp + c->ruid.len;
memcpy(cp, &r->aorhash, sizeof(r->aorhash));
cp = (char*)cp + sizeof(r->aorhash);
len -= needed;
} else {
shortage += needed;
}
}
}
Expand Down