flatstore_mod.c
Go to the documentation of this file.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
00029
00030 #include "../../sr_module.h"
00031 #include "../../mem/shm_mem.h"
00032 #include "../../db/db.h"
00033 #include "flatstore.h"
00034 #include "flat_mi.h"
00035 #include "flatstore_mod.h"
00036
00037 MODULE_VERSION
00038
00039 static int child_init(int rank);
00040
00041 static int mod_init(void);
00042
00043 static void mod_destroy(void);
00044
00045 int db_flat_bind_api(db_func_t *dbb);
00046
00047
00048
00049
00050 int flat_pid;
00051
00052
00053
00054
00055 int flat_flush = 1;
00056
00057
00058
00059
00060
00061 char* flat_delimiter = "|";
00062
00063
00064
00065
00066
00067
00068 time_t* flat_rotate;
00069
00070 time_t local_timestamp;
00071
00072
00073
00074
00075 static cmd_export_t cmds[] = {
00076 {"db_bind_api", (cmd_function)db_flat_bind_api, 0, 0, 0, 0},
00077 {0, 0, 0, 0, 0, 0}
00078 };
00079
00080
00081
00082
00083 static param_export_t params[] = {
00084 {"flush", INT_PARAM, &flat_flush},
00085 {0, 0, 0}
00086 };
00087
00088
00089
00090
00091
00092 static mi_export_t mi_cmds[] = {
00093 { MI_FLAT_ROTATE, mi_flat_rotate_cmd, MI_NO_INPUT_FLAG, 0, 0 },
00094 { 0, 0, 0, 0, 0}
00095 };
00096
00097 struct module_exports exports = {
00098 "db_flatstore",
00099 DEFAULT_DLFLAGS,
00100 cmds,
00101 params,
00102 0,
00103 mi_cmds,
00104 0,
00105 0,
00106 mod_init,
00107 0,
00108 mod_destroy,
00109 child_init
00110 };
00111
00112
00113 static int mod_init(void)
00114 {
00115 if (strlen(flat_delimiter) != 1) {
00116 LM_ERR("delimiter has to be exactly one character\n");
00117 return -1;
00118 }
00119
00120 flat_rotate = (time_t*)shm_malloc(sizeof(time_t));
00121 if (!flat_rotate) {
00122 LM_ERR("no shared memory left\n");
00123 return -1;
00124 }
00125
00126 *flat_rotate = time(0);
00127 local_timestamp = *flat_rotate;
00128
00129 return 0;
00130 }
00131
00132
00133 static void mod_destroy(void)
00134 {
00135 if (flat_rotate) shm_free(flat_rotate);
00136 }
00137
00138
00139 static int child_init(int rank)
00140 {
00141 if (rank <= 0) {
00142 flat_pid = - rank;
00143 } else {
00144 flat_pid = rank - PROC_TCP_MAIN;
00145 }
00146 return 0;
00147 }
00148
00149 int db_flat_bind_api(db_func_t *dbb)
00150 {
00151 if(dbb==NULL)
00152 return -1;
00153
00154 memset(dbb, 0, sizeof(db_func_t));
00155
00156 dbb->use_table = flat_use_table;
00157 dbb->init = flat_db_init;
00158 dbb->close = flat_db_close;
00159 dbb->insert = flat_db_insert;
00160
00161 return 0;
00162 }
00163