registrar_cb.c

Go to the documentation of this file.
00001 /*
00002  * $Id: registrar_cb.c 1666 2007-03-02 13:40:09Z anca_vamanu $
00003  *
00004  * pua_bla module - pua Bridged Line Appearance
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * --------
00026  *  2007-03-30  initial version (anca)
00027  */
00028 
00029 #include<stdio.h>
00030 #include<stdlib.h>
00031 #include "../../dprint.h"
00032 #include "../pua/pua.h"
00033 #include "registrar_cb.h"
00034 #include "pua_bla.h"
00035 
00036 
00037 void bla_cb(ucontact_t* c, int type, void* param)
00038 {
00039    subs_info_t subs;
00040    str uri={0, 0};
00041    char* at;
00042    LM_DBG("start\n");
00043    if(is_bla_aor== 0)
00044    {
00045       LM_DBG("Not a recognized BLA AOR\n");
00046       return ;
00047    }  
00048 
00049    if(type & UL_CONTACT_INSERT)
00050       LM_DBG("type= UL_CONTACT_INSERT\n");
00051    else
00052    if(type & UL_CONTACT_UPDATE)
00053       LM_DBG("type= UL_CONTACT_UPDATE\n");
00054    else
00055    if(type & UL_CONTACT_EXPIRE)
00056       LM_DBG("type= UL_CONTACT_EXPIRE\n");
00057    else
00058    if(type & UL_CONTACT_DELETE)
00059       LM_DBG("type= UL_CONTACT_DELETE\n");
00060 
00061    memset(&subs, 0, sizeof(subs_info_t));
00062    subs.remote_target= &c->c;
00063    
00064    subs.pres_uri= &reg_from_uri;
00065 
00066    uri.s = (char*)pkg_malloc(sizeof(char)*(c->aor->len+default_domain.len+6));
00067    if(uri.s == NULL)
00068       goto error;
00069 
00070    memcpy(uri.s, "sip:", 4);
00071    uri.len = 4;
00072 
00073    memcpy(uri.s+ uri.len, c->aor->s, c->aor->len);
00074    uri.len+= c->aor->len;
00075    at = memchr(c->aor->s, '@', c->aor->len);
00076    if(!at)
00077    {
00078       uri.s[uri.len++]= '@';
00079       memcpy(uri.s+ uri.len, default_domain.s, default_domain.len);
00080       uri.len+= default_domain.len;    
00081    }
00082    
00083    subs.watcher_uri= &uri;
00084    if(type & UL_CONTACT_DELETE || type & UL_CONTACT_EXPIRE )
00085       subs.expires= 0;
00086    else
00087       subs.expires= c->expires - (int)time(NULL);
00088       
00089 
00090    subs.source_flag= BLA_SUBSCRIBE;
00091    subs.event= BLA_EVENT;
00092    subs.contact= &server_address;
00093    
00094    if(bla_outbound_proxy.s && bla_outbound_proxy.len)
00095       subs.outbound_proxy= &bla_outbound_proxy;
00096    else
00097    if(c->received.s && c->received.len)
00098       subs.outbound_proxy= &c->received;
00099 
00100    if(type & UL_CONTACT_INSERT)
00101       subs.flag|= INSERT_TYPE;
00102    else
00103       subs.flag|= UPDATE_TYPE;
00104 
00105    if(pua_send_subscribe(&subs)< 0)
00106    {
00107       LM_ERR("while sending subscribe\n");
00108    }  
00109    pkg_free(uri.s);
00110 error:
00111    is_bla_aor= 0;
00112    return ;
00113 }  

Generated on Thu May 24 10:00:30 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6