~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to modules/app_lua/app_lua_mod.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "../../dprint.h"
30
30
#include "../../ut.h"
31
31
#include "../../mod_fix.h"
 
32
#include "../../rpc.h"
 
33
#include "../../rpc_lookup.h"
32
34
 
33
35
#include "app_lua_api.h"
34
36
 
41
43
static void mod_destroy(void);
42
44
static int  child_init(int rank);
43
45
 
 
46
static int app_lua_init_rpc(void);
 
47
 
44
48
static int w_app_lua_dostring(struct sip_msg *msg, char *script, char *extra);
45
49
static int w_app_lua_dofile(struct sip_msg *msg, char *script, char *extra);
46
50
static int w_app_lua_runstring(struct sip_msg *msg, char *script, char *extra);
59
63
 
60
64
int app_lua_load_param(modparam_t type, void *val);
61
65
int app_lua_register_param(modparam_t type, void *val);
 
66
int app_lua_reload_param(modparam_t type, void *val);
62
67
 
63
68
static param_export_t params[]={
64
69
        {"load",     STR_PARAM|USE_FUNC_PARAM, (void*)app_lua_load_param},
65
70
        {"register", STR_PARAM|USE_FUNC_PARAM, (void*)app_lua_register_param},
 
71
        {"reload",   INT_PARAM|USE_FUNC_PARAM, (void*)app_lua_reload_param},
66
72
        {0, 0, 0}
67
73
};
68
74
 
86
92
 
87
93
struct module_exports exports = {
88
94
        "app_lua",
89
 
        RTLD_NOW | RTLD_GLOBAL, /* dlopen flags */
 
95
        DEFAULT_DLFLAGS, /* dlopen flags */
90
96
        cmds,
91
97
        params,
92
98
        0,
99
105
        child_init      /* per child init function */
100
106
};
101
107
 
102
 
 
 
108
int mod_register(char *path, int *dlflags, void *p1, void *p2)
 
109
{
 
110
        *dlflags = RTLD_NOW | RTLD_GLOBAL;
 
111
        return 0;
 
112
}
103
113
 
104
114
/**
105
115
 * init module function
108
118
{
109
119
        if(lua_sr_init_mod()<0)
110
120
                return -1;
 
121
 
 
122
        if(app_lua_init_rpc()<0)  
 
123
        {
 
124
                LM_ERR("failed to register RPC commands\n");
 
125
                return -1;
 
126
        }
111
127
        return 0;
112
128
}
113
129
 
324
340
        return sr_lua_register_module((char*)val);
325
341
}
326
342
 
 
343
int app_lua_reload_param(modparam_t type, void *val)
 
344
{
 
345
        return sr_lua_reload_module((unsigned int)(long) (int *)val);
 
346
}
 
347
 
327
348
static int fixup_lua_run(void** param, int param_no)
328
349
{
329
350
        return fixup_spve_null(param, 1);
330
351
}
331
352
 
 
353
/*** RPC implementation ***/
 
354
 
 
355
static const char* app_lua_rpc_reload_doc[2] = {
 
356
        "Reload lua script",
 
357
        0
 
358
};
 
359
 
 
360
static const char* app_lua_rpc_list_doc[2] = {
 
361
        "list lua scripts",
 
362
        0
 
363
};
 
364
 
 
365
static void app_lua_rpc_reload(rpc_t* rpc, void* ctx)
 
366
{
 
367
        int pos = -1;
 
368
 
 
369
        rpc->scan(ctx, "*d", &pos);
 
370
        LM_DBG("selected index: %d\n", pos);
 
371
        if(lua_sr_reload_script(pos)<0)
 
372
                rpc->fault(ctx, 500, "Reload Failed");
 
373
        return;
 
374
}
 
375
 
 
376
static void app_lua_rpc_list(rpc_t* rpc, void* ctx)
 
377
{
 
378
        int i;
 
379
        sr_lua_load_t *list = NULL, *li;
 
380
        if(lua_sr_list_script(&list)<0)
 
381
        {
 
382
                LM_ERR("Can't get loaded scripts\n");
 
383
                return;
 
384
        }
 
385
        if(list)
 
386
        {
 
387
                li = list;
 
388
                i = 0;
 
389
                while(li)
 
390
                {
 
391
                        rpc->printf(ctx, "%d: [%s]", i, li->script);
 
392
                        li = li->next;
 
393
                        i += 1;
 
394
                }
 
395
        }
 
396
        else {
 
397
                rpc->printf(ctx,"No scripts loaded");
 
398
        }
 
399
        return;
 
400
}
 
401
 
 
402
rpc_export_t app_lua_rpc_cmds[] = {
 
403
        {"app_lua.reload", app_lua_rpc_reload,
 
404
                app_lua_rpc_reload_doc, 0},
 
405
        {"app_lua.list", app_lua_rpc_list,
 
406
                app_lua_rpc_list_doc, 0},
 
407
        {0, 0, 0, 0}
 
408
};
 
409
 
 
410
/**
 
411
 * register RPC commands
 
412
 */
 
413
static int app_lua_init_rpc(void)
 
414
{
 
415
        if (rpc_register_array(app_lua_rpc_cmds)!=0)
 
416
        {
 
417
                LM_ERR("failed to register RPC commands\n");
 
418
                return -1;
 
419
        }
 
420
        return 0;
 
421
}