From: Steven S. <ss...@so...> - 2004-11-10 18:37:53
|
Ok, I've been playing in the library again trying to get REGREL to work and I've found that I can send it all I want but that the curren chan_iax2 does not seem to do anything with it. Of course I am sending it with only a bare minimum of additional information -- I toss in most of the same IEs that are sent along with a REGREQ. I see the request hit Asterisk in the iax debug output, but it never seems to hit the proper point in the chan_iax2 code to unregister the host. I've added verbose statemements to chan_iax2 at line 5791 (the case statement handling IAX commands) but it never gets called. Does anybody have any idea what is going on with this? Here's my iaxc_unregister and the equivalent code in libiax2. Keep in mind that I have hacked the iaxc_register into iaxc_register2 and am keeping a list of valid registrations... [in iaxclient_lib.c]: int iaxc_unregister2(int regid) { struct iaxc_registration *prereg = NULL; struct iaxc_registration *oldreg = NULL; struct iaxc_registration *curreg = NULL; // Bail if the registration value is zero if (!registrations) return -1; // Set pointers to the base registrations value curreg = registrations; prereg = registrations; // Look for the registration by regid while (1) { if (curreg->regid == regid) { oldreg = curreg; break; } // cache the current registration for future use prereg = curreg; // get the next registration structure if (curreg->next) curreg = curreg->next; else return -2; // not found } // Hmmm... not found. if(!oldreg) { iaxc_usermsg(IAXC_ERROR, "Can't find registration to cancel."); return -3; } // Create a new session for this (should be every time) if(!oldreg->session) { oldreg->session = iax_session_new(); } // send out the unregister request iax_unregister(oldreg->session, oldreg->host, oldreg->user, oldreg->pass); // remove it from the list; if (oldreg->next) { if (prereg) prereg->next == oldreg->next; } // Destroy it free(oldreg); // return zero for success return 0; } [in iax.c (in libiax2)]: int iax_unregister(struct iax_session *session, char *server, char *peer, char *secret) { /* Send an un-registration request */ char tmp[256]; char *p; int res; 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) portno = atoi(p); memset(&ied, 0, sizeof(ied)); if (secret) strncpy(session->secret, secret, sizeof(session->secret) - 1); else strcpy(session->secret, ""); /* 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); res = send_command(session, AST_FRAME_IAX, IAX_COMMAND_REGREL, 0, ied.buf, ied.pos, -1); DEBU(G "Sent Reg Release Message\n"); return res; } |