[Asterisk-Dev] Proposed MWI support for Endpoints on Different Softswitch

Jay Ray jonty_11 at yahoo.com
Thu Apr 14 11:05:51 MST 2005


Hi All,
 
    I had proposed the changes to be able to support Asterisk VoiceMail for 3rd Party Softswitches. Here is what I have changed on Asterisk in chan_sip.c
 
While in function sip_send_mwi_to_peer() . in case peer->tohost has a value which means that its not a registered EP - but a static peer, I call another function called sip_send_mwi_to_softswitch() .....in which I separate the comma separated mailboxes defined in sip.conf for that peer. and send NOTIFY in a for loop for each of the Mailboxes....by calling another new function  transmit_notify_to_softswitch_with_mwi()
 
In transmit_notify_to_softswitch_with_mwi() ,  I populate the sip_pvt->username with the mailbox number (minus the mailbox context, if any)...so that the mailbox number gets added to the "TO" header in the NOTIFY going out to that Softswitch...for the Softswitch to pass on the NOTIFY to the appropriate Endpoint....
 
The DIFF is below, comments appreciated.......
 
 
 
 
[root at jerrylinux channels]# diff chan_sip.c.wrking1 chan_sip.c.orig
489,490d488
<       int *lastmsgsent_switch;        /* maintaining last message sent for EPS on a Third Party Softswitch */
<
1207c1205
<
---
>
1209d1206
<
1212d1208
<
3930,3932d3925
<
<
<
4217,4271d4209
< /*--- transmit_notify_to_softswitch_with_mwi: Notify Softswitch user of
<       messages waiting in voicemail ---*/
< /*      Notification works for Softswitch peers with mailbox= definitions
<  *      in sip.conf
<  *      We use the SIP Event package message-summary
<  *      MIME type defaults to  "application/simple-message-summary";
<  */
< static int transmit_notify_to_softswitch_with_mwi(struct sip_pvt *p, char *mbox, int newmsgs, int oldmsgs)
< {
<         struct sip_request req;
<         char tmp[256];
<         char tmp2[256];
<       char *tmp_mbox;
<         char clen[20];
<
<       /* I will put the Mailbox Number - the part before the @
<        * in p->username, and then call initreqprep as initreqprep
<        * looks for a p->username and puts it in TO Header
<        */
<
<       tmp_mbox = (char*) calloc(strlen(mbox), sizeof(char));
<
<       strncpy(tmp_mbox, mbox, strlen(mbox));
<
<       tmp_mbox = strsep(&tmp_mbox, "@");
<
<       strncpy(p->username, tmp_mbox, strlen(tmp_mbox));
<
<
<
<         initreqprep(&req, p, "NOTIFY", NULL);
<
<         add_header(&req, "Event", "message-summary");
<         add_header(&req, "Content-Type", default_notifymime);
<
<         snprintf(tmp, sizeof(tmp), "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
<         snprintf(tmp2, sizeof(tmp2), "Voice-Message: %d/%d\r\n", newmsgs, oldmsgs);
<         snprintf(clen, sizeof(clen), "%d", (int)(strlen(tmp) + strlen(tmp2)));
<         add_header(&req, "Content-Length", clen);
<         add_line(&req, tmp);
<         add_line(&req, tmp2);
<
<         if (!p->initreq.headers) {
<                 /* Use this as the basis */
<                 copy_request(&p->initreq, &req);
<                 parse(&p->initreq);
<                 if (sip_debug_test_pvt(p))
<                         ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
<                 determine_firstline_parts(&p->initreq);
<         }
<
<         return send_request(p, &req, 1, p->ocseq);
< }
<
<
8628,8734d8565
< //Ujju - sip_send_mwi_to_softswitch : Sending MWI to another Softswitch.
< static int sip_send_mwi_to_softswitch(struct sip_peer *peer)
< {
<       /* Checking for all the malboxes configured for a softswitch
<          and sending NOTIFY w/MWI for all */
<       struct sip_pvt *p;
<       char name[256] = "";
<       int newmsgs, oldmsgs;
<
<       if(peer->mailbox==NULL){
<       ast_log(LOG_WARNING, "No Mailboxes defined in sip.conf and voicemail.conf for this softswitch");
<       return 0;
<       }
<
<       int i;
<       int mbox_count=0;
<       char *mbox[500]; /*Pointer to individual malboxes*/
<       char *tmp=NULL; /*Temp Pointer to individual mailboxes*/
<       char *mailboxes;/* storing full comma separated  mailbox string here */
<
<       mailboxes=(char *)calloc(strlen(peer->mailbox),sizeof(char));
<
<       strcpy(mailboxes,peer->mailbox);
<
<
<       tmp=strchr(mailboxes,',');
<       //**mbox=(char **)malloc(sizeof(char *)*256);
<       //This copies first Mailbox in mbox[0]
<       mbox[mbox_count]=mailboxes;
<       mbox[mbox_count]=strsep(&mbox[mbox_count], ",");
<
<       //This copies rest of the mailboxes in mbox[1, 2, 3......]
<       while(tmp!=NULL)
<       {
<        mbox_count++;
<        tmp+=1;
<        mbox[mbox_count]=(char*) calloc(strlen(tmp), sizeof(char));
<        strncpy(mbox[mbox_count],tmp, strlen(tmp));
<        mbox[mbox_count]=strsep(&mbox[mbox_count], ",");
<        tmp=strchr(tmp,',');
<       }
<
<
<       /* Allocating memory for PTR to last msg for each mailbox for EPs on Softswitch */
<       if (peer->lastmsgsent_switch == NULL) {
<               peer->lastmsgsent_switch = (int *) calloc(mbox_count,sizeof(int));
<               for (i=0;i<=mbox_count;i++)
<                       peer->lastmsgsent_switch[i]=-1;
<       }
<
<
<       //Now looping through all the Mailboxes to send individual Notify's
<       for(i=0;i<=mbox_count;i++) {
<
<
<               ast_app_messagecount(mbox[i], &newmsgs, &oldmsgs);
<
<               time(&peer->lastmsgcheck);
<
<               /* Return now if it's the same thing we told them last time */
<               if (((newmsgs << 8) | (oldmsgs)) == peer->lastmsgsent_switch[i]) {
<                       if (i==mbox_count)
<                               return 0;
<                       else
<                               continue;
<               }
<
<               p = sip_alloc(NULL, NULL, 0);
<               if (!p) {
<                       ast_log(LOG_WARNING, "Unable to build sip pvt data for MWI\n");
<                       return -1;
<               }
<               strncpy(name, peer->name, sizeof(name) - 1);
<               peer->lastmsgsent_switch[i] = ((newmsgs << 8) | (oldmsgs));
<               if (create_addr(p, name)) {
<                       /* Maybe they're not registered, etc. */
<                       sip_destroy(p);
<                       return 0;
<               }
<               /* Recalculate our side, and recalculate Call ID */
<               if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
<                               memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
<               build_via(p, p->via, sizeof(p->via));
<               build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
<               /* Here I call another Function to Build Proper to header */
<               /* Send MWI */
<               ast_set_flag(p, SIP_OUTGOING);
<
<               //Ujju Set the p->peername pointer to char to NULL if its length is 0
<
<               if (!strlen(p->peername)){
<                       strncpy(p->peername, peer->name, sizeof(p->peername));
<               }
<
<
<               transmit_notify_to_softswitch_with_mwi(p, mbox[i], newmsgs, oldmsgs);
<               sip_scheddestroy(p, 15000);
<       }
<
<
<
<       return 0;
<
< }
<
<
<
8743,8750c8574
<       /* Ujju Here we call function to separate all the mailboxes if tohost ne NULL and
<          then call the below func - sip_send_mwi_to_softswitch -  for each of those mailboxes */
<
<       if (strlen(peer->tohost) != 0){
<               sip_send_mwi_to_softswitch(peer);
<               return 0;
<       }
<
---
>       /* Check for messages */



		
---------------------------------
Do you Yahoo!?
 Yahoo! Small Business - Try our new resources site! 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20050414/a403b560/attachment.htm


More information about the asterisk-dev mailing list