- simplified SIP RX & TX routines

This commit is contained in:
Thomas Ries
2004-04-25 22:50:00 +00:00
parent 0e60d731de
commit d9aec2834b
8 changed files with 64 additions and 64 deletions
+1
View File
@@ -1,6 +1,7 @@
0.5.6
=====
11-Apr-2004: - on termination, stop all active RTP streams
24-Apr-2004: - simplified SIP RX & TX routines
0.5.5
=====
+3 -3
View File
@@ -43,7 +43,6 @@ extern struct siproxd_config configuration;
extern int errno;
extern struct urlmap_s urlmap[]; /* URL mapping table */
extern struct lcl_if_s local_addresses;
extern int sip_socket; /* sending SIP datagrams */
/*
@@ -547,7 +546,7 @@ int proxy_request (osip_message_t *request, struct sockaddr_in *from) {
return STS_FAILURE;
}
sipsock_send_udp(&sip_socket, sendto_addr, port, buffer, strlen(buffer), 1);
sipsock_send(sendto_addr, port, buffer, strlen(buffer));
osip_free (buffer);
/*
@@ -730,6 +729,7 @@ int proxy_response (osip_message_t *response, struct sockaddr_in *from) {
(osip_strncasecmp(ua_hdr->hvalue,"grandstream", 11)==0) &&
(MSG_IS_RESPONSE_FOR(response,"SUBSCRIBE")) &&
(MSG_TEST_CODE(response, 202))) {
DEBUGC(DBCLASS_PROXY, "proxy_request: Grandstream hack 202->404");
response->status_code=404;
}
}
@@ -811,7 +811,7 @@ int proxy_response (osip_message_t *response, struct sockaddr_in *from) {
return STS_FAILURE;
}
sipsock_send_udp(&sip_socket, sendto_addr, port, buffer, strlen(buffer), 1);
sipsock_send(sendto_addr, port, buffer, strlen(buffer));
osip_free (buffer);
return STS_SUCCESS;
}
+1 -3
View File
@@ -42,8 +42,6 @@ extern struct siproxd_config configuration;
struct urlmap_s urlmap[URLMAP_SIZE]; /* URL mapping table */
extern int sip_socket; /* sending SIP datagrams */
extern int errno;
/*
* initialize the URL mapping table
@@ -536,7 +534,7 @@ int register_response(osip_message_t *request, int flag) {
port=configuration.sip_listen_port;
}
sipsock_send_udp(&sip_socket, addr, port, buffer, strlen(buffer), 1);
sipsock_send(addr, port, buffer, strlen(buffer));
/* free the resources */
osip_message_free(response);
+26 -16
View File
@@ -299,24 +299,34 @@ static void *rtpproxy_main(void *arg) {
} /* rtp_tx_sock == 0 */
if (rtp_proxytable[i].rtp_tx_sock != 0) {
/* write to dest via socket rtp_tx_sock */
sts = sipsock_send_udp(&rtp_proxytable[i].rtp_tx_sock,
rtp_proxytable[i].remote_ipaddr,
rtp_proxytable[i].remote_port,
rtp_buff, count, 0); /* don't dump it */
/* write to dest via socket rtp_tx_sock */
struct sockaddr_in dst_addr;
dst_addr.sin_family = AF_INET;
memcpy(&dst_addr.sin_addr.s_addr,
&rtp_proxytable[i].remote_ipaddr,
sizeof(struct in_addr));
dst_addr.sin_port= htons(rtp_proxytable[i].remote_port);
if (sts != STS_SUCCESS) {
/* if sendto() fails with bad filedescriptor,
* this means that the opposite stream has been
* canceled or timed out.
* we should then cancel this stream as well.*/
sts = sendto(rtp_proxytable[i].rtp_tx_sock, rtp_buff,
count, 0, (const struct sockaddr *)&dst_addr,
(socklen_t)sizeof(dst_addr));
if (sts == -1) {
if (errno != ECONNREFUSED) {
ERROR("sendto() [%s:%i size=%i] call failed: %s",
utils_inet_ntoa(rtp_proxytable[i].remote_ipaddr),
rtp_proxytable[i].remote_port, count, strerror(errno));
WARN("stopping opposite stream");
/* don't lock the mutex, as we own the lock */
callid.number=rtp_proxytable[i].callid_number;
callid.host=rtp_proxytable[i].callid_host;
rtp_relay_stop_fwd(&callid,
rtp_proxytable[i].direction, 1);
/* if sendto() fails with bad filedescriptor,
* this means that the opposite stream has been
* canceled or timed out.
* we should then cancel this stream as well.*/
WARN("stopping opposite stream");
/* don't lock the mutex, as we own the lock */
callid.number=rtp_proxytable[i].callid_number;
callid.host=rtp_proxytable[i].callid_host;
rtp_relay_stop_fwd(&callid, rtp_proxytable[i].direction, 1);
}
}
}
} /* count > 0 */
+1 -3
View File
@@ -50,7 +50,6 @@ static char const ident[]="$Id$";
extern struct siproxd_config configuration;
extern int h_errno;
extern int sip_socket; /* sending SIP datagrams */
extern struct urlmap_s urlmap[]; /* URL mapping table */
@@ -571,8 +570,7 @@ int sip_gen_response(osip_message_t *request, int code) {
}
/* send to destination */
sipsock_send_udp(&sip_socket, addr, port,
buffer, strlen(buffer), 1);
sipsock_send(addr, port, buffer, strlen(buffer));
/* free the resources */
osip_message_free(response);
+4 -7
View File
@@ -43,9 +43,6 @@ static char const ident[]="$Id$";
/* configuration storage */
struct siproxd_config configuration;
/* socket used for sending SIP datagrams */
int sip_socket=0;
/* -h help option text */
static const char str_helpmsg[] =
PACKAGE "-" VERSION "-" BUILDSTR " (c) 2002-2004 Thomas Ries\n"
@@ -216,7 +213,7 @@ int main (int argc, char *argv[])
parser_init();
/* listen for incoming messages */
sts=sipsock_listen(&sip_socket);
sts=sipsock_listen();
if (sts == STS_FAILURE) {
/* failure to allocate SIP socket... */
ERROR("unable to bind to SIP listening socket - aborting");
@@ -238,7 +235,7 @@ int main (int argc, char *argv[])
while (!exit_program) {
DEBUGC(DBCLASS_BABBLE,"going into sip_wait\n");
while (sipsock_wait(sip_socket)<=0) {
while (sipsock_wait()<=0) {
/* got no input, here by timeout. do aging */
register_agemap();
@@ -260,7 +257,7 @@ int main (int argc, char *argv[])
/* got input, process */
DEBUGC(DBCLASS_BABBLE,"back from sip_wait");
i=sipsock_read(sip_socket, &buff, sizeof(buff)-1, &from);
i=sipsock_read(&buff, sizeof(buff)-1, &from);
buff[i]='\0';
/* evaluate the access lists (IP based filter)*/
@@ -456,7 +453,7 @@ int main (int argc, char *argv[])
} /* while TRUE */
exit_prg:
/* dump current knwon SIP registrations */
/* dump current known SIP registrations */
register_shut();
INFO("properly terminating siproxd");
+5 -5
View File
@@ -28,12 +28,12 @@
/* function returns STS_* status values vvv */
/* sock.c */
int sipsock_listen (int *sock); /*X*/
int sipsock_wait(int sock);
int sipsock_read(int sock, void *buf, size_t bufsize,
int sipsock_listen (void); /*X*/
int sipsock_wait();
int sipsock_read(void *buf, size_t bufsize,
struct sockaddr_in *from);
int sipsock_send_udp(int *sock, struct in_addr addr, int port, /*X*/
char *buffer, int size, int allowdump);
int sipsock_send(struct in_addr addr, int port, /*X*/
char *buffer, int size);
int sockbind(struct in_addr ipaddr, int localport, int errflg);
/* register.c */
+23 -27
View File
@@ -44,6 +44,10 @@ static char const ident[]="$Id$";
/* configuration storage */
extern struct siproxd_config configuration;
/* socket used for sending SIP datagrams */
int sip_udp_socket=0;
/*
* binds to SIP UDP socket for listening to incoming packets
*
@@ -51,17 +55,15 @@ extern struct siproxd_config configuration;
* STS_SUCCESS on success
* STS_FAILURE on error
*/
int sipsock_listen (int *sock) {
int sipsock_listen (void) {
struct in_addr ipaddr;
if (sock == NULL) return STS_FAILURE;
memset(&ipaddr, 0, sizeof(ipaddr));
*sock=sockbind(ipaddr, configuration.sip_listen_port, 1);
if (*sock == 0) return STS_FAILURE; /* failure*/
sip_udp_socket=sockbind(ipaddr, configuration.sip_listen_port, 1);
if (sip_udp_socket == 0) return STS_FAILURE; /* failure*/
INFO("bound to port %i", configuration.sip_listen_port);
DEBUGC(DBCLASS_NET,"bound socket %i",*sock);
DEBUGC(DBCLASS_NET,"bound socket %i",sip_udp_socket);
return STS_SUCCESS;
}
@@ -71,7 +73,7 @@ int sipsock_listen (int *sock) {
*
* RETURNS >0 if data received, =0 if nothing received /T/O), -1 on error
*/
int sipsock_wait(int sock) {
int sipsock_wait(void) {
int sts;
fd_set fdset;
struct timeval timeout;
@@ -80,8 +82,8 @@ int sipsock_wait(int sock) {
timeout.tv_usec=0;
FD_ZERO(&fdset);
FD_SET (sock, &fdset);
sts=select (sock+1, &fdset, NULL, NULL, &timeout);
FD_SET (sip_udp_socket, &fdset);
sts=select (sip_udp_socket+1, &fdset, NULL, NULL, &timeout);
/* WARN on failures */
if (sts<0) {
@@ -104,13 +106,13 @@ int sipsock_wait(int sock) {
* RETURNS number of bytes read
* from is modified to return the sockaddr_in of the sender
*/
int sipsock_read(int sock, void *buf, size_t bufsize,
int sipsock_read(void *buf, size_t bufsize,
struct sockaddr_in *from) {
int count;
socklen_t fromlen;
fromlen=sizeof(struct sockaddr_in);
count=recvfrom(sock, buf, bufsize, 0,
count=recvfrom(sip_udp_socket, buf, bufsize, 0,
(struct sockaddr *)from, &fromlen);
if (count<0) {
@@ -132,23 +134,19 @@ int sipsock_read(int sock, void *buf, size_t bufsize,
* STS_SUCCESS on success
* STS_FAILURE on error
*/
int sipsock_send_udp(int *sock, struct in_addr addr, int port,
char *buffer, int size, int allowdump) {
int sipsock_send(struct in_addr addr, int port,
char *buffer, int size) {
struct sockaddr_in dst_addr;
int sts;
/* first time: allocate a socket for sending */
if (*sock == 0) {
*sock=socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (*sock < 0) {
ERROR("socket() call failed:%s",strerror(errno));
return STS_FAILURE;
}
DEBUGC(DBCLASS_NET,"allocated send socket %i",*sock);
if (sip_udp_socket == 0) {
ERROR("SIP socket not allocated");
return STS_FAILURE;
}
if (buffer == NULL) {
ERROR("sipsock_send_udp got NULL buffer");
ERROR("sipsock_send got NULL buffer");
return STS_FAILURE;
}
@@ -156,13 +154,11 @@ int sipsock_send_udp(int *sock, struct in_addr addr, int port,
memcpy(&dst_addr.sin_addr.s_addr, &addr, sizeof(struct in_addr));
dst_addr.sin_port= htons(port);
if (allowdump) {
DEBUGC(DBCLASS_NET,"send UDP packet to %s: %i",
utils_inet_ntoa(addr),port);
DUMP_BUFFER(DBCLASS_NETTRAF, buffer, size);
}
DEBUGC(DBCLASS_NET,"send UDP packet to %s: %i", utils_inet_ntoa(addr),port);
DUMP_BUFFER(DBCLASS_NETTRAF, buffer, size);
sts = sendto(*sock, buffer, size, 0, (const struct sockaddr *)&dst_addr,
sts = sendto(sip_udp_socket, buffer, size, 0,
(const struct sockaddr *)&dst_addr,
(socklen_t)sizeof(dst_addr));
if (sts == -1) {