From: <jpg...@us...> - 2007-12-20 15:18:35
|
Revision: 1321 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1321&view=rev Author: jpgrayson Date: 2007-12-20 07:18:27 -0800 (Thu, 20 Dec 2007) Log Message: ----------- Apply patch from Lee Howard to add iax_unregister() function to libiax2 api. Modified Paths: -------------- trunk/lib/libiax2/src/iax-client.h trunk/lib/libiax2/src/iax.c Modified: trunk/lib/libiax2/src/iax-client.h =================================================================== --- trunk/lib/libiax2/src/iax-client.h 2007-12-20 05:16:37 UTC (rev 1320) +++ trunk/lib/libiax2/src/iax-client.h 2007-12-20 15:18:27 UTC (rev 1321) @@ -184,6 +184,7 @@ extern int iax_ring_announce(struct iax_session *session); extern struct sockaddr_in iax_get_peer_addr(struct iax_session *session); extern int iax_register(struct iax_session *session, const char *hostname, const char *peer, const char *secret, int refresh); +extern int iax_unregister(struct iax_session *session, const char *hostname, const char *peer, const char *secret, const char *reason); extern int iax_lag_request(struct iax_session *session); extern int iax_dial(struct iax_session *session, char *number); /* Dial on a TBD call */ extern int iax_dialplan_request(struct iax_session *session, char *number); /* Request dialplan status for number */ Modified: trunk/lib/libiax2/src/iax.c =================================================================== --- trunk/lib/libiax2/src/iax.c 2007-12-20 05:16:37 UTC (rev 1320) +++ trunk/lib/libiax2/src/iax.c 2007-12-20 15:18:27 UTC (rev 1321) @@ -202,6 +202,8 @@ struct timeval rxcore; /* Current link state */ int state; + /* Unregister reason */ + char unregreason[MAXSTRLEN]; /* Expected Username */ char username[MAXSTRLEN]; /* Expected Secret */ @@ -1756,6 +1758,8 @@ else strcpy(session->secret, ""); + memset(&session->unregreason, 0, sizeof(session->unregreason)); + /* Connect first */ hp = gethostbyname(tmp); if (!hp) { @@ -1773,6 +1777,49 @@ return res; } +int iax_unregister(struct iax_session *session, const char *server, const char *peer, const char *secret, const char *reason) +{ + /* Send an unregistration request */ + char tmp[256]; + char *p; + int portno = IAX_DEFAULT_PORTNO; + struct iax_ie_data ied; + struct hostent *hp; + + tmp[255] = '\0'; + strncpy(tmp, server, sizeof(tmp) - 1); + p = strchr(tmp, ':'); + if (p) { + *p = '\0'; + portno = atoi(p+1); + } + + memset(&ied, 0, sizeof(ied)); + if (secret) + strncpy(session->secret, secret, sizeof(session->secret) - 1); + else + strcpy(session->secret, ""); + + if (reason && strlen(reason)) + strncpy(session->unregreason, reason, sizeof(session->unregreason) - 1); + else + strcpy(session->unregreason, "Unspecified"); + + /* Connect first */ + hp = gethostbyname(tmp); + if (!hp) { + snprintf(iax_errstr, sizeof(iax_errstr), "Invalid hostname: %s", tmp); + return -1; + } + memcpy(&session->peeraddr.sin_addr, hp->h_addr, sizeof(session->peeraddr.sin_addr)); + session->peeraddr.sin_port = htons(portno); + session->peeraddr.sin_family = AF_INET; + strncpy(session->username, peer, sizeof(session->username) - 1); + iax_ie_append_str(&ied, IAX_IE_USERNAME, peer); + iax_ie_append_str(&ied, IAX_IE_CAUSE, session->unregreason); + return send_command(session, AST_FRAME_IAX, IAX_COMMAND_REGREL, 0, ied.buf, ied.pos, -1); +} + int iax_reject(struct iax_session *session, char *reason) { struct iax_ie_data ied; @@ -1970,7 +2017,6 @@ struct iax_ie_data ied; memset(&ied, 0, sizeof(ied)); iax_ie_append_str(&ied, IAX_IE_USERNAME, session->username); - iax_ie_append_short(&ied, IAX_IE_REFRESH, session->refresh); if ((methods & IAX_AUTHMETHOD_MD5) && challenge) { MD5Init(&md5); MD5Update(&md5, (const unsigned char *) challenge, @@ -1984,7 +2030,13 @@ } else { iax_ie_append_str(&ied, IAX_IE_PASSWORD, password); } - return send_command(session, AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1); + if (strlen(session->unregreason)) { /* Non-zero unregreason length indicates REGREL */ + iax_ie_append_str(&ied, IAX_IE_CAUSE, session->unregreason); + return send_command(session, AST_FRAME_IAX, IAX_COMMAND_REGREL, 0, ied.buf, ied.pos, -1); + } else { + iax_ie_append_short(&ied, IAX_IE_REFRESH, session->refresh); + return send_command(session, AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |