speeddial.c

Go to the documentation of this file.
00001 /*
00002  * $Id: speeddial.c 4657 2008-08-10 22:51:44Z henningw $
00003  *
00004  * Copyright (C) 2004-2006 Voice Sistem SRL
00005  *
00006  * This file is part of Kamailio.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021  *
00022  * History:
00023  * ---------
00024  * 
00025  */
00026 
00027 
00028 #include <stdio.h>
00029 #include <string.h>
00030 #include "../../sr_module.h"
00031 #include "../../db/db.h"
00032 #include "../../dprint.h"
00033 #include "../../error.h"
00034 #include "../../mem/mem.h"
00035 #include "../../mod_fix.h"
00036 
00037 #include "sdlookup.h"
00038 
00039 MODULE_VERSION
00040 
00041 
00042 /* Module destroy function prototype */
00043 static void destroy(void);
00044 
00045 
00046 /* Module child-init function prototype */
00047 static int child_init(int rank);
00048 
00049 
00050 /* Module initialization function prototype */
00051 static int mod_init(void);
00052 
00053 /* Module parameter variables */
00054 static str db_url    = str_init(DEFAULT_RODB_URL);
00055 str user_column      = str_init("username");
00056 str domain_column    = str_init("domain");
00057 str sd_user_column   = str_init("sd_username");
00058 str sd_domain_column = str_init("sd_domain");
00059 str new_uri_column   = str_init("new_uri");
00060 int use_domain       = 0;
00061 static str domain_prefix    = {NULL, 0};
00062 
00063 str dstrip_s = {NULL, 0};
00064 
00065 
00066 db_func_t db_funcs;      /* Database functions */
00067 db_con_t* db_handle=0;   /* Database connection handle */
00068 
00069 
00070 /* Exported functions */
00071 static cmd_export_t cmds[] = {
00072    {"sd_lookup", (cmd_function)sd_lookup, 1, fixup_spve_null, 0,
00073       REQUEST_ROUTE},
00074    {"sd_lookup", (cmd_function)sd_lookup, 2, fixup_spve_spve, 0,
00075       REQUEST_ROUTE},
00076    {0, 0, 0, 0, 0, 0}
00077 };
00078 
00079 
00080 /* Exported parameters */
00081 static param_export_t params[] = {
00082    {"db_url",           STR_PARAM, &db_url.s             },
00083    {"user_column",      STR_PARAM, &user_column.s        },
00084    {"domain_column",    STR_PARAM, &domain_column.s      },
00085    {"sd_user_column",   STR_PARAM, &sd_user_column.s     },
00086    {"sd_domain_column", STR_PARAM, &sd_domain_column.s   },
00087    {"new_uri_column",   STR_PARAM, &new_uri_column.s     },
00088    {"use_domain",       INT_PARAM, &use_domain           },
00089    {"domain_prefix",    STR_PARAM, &domain_prefix.s      },
00090    {0, 0, 0}
00091 };
00092 
00093 
00094 /* Module interface */
00095 struct module_exports exports = {
00096    "speeddial", 
00097    DEFAULT_DLFLAGS, /* dlopen flags */
00098    cmds,       /* Exported functions */
00099    params,     /* Exported parameters */
00100    0,          /* exported statistics */
00101    0,          /* exported MI functions */
00102    0,          /* exported pseudo-variables */
00103    0,          /* extra processes */
00104    mod_init,   /* module initialization function */
00105    0,          /* response function */
00106    destroy,    /* destroy function */
00107    child_init  /* child initialization function */
00108 };
00109 
00110 
00111 /**
00112  *
00113  */
00114 static int child_init(int rank)
00115 {
00116    db_handle = db_funcs.init(&db_url);
00117    if (!db_handle)
00118    {
00119       LM_ERR("failed to connect database\n");
00120       return -1;
00121    }
00122    return 0;
00123 
00124 }
00125 
00126 
00127 /**
00128  *
00129  */
00130 static int mod_init(void)
00131 {
00132    db_url.len = strlen(db_url.s);
00133    user_column.len = strlen(user_column.s);
00134    domain_column.len = strlen(domain_column.s);
00135    sd_user_column.len = strlen(sd_user_column.s);
00136    sd_domain_column.len  = strlen(sd_domain_column.s);
00137    new_uri_column.len = strlen(new_uri_column.s);
00138    if (domain_prefix.s)
00139       domain_prefix.len = strlen(domain_prefix.s);
00140 
00141     /* Find a database module */
00142    if (db_bind_mod(&db_url, &db_funcs))
00143    {
00144       LM_ERR("failed to bind database module\n");
00145       return -1;
00146    }
00147    if (!DB_CAPABILITY(db_funcs, DB_CAP_QUERY))
00148    {
00149       LM_ERR("Database modules does not "
00150          "provide all functions needed by SPEEDDIAL module\n");
00151       return -1;
00152    }
00153    if (domain_prefix.s && domain_prefix.len > 0) {
00154       dstrip_s.s = domain_prefix.s;
00155       dstrip_s.len = domain_prefix.len;
00156    }
00157 
00158    return 0;
00159 }
00160 
00161 
00162 /**
00163  *
00164  */
00165 static void destroy(void)
00166 {
00167    if (db_handle)
00168       db_funcs.close(db_handle);
00169 }
00170 

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