json_mod.c

00001 
00025 #include <stdio.h>
00026 #include <string.h>
00027 
00028 #include "../../mod_fix.h"
00029 #include "../../sr_module.h"
00030 
00031 #include "json_funcs.h"
00032 
00033 MODULE_VERSION
00034 
00035 static int fixup_get_field(void** param, int param_no);
00036 static int fixup_get_field_free(void** param, int param_no);
00037 
00038 /* Exported functions */
00039 static cmd_export_t cmds[]={
00040         {"json_get_field", (cmd_function)json_get_field, 3, 
00041                 fixup_get_field, fixup_get_field_free, ANY_ROUTE},
00042         {0, 0, 0, 0, 0, 0}
00043 };
00044 
00045 struct module_exports exports = {
00046                 "json",
00047                 DEFAULT_DLFLAGS, /* dlopen flags */
00048                 cmds,                    /* Exported functions */
00049                 0,               /* Exported parameters */
00050                 0,               /* exported statistics */
00051                 0,                   /* exported MI functions */
00052                 0,                               /* exported pseudo-variables */
00053                 0,                               /* extra processes */
00054                 0,        /* module initialization function */
00055                 0,                               /* response function*/
00056                 0,       /* destroy function */
00057                 0       /* per-child init function */
00058 };
00059 
00060 
00061 static int fixup_get_field(void** param, int param_no)
00062 {
00063   if (param_no == 1 || param_no == 2) {
00064                 return fixup_spve_null(param, 1);
00065         }
00066 
00067         if (param_no == 3) {
00068                 if (fixup_pvar_null(param, 1) != 0) {
00069                     LM_ERR("failed to fixup result pvar\n");
00070                     return -1;
00071                 }
00072                 if (((pv_spec_t *)(*param))->setf == NULL) {
00073                     LM_ERR("result pvar is not writeble\n");
00074                     return -1;
00075                 }
00076                 return 0;
00077         }
00078         
00079         LM_ERR("invalid parameter number <%d>\n", param_no);
00080         return -1;
00081 }
00082 
00083 static int fixup_get_field_free(void** param, int param_no)
00084 {
00085         if (param_no == 1 || param_no == 2) {
00086                 LM_WARN("free function has not been defined for spve\n");
00087                 return 0;
00088         }
00089 
00090         if (param_no == 3) {
00091                 return fixup_free_pvar_null(param, 3);
00092         }
00093 
00094         LM_ERR("invalid parameter number <%d>\n", param_no);
00095         return -1;
00096 }