alias_db.c

Go to the documentation of this file.
00001 /* 
00002  * $Id: alias_db.c 4657 2008-08-10 22:51:44Z henningw $
00003  *
00004  * ALIAS_DB Module
00005  *
00006  * Copyright (C) 2004 Voice Sistem SRL
00007  *
00008  * This file is part of a module for 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  * 2004-09-01: first version (ramona)
00027  */
00028 
00029 
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include "../../sr_module.h"
00033 #include "../../db/db.h"
00034 #include "../../dprint.h"
00035 #include "../../error.h"
00036 #include "../../mem/mem.h"
00037 #include "../../ut.h"
00038 #include "../../mod_fix.h"
00039 
00040 #include "alookup.h"
00041 
00042 MODULE_VERSION
00043 
00044 
00045 /* Module destroy function prototype */
00046 static void destroy(void);
00047 
00048 
00049 /* Module child-init function prototype */
00050 static int child_init(int rank);
00051 
00052 
00053 /* Module initialization function prototype */
00054 static int mod_init(void);
00055 
00056 
00057 /* Module parameter variables */
00058 static str db_url       = str_init(DEFAULT_RODB_URL);
00059 str user_column         = str_init("username");
00060 str domain_column       = str_init("domain");
00061 str alias_user_column   = str_init("alias_username");
00062 str alias_domain_column = str_init("alias_domain");
00063 str domain_prefix       = {NULL, 0};
00064 int use_domain          = 0;
00065 int ald_append_branches = 0;
00066 
00067 db_con_t* db_handle;   /* Database connection handle */
00068 db_func_t adbf;  /* DB functions */
00069 
00070 /* Exported functions */
00071 static cmd_export_t cmds[] = {
00072    {"alias_db_lookup", (cmd_function)alias_db_lookup, 1, fixup_spve_null, 0,
00073       REQUEST_ROUTE|FAILURE_ROUTE},
00074    {0, 0, 0, 0, 0, 0}
00075 };
00076 
00077 
00078 /* Exported parameters */
00079 static param_export_t params[] = {
00080    {"db_url",              STR_PARAM, &db_url.s        },
00081    {"user_column",         STR_PARAM, &user_column.s   },
00082    {"domain_column",       STR_PARAM, &domain_column.s },
00083    {"alias_user_column",   STR_PARAM, &alias_user_column.s   },
00084    {"alias_domain_column", STR_PARAM, &alias_domain_column.s },
00085    {"use_domain",          INT_PARAM, &use_domain      },
00086    {"domain_prefix",       STR_PARAM, &domain_prefix.s },
00087    {"append_branches",     INT_PARAM, &ald_append_branches   },
00088    {0, 0, 0}
00089 };
00090 
00091 
00092 /* Module interface */
00093 struct module_exports exports = {
00094    "alias_db",
00095    DEFAULT_DLFLAGS, /* dlopen flags */
00096    cmds,       /* Exported functions */
00097    params,     /* Exported parameters */
00098    0,          /* exported statistics */
00099    0,          /* exported MI functions */
00100    0,          /* exported pseudo-variables */
00101    0,          /* extra processes */
00102    mod_init,   /* module initialization function */
00103    0,          /* response function */
00104    destroy,    /* destroy function */
00105    child_init  /* child initialization function */
00106 };
00107 
00108 
00109 /**
00110  *
00111  */
00112 static int child_init(int rank)
00113 {
00114    db_handle = adbf.init(&db_url);
00115    if (!db_handle)
00116    {
00117       LM_ERR("unable to connect database\n");
00118       return -1;
00119    }
00120    return 0;
00121 
00122 }
00123 
00124 
00125 /**
00126  *
00127  */
00128 static int mod_init(void)
00129 {
00130    db_url.len = strlen(db_url.s);
00131    user_column.len = strlen(user_column.s);
00132    domain_column.len = strlen(domain_column.s);
00133    alias_domain_column.len = strlen(alias_domain_column.s);
00134    alias_user_column.len = strlen(alias_user_column.s);
00135    if (domain_prefix.s)
00136       domain_prefix.len = strlen(domain_prefix.s);
00137 
00138     /* Find a database module */
00139    if (db_bind_mod(&db_url, &adbf))
00140    {
00141       LM_ERR("unable to bind database module\n");
00142       return -1;
00143    }
00144    if (!DB_CAPABILITY(adbf, DB_CAP_QUERY))
00145    {
00146       LM_CRIT("database modules does not "
00147          "provide all functions needed by avpops module\n");
00148       return -1;
00149    }
00150 
00151    return 0;
00152 }
00153 
00154 
00155 /**
00156  *
00157  */
00158 static void destroy(void)
00159 {
00160    if (db_handle) {
00161       adbf.close(db_handle);
00162       db_handle = 0;
00163    }
00164 }
00165 

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