pua_usrloc.c

Go to the documentation of this file.
00001 /*
00002  * $Id: pua_usrloc.c 4949 2008-09-18 12:02:39Z henningw $
00003  *
00004  * pua_usrloc module - usrloc pua module
00005  *
00006  * Copyright (C) 2006 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  *  2006-11-29  initial version (anca)
00027  */
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <libxml/parser.h>
00033 #include <time.h>
00034 
00035 #include "../../script_cb.h"
00036 #include "../../sr_module.h"
00037 #include "../../parser/parse_expires.h"
00038 #include "../../dprint.h"
00039 #include "../../mem/shm_mem.h"
00040 #include "../../parser/msg_parser.h"
00041 #include "../../str.h"
00042 #include "../../mem/mem.h"
00043 #include "../../pt.h"
00044 #include "../usrloc/ul_mod.h"
00045 #include "../usrloc/usrloc.h"
00046 #include "../usrloc/ul_callback.h"
00047 #include "../pua/pua_bind.h"
00048 #include "pua_usrloc.h"
00049 
00050 MODULE_VERSION
00051 
00052 str default_domain= {NULL, 0};
00053 int pua_ul_publish= 0;
00054 pua_api_t pua;
00055 str pres_prefix= {0, 0};
00056 
00057 /* Structure containing pointers to usrloc functions */
00058 usrloc_api_t ul;
00059 
00060 /** module functions */
00061 
00062 static int mod_init(void);
00063 
00064 int pua_set_publish(struct sip_msg* , char*, char*);
00065 
00066 
00067 static cmd_export_t cmds[]=
00068 {
00069    {"pua_set_publish", (cmd_function)pua_set_publish, 0, 0, 0, REQUEST_ROUTE},   
00070    {0, 0, 0, 0, 0, 0} 
00071 };
00072 
00073 static param_export_t params[]={
00074    {"default_domain",    STR_PARAM, &default_domain.s  },
00075    {"entity_prefix",  STR_PARAM, &pres_prefix.s     },
00076    {0,                      0,         0            }
00077 };
00078 
00079 struct module_exports exports= {
00080    "pua_usrloc",           /* module name */
00081    DEFAULT_DLFLAGS,        /* dlopen flags */
00082    cmds,                /* exported functions */
00083    params,                 /* exported parameters */
00084    0,                   /* exported statistics */
00085    0,                   /* exported MI functions */
00086    0,                   /* exported pseudo-variables */
00087    0,                   /* extra processes */
00088    mod_init,               /* module initialization function */
00089    0,                   /* response handling function */
00090    0,                   /* destroy function */
00091    0                    /* per-child init function */
00092 };
00093    
00094 /**
00095  * init module function
00096  */
00097 static int mod_init(void)
00098 {
00099    bind_usrloc_t bind_usrloc;
00100    bind_pua_t bind_pua;
00101    
00102    if(default_domain.s == NULL )
00103    {  
00104       LM_ERR("default domain parameter not set\n");
00105       return -1;
00106    }
00107    default_domain.len= strlen(default_domain.s);
00108    
00109    if(pres_prefix.s == NULL )
00110    {  
00111       LM_DBG("No pres_prefix configured\n");
00112    }
00113    else
00114       pres_prefix.len= strlen(pres_prefix.s);
00115 
00116    bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
00117    if (!bind_usrloc)
00118    {
00119       LM_ERR("Can't bind usrloc\n");
00120       return -1;
00121    }
00122    if (bind_usrloc(&ul) < 0)
00123    {
00124       LM_ERR("Can't bind usrloc\n");
00125       return -1;
00126    }
00127    if(ul.register_ulcb == NULL)
00128    {
00129       LM_ERR("Could not import ul_register_ulcb\n");
00130       return -1;
00131    }
00132 
00133    if(ul.register_ulcb(UL_CONTACT_INSERT, ul_publish, 0)< 0)
00134    {
00135       LM_ERR("can not register callback for"
00136             " insert\n");
00137       return -1;
00138    }
00139    if(ul.register_ulcb(UL_CONTACT_EXPIRE, ul_publish, 0)< 0)
00140    {
00141       LM_ERR("can not register callback for"
00142             " expire\n");
00143       return -1;
00144    }
00145    
00146    if(ul.register_ulcb(UL_CONTACT_UPDATE, ul_publish, 0)< 0)
00147    {
00148       LM_ERR("can not register callback for update\n");
00149       return -1;
00150    }
00151    
00152    if(ul.register_ulcb(UL_CONTACT_DELETE, ul_publish, 0)< 0)
00153    {
00154       LM_ERR("can not register callback for delete\n");
00155       return -1;
00156    }
00157    
00158    bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
00159    if (!bind_pua)
00160    {
00161       LM_ERR("Can't bind pua\n");
00162       return -1;
00163    }
00164    
00165    if (bind_pua(&pua) < 0)
00166    {
00167       LM_ERR("Can't bind pua\n");
00168       return -1;
00169    }
00170    if(pua.send_publish == NULL)
00171    {
00172       LM_ERR("Could not import send_publish\n");
00173       return -1;
00174    }
00175    pua_send_publish= pua.send_publish;
00176 
00177    if(pua.send_subscribe == NULL)
00178    {
00179       LM_ERR("Could not import send_subscribe\n");
00180       return -1;
00181    }
00182    pua_send_subscribe= pua.send_subscribe;
00183    
00184    /* register post-script pua_unset_publish unset function */
00185    if(register_script_cb(pua_unset_publish, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0)
00186    {
00187       LM_ERR("failed to register POST request callback\n");
00188       return -1;
00189    }
00190 
00191 
00192    return 0;
00193 }

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