- more work an new libosip API

This commit is contained in:
Thomas Ries 2005-02-19 09:36:22 +00:00
parent 571374928e
commit 9c40c4454d
7 changed files with 57 additions and 40 deletions

View File

@ -1,5 +1,6 @@
0.5.11
======
19-Feb-2005: - more work an new libosip API
13-Feb-2005: - made compile with libosip2-2.2.0 (change of libosip2 API)
0.5.10

View File

@ -81,6 +81,7 @@ int proxy_request (sip_ticket_t *ticket) {
osip_uri_t *url;
int port;
char *buffer;
int buflen;
osip_message_t *request;
struct sockaddr_in *from;
@ -516,14 +517,14 @@ int proxy_request (sip_ticket_t *ticket) {
* RFC 3261, Section 16.6 step 10
* Proxy Behavior - Forward the new request
*/
sts = sip_message_to_str(request, &buffer);
sts = sip_message_to_str(request, &buffer, &buflen);
if (sts != 0) {
ERROR("proxy_request: sip_message_to_str failed");
return STS_FAILURE;
}
sipsock_send(sendto_addr, port, ticket->protocol,
buffer, strlen(buffer));
buffer, buflen);
osip_free (buffer);
/*
@ -565,6 +566,7 @@ int proxy_response (sip_ticket_t *ticket) {
osip_via_t *via;
int port;
char *buffer;
int buflen;
osip_message_t *response;
struct sockaddr_in *from;
@ -910,14 +912,14 @@ int proxy_response (sip_ticket_t *ticket) {
}
}
sts = sip_message_to_str(response, &buffer);
sts = sip_message_to_str(response, &buffer, &buflen);
if (sts != 0) {
ERROR("proxy_response: sip_message_to_str failed");
return STS_FAILURE;
}
sipsock_send(sendto_addr, port, ticket->protocol,
buffer, strlen(buffer));
buffer, buflen);
osip_free (buffer);
return STS_SUCCESS;
}
@ -938,6 +940,7 @@ int proxy_rewrite_invitation_body(osip_message_t *mymsg, int direction){
struct in_addr map_addr, addr_sess, addr_media, outside_addr, inside_addr;
int sts;
char *bodybuff;
int bodybuflen;
char clen[8]; /* content length: probably never more than 7 digits !*/
int map_port, msg_port;
int media_stream_no;
@ -966,28 +969,31 @@ int proxy_rewrite_invitation_body(osip_message_t *mymsg, int direction){
}
}
sts = sip_body_to_str(body, &bodybuff);
sts = sip_body_to_str(body, &bodybuff, &bodybuflen);
if (sts != 0) {
ERROR("rewrite_invitation_body: unable to sip_body_to_str");
}
sts = sdp_message_init(&sdp);
sts = sdp_message_parse (sdp, bodybuff);
osip_free(bodybuff);
if (sts != 0) {
ERROR("rewrite_invitation_body: unable to sdp_message_parse body");
DUMP_BUFFER(-1, bodybuff, bodybuflen);
osip_free(bodybuff);
sdp_message_free(sdp);
return STS_FAILURE;
}
osip_free(bodybuff);
if (configuration.debuglevel)
{ /* just dump the buffer */
char *tmp, *tmp2;
int tmplen;
sts = osip_message_get_body(mymsg, 0, &body);
sts = sip_body_to_str(body, &tmp);
sts = sip_body_to_str(body, &tmp, &tmplen);
osip_content_length_to_str(mymsg->content_length, &tmp2);
DEBUG("Body before rewrite (clen=%s, strlen=%i):\n%s\n----",
tmp2, strlen(tmp), tmp);
tmp2, tmplen, tmp);
osip_free(tmp);
osip_free(tmp2);
}
@ -1208,12 +1214,13 @@ if (configuration.debuglevel)
/* dump new body */
sdp_message_to_str(sdp, &bodybuff);
bodybuflen=strlen(bodybuff);
/* free sdp structure */
sdp_message_free(sdp);
/* include new body */
sip_message_set_body(mymsg, bodybuff);
sip_message_set_body(mymsg, bodybuff, bodybuflen);
if (sts != 0) {
ERROR("rewrite_invitation_body: unable to sip_message_set_body body");
}
@ -1221,7 +1228,7 @@ if (configuration.debuglevel)
/* free content length resource and include new one*/
osip_content_length_free(mymsg->content_length);
mymsg->content_length=NULL;
sprintf(clen,"%i",strlen(bodybuff));
sprintf(clen,"%i",bodybuflen);
sts = osip_message_set_content_length(mymsg, clen);
/* free old body */
@ -1230,11 +1237,12 @@ if (configuration.debuglevel)
if (configuration.debuglevel)
{ /* just dump the buffer */
char *tmp, *tmp2;
int tmplen;
sts = osip_message_get_body(mymsg, 0, &body);
sts = sip_body_to_str(body, &tmp);
sts = sip_body_to_str(body, &tmp, &tmplen);
osip_content_length_to_str(mymsg->content_length, &tmp2);
DEBUG("Body after rewrite (clen=%s, strlen=%i):\n%s\n----",
tmp2, strlen(tmp), tmp);
tmp2, tmplen, tmp);
osip_free(tmp);
osip_free(tmp2);
}

