-
Notifications
You must be signed in to change notification settings - Fork 0
/
sipluami.c
86 lines (76 loc) · 2.56 KB
/
sipluami.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
*
* Copyright (c) 2008, 2009
* Eric Gouyer <[email protected]>
* Copyright (c) 2008, 2009, 2010, 2011
* Arnaud Chong <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "../../mi/mi.h"
#include "sipwatch.h"
#include "sipluami.h"
#define SIPLUAMI_USAGE "usage: watch [add | delete | show] [extension]"
struct mi_root *siplua_mi_reload(struct mi_root *cmd_tree, void *param)
{
struct mi_root *answer;
answer = init_mi_tree(200, "xOK", 3);
addf_mi_node_child(&answer->node, 0, "pid", 3, "%d", (int)getpid());
return answer;
}
struct mi_root *siplua_mi_bla(struct mi_root *cmd_tree, void *param)
{
return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
}
struct mi_root *siplua_mi_watch(struct mi_root *cmd_tree, void *param)
{
struct mi_root *answer;
struct mi_node *node;
str action;
node = cmd_tree->node.kids;
if (!node)
return init_mi_tree(200, SIPLUAMI_USAGE, sizeof(SIPLUAMI_USAGE) - 1);
action = node->value;
node = node->next;
if (action.len == 3 && !strncmp("add", action.s, action.len))
{
if (!node)
return init_mi_tree(200, "usage: missing extension", 24);
sipwatch_add(node->value.s, node->value.len);
}
if (action.len == 6 && !strncmp("delete", action.s, action.len))
{
if (!node)
return init_mi_tree(200, "usage: missing extension", 24);
sipwatch_delete(node->value.s, node->value.len);
}
if (action.len == 4 && !strncmp("show", action.s, action.len))
{
int i;
answer = init_mi_tree(200, "xOK", 3);
sipwatch_lock();
for (i = 0; i < siplua_watch->nb; ++i)
addf_mi_node_child(&answer->node, 0, "extension", 9, "%s",
siplua_watch->ext[i].str);
sipwatch_unlock();
return answer;
}
answer = init_mi_tree(200, "xOK", 3);
return answer;
}