pua_bla.c

Go to the documentation of this file.
00001 /*
00002  * $Id: pua_bla.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 "../../sr_module.h"
00032 #include "../../dprint.h"
00033 #include "../usrloc/usrloc.h"
00034 #include "../../parser/msg_parser.h"
00035 #include "../../parser/parse_from.h"
00036 #include "pua_bla.h"
00037 #include "registrar_cb.h"
00038 
00039 MODULE_VERSION
00040 /* Structure containing pointers to pua functions */
00041 pua_api_t pua;
00042 /* Structure containing pointers to usrloc functions */
00043 usrloc_api_t ul;
00044 str default_domain= {NULL, 0};
00045 str header_name= {0, 0};
00046 str bla_outbound_proxy= {0, 0};
00047 int is_bla_aor= 0;
00048 str reg_from_uri= {0, 0};
00049 static int mod_init(void);
00050 
00051 send_publish_t pua_send_publish;
00052 send_subscribe_t pua_send_subscribe;
00053 query_dialog_t pua_is_dialog;
00054 int bla_set_flag(struct sip_msg* , char*, char*);
00055 str server_address= {0, 0};
00056 static cmd_export_t cmds[]=
00057 {
00058    {"bla_set_flag", (cmd_function)bla_set_flag,     0, 0, 0, REQUEST_ROUTE},
00059    {"bla_handle_notify", (cmd_function)bla_handle_notify,   0, 0, 0, REQUEST_ROUTE},   
00060    {0, 0, 0, 0, 0, 0}
00061 };
00062 static param_export_t params[]=
00063 {
00064    {"server_address",    STR_PARAM, &server_address.s  },
00065    {"default_domain",    STR_PARAM, &default_domain.s  },
00066    {"header_name",      STR_PARAM, &header_name.s       },
00067    {"outbound_proxy",   STR_PARAM, &bla_outbound_proxy.s    },
00068    {0,                      0,         0            }
00069 };
00070 
00071 /** module exports */
00072 struct module_exports exports= {
00073    "pua_bla",              /* module name */
00074    DEFAULT_DLFLAGS,            /* dlopen flags */
00075    cmds,                /* exported functions */
00076    params,                 /* exported parameters */
00077    0,                   /* exported statistics */
00078    0,                   /* exported MI functions */
00079    0,                   /* exported pseudo-variables */
00080    0,                   /* extra processes */
00081    mod_init,               /* module initialization function */
00082    0,                   /* response handling function */
00083    0,                   /* destroy function */
00084    0                    /* per-child init function */
00085 };
00086    
00087 /**
00088  * init module function
00089  */
00090 static int mod_init(void)
00091 {
00092    bind_pua_t bind_pua;
00093    bind_usrloc_t bind_usrloc;
00094 
00095    if(server_address.s== NULL)
00096    {
00097       LM_ERR("compulsory 'server_address' parameter not set!");
00098       return -1;
00099    }
00100    server_address.len= strlen(server_address.s);
00101 
00102    if(default_domain.s == NULL )
00103    {  
00104       LM_ERR("default domain not found\n");
00105       return -1;
00106    }
00107    default_domain.len= strlen(default_domain.s);
00108 
00109    if(header_name.s == NULL )
00110    {  
00111       LM_ERR("header_name parameter not set\n");
00112       return -1;
00113    }
00114    header_name.len= strlen(header_name.s);
00115 
00116    if(bla_outbound_proxy.s == NULL )
00117    {  
00118       LM_DBG("No outbound proxy set\n");
00119    }
00120    else
00121       bla_outbound_proxy.len= strlen(bla_outbound_proxy.s);
00122 
00123    bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
00124    if (!bind_pua)
00125    {
00126       LM_ERR("Can't bind pua\n");
00127       return -1;
00128    }
00129    
00130    if (bind_pua(&pua) < 0)
00131    {
00132       LM_ERR("Can't bind pua\n");
00133       return -1;
00134    }
00135    if(pua.send_publish == NULL)
00136    {
00137       LM_ERR("Could not import send_publish\n");
00138       return -1;
00139    }
00140    pua_send_publish= pua.send_publish;
00141 
00142    if(pua.send_subscribe == NULL)
00143    {
00144       LM_ERR("Could not import send_subscribe\n");
00145       return -1;
00146    }
00147    pua_send_subscribe= pua.send_subscribe;
00148 
00149    if(pua.is_dialog == NULL)
00150    {
00151       LM_ERR("Could not import send_subscribe\n");
00152       return -1;
00153    }
00154    pua_is_dialog= pua.is_dialog;
00155    
00156    if(pua.register_puacb== NULL)
00157    {
00158       LM_ERR("Could not import register callback\n");
00159       return -1;
00160    }  
00161 
00162    bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
00163    if (!bind_usrloc)
00164    {
00165       LM_ERR("Can't bind usrloc\n");
00166       return -1;
00167    }
00168    if (bind_usrloc(&ul) < 0)
00169    {
00170       LM_ERR("Can't bind usrloc\n");
00171       return -1;
00172    }
00173    if(ul.register_ulcb == NULL)
00174    {
00175       LM_ERR("Could not import ul_register_ulcb\n");
00176       return -1;
00177    }
00178 
00179    if(ul.register_ulcb(UL_CONTACT_INSERT, bla_cb , 0)< 0)
00180    {
00181       LM_ERR("can not register callback for"
00182             " insert\n");
00183       return -1;
00184    }
00185    if(ul.register_ulcb(UL_CONTACT_EXPIRE, bla_cb, 0)< 0)
00186    {  
00187       LM_ERR("can not register callback for"
00188             " insert\n");
00189       return -1;
00190    }
00191    if(ul.register_ulcb(UL_CONTACT_UPDATE, bla_cb, 0)< 0)
00192    {  
00193       LM_ERR("can not register callback for"
00194             " update\n");
00195       return -1;
00196    }
00197    if(ul.register_ulcb(UL_CONTACT_DELETE, bla_cb, 0)< 0)
00198    {  
00199       LM_ERR("can not register callback for"
00200             " delete\n");
00201       return -1;
00202    }
00203 
00204    return 0;
00205 }
00206 
00207 
00208 int bla_set_flag(struct sip_msg* msg , char* s1, char* s2)
00209 {
00210    LM_DBG("mark as bla aor\n");
00211    
00212    is_bla_aor= 1;
00213    
00214    if( parse_headers(msg,HDR_EOH_F, 0)==-1 )
00215    {
00216       LM_ERR("parsing headers\n");
00217       return -1;
00218    }
00219    
00220 
00221    if (msg->from->parsed == NULL)
00222    {
00223       if ( parse_from_header( msg )<0 ) 
00224       {
00225          LM_DBG("cannot parse From header\n");
00226          return -1;
00227       }
00228    }
00229 
00230    reg_from_uri= ((struct to_body*)(msg->from->parsed))->uri;
00231 
00232    return 1;
00233 }  
00234 

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