flatstore_mod.c

Go to the documentation of this file.
00001 /* 
00002  * $Id: flatstore_mod.c 4518 2008-07-28 15:39:28Z henningw $ 
00003  *
00004  * Flatstore module interface
00005  *
00006  * Copyright (C) 2004 FhG Fokus
00007  *
00008  * This file is part of 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  *  2003-03-11  updated to the new module exports interface (andrei)
00027  *  2003-03-16  flags export parameter added (janakj)
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  * Process number used in filenames
00049  */
00050 int flat_pid;
00051 
00052 /*
00053  * Should we flush after each write to the database ?
00054  */
00055 int flat_flush = 1;
00056 
00057 
00058 /*
00059  * Delimiter delimiting columns
00060  */
00061 char* flat_delimiter = "|";
00062 
00063 
00064 /*
00065  * Timestamp of the last log rotation request from
00066  * the FIFO interface
00067  */
00068 time_t* flat_rotate;
00069 
00070 time_t local_timestamp;
00071 
00072 /*
00073  * Flatstore database module interface
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  * Exported parameters
00082  */
00083 static param_export_t params[] = {
00084    {"flush", INT_PARAM, &flat_flush},
00085    {0, 0, 0}
00086 };
00087 
00088 
00089 /*
00090  * Exported parameters
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, /* dlopen flags */
00100    cmds,
00101    params,      /*  module parameters */
00102    0,           /* exported statistics */
00103    mi_cmds,     /* exported MI functions */
00104    0,           /* exported pseudo-variables */
00105    0,           /* extra processes */
00106    mod_init,    /* module initialization function */
00107    0,           /* response function*/
00108    mod_destroy, /* destroy function */
00109    child_init   /* per-child init function */
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 

Generated on Wed May 23 06:00:45 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6