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
87
88
89
90
91
92
93
|
/*
* simple-methods.c part of tcosxmlrpc
* Copyright (C) 2006,2007,2008 mariodebian at gmail
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* tcosxmlrpc simple methods */
#include "common.h"
#include "debug.h"
#include "validate.h"
#if NEWAPI
xmlrpc_value *tcos_version(xmlrpc_env *const env, xmlrpc_value *const in, void *const serverContext)
#else
xmlrpc_value *tcos_version(xmlrpc_env *env, xmlrpc_value *in, void *ud)
#endif
{
dbgtcos("tcosxmlrpc::tcos_version() %s\n", VERSION);
return xmlrpc_build_value(env, "s", VERSION);
}
#if NEWAPI
xmlrpc_value *tcos_echo(xmlrpc_env *const env, xmlrpc_value *const in, void *const serverContext)
#else
xmlrpc_value *tcos_echo(xmlrpc_env *env, xmlrpc_value *in, void *ud)
#endif
{
char *s;
size_t *len;
xmlrpc_parse_value(env, in, "(s#)", &s, &len);
dbgtcos("tcosxmlrpc::tcos_echo() %s\n", s);
return xmlrpc_build_value(env, "s", s);
}
#if NEWAPI
xmlrpc_value *tcos_status(xmlrpc_env *const env, xmlrpc_value *const in, void *const serverContext)
#else
xmlrpc_value *tcos_status (xmlrpc_env *env, xmlrpc_value *in, void *user_data)
#endif
{
FILE *fp=NULL;
char *app=NULL;
char cmd[BUFF_SIZE];
char ret[BUFF_SIZE];
int fret;
UNUSED(fret);
dbgtcos("tcosxmlrpc::tcos_status() Init \n");
/* Parse app string */
xmlrpc_parse_value(env, in, "(s)", &app);
if (env->fault_occurred)
return xmlrpc_build_value(env, "s", "params error");
dbgtcos("tcosxmlrpc::tcos_status() pidof %s\n", app);
snprintf( (char*) &cmd, BUFF_SIZE, "pidof %s| grep -c \"[1234567890]\"",app);
dbgtcos("tcosxmlrpc::tcos_status() exec cmd=\"%s\"\n", cmd);
fp=(FILE*)popen(cmd, "r");
if (env->fault_occurred) {
pclose(fp);
return xmlrpc_build_value(env, "s", "exec error");
}
dbgtcos("tcosxmlrpc::tcos_status() reading from fp pointer\n");
fret=fscanf(fp, "%s", ret);
dbgtcos( "tcosxmlrpc::tcos_status() ret value=%s\n", ret);
pclose(fp);
if (ret != NULL)
return xmlrpc_build_value(env, "s", ret);
else
return xmlrpc_build_value(env, "s", "error");
}
|