View File

@ -495,6 +495,7 @@ int register_response(sip_ticket_t *ticket, int flag) {
osip_via_t *via;
int port;
char *buffer;
int buflen;
struct in_addr addr;
osip_header_t *expires_hdr;
@ -550,7 +551,7 @@ int register_response(sip_ticket_t *ticket, int flag) {
}
}
sts = sip_message_to_str(response, &buffer);
sts = sip_message_to_str(response, &buffer, &buflen);
if (sts != 0) {
ERROR("register_response: msg_2char failed");
return STS_FAILURE;
@ -563,7 +564,7 @@ int register_response(sip_ticket_t *ticket, int flag) {
port=configuration.sip_listen_port;
}
sipsock_send(addr, port, ticket->protocol, buffer, strlen(buffer));
sipsock_send(addr, port, ticket->protocol, buffer, buflen);
/* free the resources */
osip_message_free(response);

View File

@ -30,49 +30,53 @@ static char const ident[]="$Id$";
* argument for a number of functions used by siproxd.
*/
int sip_message_parse(osip_message_t * sip, const char *buf) {
int sip_message_parse(osip_message_t * sip, const char *buf, int len) {
#ifdef HAVE_FUNC_OSIP_MESSAGE_PARSE_3
return osip_message_parse(sip, buf, strlen(buf));
return osip_message_parse(sip, buf, len);
#else
return osip_message_parse(sip, buf);
#endif
}
int sip_message_to_str(osip_message_t * sip, char **dest) {
int sip_message_to_str(osip_message_t * sip, char **dest, int *len) {
#ifdef HAVE_FUNC_OSIP_MESSAGE_TO_STR_3
int sts;
size_t len;
sts = osip_message_to_str(sip, dest, &len);
sts = osip_message_to_str(sip, dest, len);
/*
* NULL termination (libosip2-2.2.0 does NOT do this properly,
* there is always one byte too much :-( )
*/
(*dest)[len]='\0';
(*dest)[*len]='\0';
return sts;
#else
return osip_message_to_str(sip, dest);
int sts;
sts = osip_message_to_str(sip, dest);
*len = strlen(*dest);
return sts;
#endif
}
int sip_body_to_str(const osip_body_t * body, char **dest) {
int sip_body_to_str(const osip_body_t * body, char **dest, int *len) {
#ifdef HAVE_FUNC_OSIP_BODY_TO_STR_3
int sts;
size_t len;
sts = osip_body_to_str(body, dest, &len);
sts = osip_body_to_str(body, dest, len);
/*
* NULL termination (libosip2-2.2.0 does NOT do this properly,
* there is always one byte too much :-( )
*/
(*dest)[len]='\0';
(*dest)[*len]='\0';
return sts;
#else
return osip_body_to_str(body, &dest);
int sts;
sts = osip_body_to_str(body, &dest);
*len = strlen(*dest);
return sts;
#endif
}
int sip_message_set_body(osip_message_t * sip, const char *buf) {
int sip_message_set_body(osip_message_t * sip, const char *buf, int len) {
#ifdef HAVE_FUNC_OSIP_MESSAGE_SET_BODY_3
return osip_message_set_body(sip, buf, strlen(buf));
return osip_message_set_body(sip, buf, len);
#else
return osip_message_set_body(sip, buf);
#endif

View File

@ -533,6 +533,7 @@ int sip_gen_response(sip_ticket_t *ticket, int code) {
osip_via_t *via;
int port;
char *buffer;
int buflen;
struct in_addr addr;
/* create the response template */
@ -563,7 +564,7 @@ int sip_gen_response(sip_ticket_t *ticket, int code) {
}
}
sts = sip_message_to_str(response, &buffer);
sts = sip_message_to_str(response, &buffer, &buflen);
if (sts != 0) {
ERROR("sip_gen_response: msg_2char failed");
return STS_FAILURE;
@ -577,7 +578,7 @@ int sip_gen_response(sip_ticket_t *ticket, int code) {
}
/* send to destination */
sipsock_send(addr, port, ticket->protocol, buffer, strlen(buffer));
sipsock_send(addr, port, ticket->protocol, buffer, buflen);
/* free the resources */
osip_message_free(response);

View File

@ -82,6 +82,7 @@ int main (int argc, char *argv[])
{
int sts;
int i;
int buflen;
int access;
char buff [BUFFER_SIZE];
sip_ticket_t ticket;
@ -291,8 +292,9 @@ int main (int argc, char *argv[])
/* got input, process */
DEBUGC(DBCLASS_BABBLE,"back from sipsock_wait");
i=sipsock_read(&buff, sizeof(buff)-1, &ticket.from, &ticket.protocol);
buff[i]='\0';
buflen=sipsock_read(&buff, sizeof(buff)-1, &ticket.from,
&ticket.protocol);
buff[buflen]='\0';
/* evaluate the access lists (IP based filter)*/
access=accesslist_check(ticket.from);
@ -302,7 +304,7 @@ int main (int argc, char *argv[])
}
/* integrity checks */
sts=security_check_raw(buff, i);
sts=security_check_raw(buff, buflen);
if (sts != STS_SUCCESS) {
DEBUGC(DBCLASS_SIP,"security check (raw) failed");
continue; /* there are no resources to free */
@ -321,10 +323,10 @@ int main (int argc, char *argv[])
* Proxy Behavior - Request Validation - Reasonable Syntax
* (parse the received message)
*/
sts=sip_message_parse(ticket.sipmsg, buff);
sts=sip_message_parse(ticket.sipmsg, buff, buflen);
if (sts != 0) {
ERROR("sip_message_parse() failed... this is not good");
DUMP_BUFFER(-1, buff, i);
DUMP_BUFFER(-1, buff, buflen);
goto end_loop; /* skip and free resources */
}
@ -332,7 +334,7 @@ int main (int argc, char *argv[])
sts=security_check_sip(&ticket);
if (sts != STS_SUCCESS) {
ERROR("security_check_sip() failed... this is not good");
DUMP_BUFFER(-1, buff, i);
DUMP_BUFFER(-1, buff, buflen);
goto end_loop; /* skip and free resources */
}

View File

@ -202,10 +202,10 @@ int fwapi_stop_rtp(int rtp_direction,
struct in_addr remote_ipaddr, int remote_port);
/* sip_layer.c */
int sip_message_parse(osip_message_t * sip, const char *buf);
int sip_message_to_str(osip_message_t * sip, char **dest);
int sip_body_to_str(const osip_body_t * body, char **dest);
int sip_message_set_body(osip_message_t * sip, const char *buf);
int sip_message_parse(osip_message_t * sip, const char *buf, int len);
int sip_message_to_str(osip_message_t * sip, char **dest, int *len);
int sip_body_to_str(const osip_body_t * body, char **dest, int *len);
int sip_message_set_body(osip_message_t * sip, const char *buf, int len);
/*