00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00043 static void destroy(void);
00044
00045
00046
00047 static int child_init(int rank);
00048
00049
00050
00051 static int mod_init(void);
00052
00053
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;
00067 db_con_t* db_handle=0;
00068
00069
00070
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
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
00095 struct module_exports exports = {
00096 "speeddial",
00097 DEFAULT_DLFLAGS,
00098 cmds,
00099 params,
00100 0,
00101 0,
00102 0,
00103 0,
00104 mod_init,
00105 0,
00106 destroy,
00107 child_init
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
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