all: updated FSF address in GPL text
[sip-router] / modules / pua_mi / pua_mi.c
1 /*
2  * $Id$
3  *
4  * pua_mi module - MI pua module
5  *
6  * Copyright (C) 2006 Voice Sistem S.R.L.
7  *
8  * This file is part of Kamailio, a free SIP server.
9  *
10  * Kamailio is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version
14  *
15  * Kamailio is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License 
21  * along with this program; if not, write to the Free Software 
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  * History:
25  * --------
26  *  2006-11-29  initial version (anca)
27  */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <time.h>
33
34 #include "../../sr_module.h"
35 #include "../../parser/parse_expires.h"
36 #include "../../dprint.h"
37 #include "../../mem/shm_mem.h"
38 #include "../../parser/msg_parser.h"
39 #include "../../str.h"
40 #include "../../mem/mem.h"
41 #include "../../pt.h"
42 #include "../../modules/tm/tm_load.h"
43 #include "../../lib/kmi/mi.h"
44 #include "../pua/pua_bind.h"
45 #include "mi_func.h"
46
47 MODULE_VERSION
48
49 pua_api_t pua;
50
51 /** module functions */
52
53 static int mod_init(void);
54
55 send_publish_t pua_send_publish;
56 send_subscribe_t pua_send_subscribe;
57
58 /*
59  * Exported MI functions
60  */
61 static mi_export_t mi_cmds[] = {
62         { "pua_publish",     mi_pua_publish,     MI_ASYNC_RPL_FLAG,  0,  0},
63         { "pua_subscribe",   mi_pua_subscribe,   0,                                  0,  0},
64         { 0,                             0,                                      0,                                      0,  0}
65 };
66
67 /** module exports */
68 struct module_exports exports= {
69         "pua_mi",                                       /* module name */
70         DEFAULT_DLFLAGS,                        /* dlopen flags */
71         0,                                                      /* exported functions */
72         0,                                                      /* exported parameters */
73         0,                                                      /* exported statistics */
74         mi_cmds,                                        /* exported MI functions */
75         0,                                                      /* exported pseudo-variables */
76         0,                                                      /* extra processes */
77         mod_init,                                       /* module initialization function */
78         0,                                                      /* response handling function */
79         0,                                                      /* destroy function */
80         0                                                       /* per-child init function */
81 };
82         
83 /**
84  * init module function
85  */
86 static int mod_init(void)
87 {
88         bind_pua_t bind_pua;
89         
90         LM_DBG("...\n");
91         
92         if(register_mi_mod(exports.name, mi_cmds)!=0)
93         {
94                 LM_ERR("failed to register MI commands\n");
95                 return -1;
96         }
97
98         bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
99         if (!bind_pua)
100         {
101                 LM_ERR("Can't bind pua\n");
102                 return -1;
103         }
104         
105         if (bind_pua(&pua) < 0)
106         {
107                 LM_ERR("Can't bind pua\n");
108                 return -1;
109         }
110         if(pua.send_publish == NULL)
111         {
112                 LM_ERR("Could not import send_publish\n");
113                 return -1;
114         }
115         pua_send_publish= pua.send_publish;
116
117         if(pua.send_subscribe == NULL)
118         {
119                 LM_ERR("Could not import send_subscribe\n");
120                 return -1;
121         }
122         pua_send_subscribe= pua.send_subscribe;
123         
124         if(pua.register_puacb(MI_ASYN_PUBLISH, mi_publ_rpl_cback, NULL)< 0)
125         {
126                 LM_ERR("Could not register callback\n");
127                 return -1;
128         }       
129
130         return 0;
131 }