c4af7a7065a92af1280485697a879104b5e94112
[sip-router] / core_cmd.c
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2005 iptelorg GmbH
5  *
6  * This file is part of ser, a free SIP server.
7  *
8  * ser is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * For a license to use the ser software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * ser is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27
28 #include <time.h>
29 #include <sys/types.h>
30 #include <signal.h>
31 #include "mem/mem.h"
32 #include "mem/shm_mem.h"
33 #include "sr_module.h"
34 #include "dprint.h"
35 #include "core_cmd.h"
36 #include "globals.h"
37 #include "pt.h"
38 #include "ut.h"
39 #include "tcp_info.h"
40 #include "tcp_options.h"
41 #include "core_cmd.h"
42 #ifdef USE_SCTP
43 #include "sctp_options.h"
44 #include "sctp_server.h"
45 #endif
46
47 #ifdef USE_DNS_CACHE
48 void dns_cache_debug(rpc_t* rpc, void* ctx);
49 void dns_cache_debug_all(rpc_t* rpc, void* ctx);
50 void dns_cache_mem_info(rpc_t* rpc, void* ctx);
51 void dns_cache_view(rpc_t* rpc, void* ctx);
52 void dns_cache_rpc_lookup(rpc_t* rpc, void* ctx);
53 void dns_cache_delete_all(rpc_t* rpc, void* ctx);
54 void dns_cache_add_a(rpc_t* rpc, void* ctx);
55 void dns_cache_add_aaaa(rpc_t* rpc, void* ctx);
56 void dns_cache_add_srv(rpc_t* rpc, void* ctx);
57 void dns_cache_delete_a(rpc_t* rpc, void* ctx);
58 void dns_cache_delete_aaaa(rpc_t* rpc, void* ctx);
59 void dns_cache_delete_srv(rpc_t* rpc, void* ctx);
60 void dns_cache_delete_naptr(rpc_t* rpc, void* ctx);
61 void dns_cache_delete_cname(rpc_t* rpc, void* ctx);
62 void dns_cache_delete_txt(rpc_t* rpc, void* ctx);
63 void dns_cache_delete_ebl(rpc_t* rpc, void* ctx);
64 void dns_cache_delete_ptr(rpc_t* rpc, void* ctx);
65
66
67 static const char* dns_cache_mem_info_doc[] = {
68         "dns cache memory info.",    /* Documentation string */
69         0                      /* Method signature(s) */
70 };
71 static const char* dns_cache_debug_doc[] = {
72         "dns debug  info.",    /* Documentation string */
73         0                      /* Method signature(s) */
74 };
75
76 static const char* dns_cache_debug_all_doc[] = {
77         "complete dns debug  dump",    /* Documentation string */
78         0                              /* Method signature(s) */
79 };
80
81 static const char* dns_cache_view_doc[] = {
82         "dns cache dump in a human-readable format",
83         0
84 };
85
86 static const char* dns_cache_rpc_lookup_doc[] = {
87         "perform a dns lookup",
88         0
89 };
90
91 static const char* dns_cache_delete_all_doc[] = {
92         "deletes all the entries from the DNS cache",
93         0
94 };
95
96 static const char* dns_cache_add_a_doc[] = {
97         "adds an A record to the DNS cache",
98         0
99 };
100
101 static const char* dns_cache_add_aaaa_doc[] = {
102         "adds an AAAA record to the DNS cache",
103         0
104 };
105 static const char* dns_cache_add_srv_doc[] = {
106         "adds an SRV record to the DNS cache",
107         0
108 };
109
110 static const char* dns_cache_delete_a_doc[] = {
111         "deletes an A record from the DNS cache",
112         0
113 };
114
115 static const char* dns_cache_delete_aaaa_doc[] = {
116         "deletes an AAAA record from the DNS cache",
117         0
118 };
119
120 static const char* dns_cache_delete_srv_doc[] = {
121         "deletes an SRV record from the DNS cache",
122         0
123 };
124
125 static const char* dns_cache_delete_naptr_doc[] = {
126         "deletes a NAPTR record from the DNS cache",
127         0
128 };
129
130 static const char* dns_cache_delete_cname_doc[] = {
131         "deletes a CNAME record from the DNS cache",
132         0
133 };
134
135 static const char* dns_cache_delete_txt_doc[] = {
136         "deletes a TXT record from the DNS cache",
137         0
138 };
139
140 static const char* dns_cache_delete_ebl_doc[] = {
141         "deletes an EBL record from the DNS cache",
142         0
143 };
144
145
146 static const char* dns_cache_delete_ptr_doc[] = {
147         "deletes an PTR record from the DNS cache",
148         0
149 };
150
151
152 #ifdef USE_DNS_CACHE_STATS
153 void dns_cache_stats_get(rpc_t* rpc, void* ctx);
154
155 static const char* dns_cache_stats_get_doc[] = {
156         "returns the dns measurement counters.",
157         0
158 };
159 #endif /* USE_DNS_CACHE_STATS */
160 #ifdef DNS_WATCHDOG_SUPPORT
161 void dns_set_server_state_rpc(rpc_t* rpc, void* ctx);
162
163 static const char* dns_set_server_state_doc[] = {
164         "sets the state of the DNS servers " \
165         "(0: all the servers are down, 1: at least one server is up)",    /* Documentation string */
166         0                              /* Method signature(s) */
167 };
168
169 void dns_get_server_state_rpc(rpc_t* rpc, void* ctx);
170
171 static const char* dns_get_server_state_doc[] = {
172         "prints the state of the DNS servers " \
173         "(0: all the servers are down, 1: at least one server is up)",  /* Documentation string */
174         0                               /* Method signature(s) */
175 };
176
177 #endif /* DNS_WATCHDOG_SUPPORT */
178 #endif /* USE_DNS_CACHE */
179 #ifdef USE_DST_BLACKLIST
180 void dst_blst_debug(rpc_t* rpc, void* ctx);
181 void dst_blst_mem_info(rpc_t* rpc, void* ctx);
182 void dst_blst_view(rpc_t* rpc, void* ctx);
183 void dst_blst_delete_all(rpc_t* rpc, void* ctx);
184 void dst_blst_add(rpc_t* rpc, void* ctx);
185
186 static const char* dst_blst_mem_info_doc[] = {
187         "dst blacklist memory usage info.",  /* Documentation string */
188         0                                    /* Method signature(s) */
189 };
190 static const char* dst_blst_debug_doc[] = {
191         "dst blacklist  debug  info.",  /* Documentation string */
192         0                               /* Method signature(s) */
193 };
194 static const char* dst_blst_view_doc[] = {
195         "dst blacklist dump in human-readable format.",  /* Documentation string */
196         0                               /* Method signature(s) */
197 };
198 static const char* dst_blst_delete_all_doc[] = {
199         "Deletes all the entries from the dst blacklist except the permanent ones.",  /* Documentation string */
200         0                               /* Method signature(s) */
201 };
202 static const char* dst_blst_add_doc[] = {
203         "Adds a new entry to the dst blacklist.",  /* Documentation string */
204         0                               /* Method signature(s) */
205 };
206 #ifdef USE_DST_BLACKLIST_STATS
207 void dst_blst_stats_get(rpc_t* rpc, void* ctx);
208
209 static const char* dst_blst_stats_get_doc[] = {
210         "returns the dst blacklist measurement counters.",
211         0
212 };
213 #endif /* USE_DST_BLACKLIST_STATS */
214
215 #endif
216
217
218
219 #define MAX_CTIME_LEN 128
220
221 /* up time */
222 static char up_since_ctime[MAX_CTIME_LEN];
223
224
225 static const char* system_listMethods_doc[] = {
226         "Lists all RPC methods supported by the server.",  /* Documentation string */
227         0                                                  /* Method signature(s) */
228 };
229
230 static void system_listMethods(rpc_t* rpc, void* c)
231 {
232         struct sr_module* t;
233         rpc_export_t* ptr;
234
235         for(ptr = core_rpc_methods; ptr && ptr->name; ptr++) {
236                 if (rpc->add(c, "s", ptr->name) < 0) return;
237         }
238
239         for(t = modules; t; t = t->next) {
240                 if (t->mod_interface_ver!=0) continue;
241                 for(ptr = t->exports->v0.rpc_methods; ptr && ptr->name; ptr++) {
242                         if (rpc->add(c, "s", ptr->name) < 0) return;
243                 }
244         }
245 }
246
247 static const char* system_methodSignature_doc[] = {
248         "Returns signature of given method.",  /* Documentation string */
249         0                                      /* Method signature(s) */
250 };
251
252 static void system_methodSignature(rpc_t* rpc, void* c)
253 {
254         rpc->fault(c, 500, "Not Implemented Yet");
255 }
256
257
258 static const char* system_methodHelp_doc[] = {
259         "Print the help string for given method.",  /* Documentation string */
260         0                                           /* Method signature(s) */
261 };
262
263 static void system_methodHelp(rpc_t* rpc, void* c)
264 {
265         struct sr_module* t;
266         rpc_export_t* ptr;
267         char* name;
268
269         if (rpc->scan(c, "s", &name) < 1) {
270                 rpc->fault(c, 400, "Method Name Expected");
271                 return;
272         }
273
274         for(t = modules; t; t = t->next) {
275                 if (t->mod_interface_ver!=0) continue;
276                 for(ptr = t->exports->v0.rpc_methods; ptr && ptr->name; ptr++) {
277                         if (strcmp(name, ptr->name) == 0) {
278                                 if (ptr->doc_str && ptr->doc_str[0]) {
279                                         rpc->add(c, "s", ptr->doc_str[0]);
280                                 } else {
281                                         rpc->add(c, "s", "undocumented");
282                                 }
283                                 return;
284                         }
285                 }
286         }
287         /* try the core methods too */
288         for (ptr=core_rpc_methods;ptr && ptr->name; ptr++){
289                         if (strcmp(name, ptr->name) == 0) {
290                                 if (ptr->doc_str && ptr->doc_str[0]) {
291                                         rpc->add(c, "s", ptr->doc_str[0]);
292                                 } else {
293                                         rpc->add(c, "s", "undocumented");
294                                 }
295                                 return;
296                         }
297         }
298         rpc->fault(c, 400, "command not found");
299 }
300
301
302 static const char* core_prints_doc[] = {
303         "Returns the string given as parameter.",   /* Documentation string */
304         0                                           /* Method signature(s) */
305 };
306
307
308 static void core_prints(rpc_t* rpc, void* c)
309 {
310         char* string = 0;
311         if (rpc->scan(c, "s", &string)>0)
312                 rpc->add(c, "s", string);
313 }
314
315
316 static const char* core_version_doc[] = {
317         "Returns the version string of the server.", /* Documentation string */
318         0                                           /* Method signature(s) */
319 };
320
321 static void core_version(rpc_t* rpc, void* c)
322 {
323         rpc->add(c, "s", SERVER_HDR);
324 }
325
326
327
328 static const char* core_uptime_doc[] = {
329         "Returns uptime of SER server.",  /* Documentation string */
330         0                                 /* Method signature(s) */
331 };
332
333
334 static void core_uptime(rpc_t* rpc, void* c)
335 {
336         void* s;
337         time_t now;
338
339         time(&now);
340
341         if (rpc->add(c, "{", &s) < 0) return;
342         rpc->struct_add(s, "s", "now", ctime(&now));
343         rpc->struct_add(s, "s", "up_since", up_since_ctime);
344         /* no need for a float here (unless you're concerned that your uptime)
345         rpc->struct_add(s, "f", "uptime",  difftime(now, up_since));
346         */
347         /* on posix system we can substract time_t directly */
348         rpc->struct_add(s, "d", "uptime",  (int)(now-up_since));
349 }
350
351
352 static const char* core_ps_doc[] = {
353         "Returns the description of running SER processes.",  /* Documentation string */
354         0                                                     /* Method signature(s) */
355 };
356
357
358 static void core_ps(rpc_t* rpc, void* c)
359 {
360         int p;
361
362         for (p=0; p<*process_count;p++) {
363                 rpc->add(c, "d", pt[p].pid);
364                 rpc->add(c, "s", pt[p].desc);
365         }
366 }
367
368
369 static const char* core_pwd_doc[] = {
370         "Returns the working directory of SER server.",    /* Documentation string */
371         0                                                  /* Method signature(s) */
372 };
373
374
375 static void core_pwd(rpc_t* rpc, void* c)
376 {
377         char *cwd_buf;
378         int max_len;
379
380         max_len = pathmax();
381         cwd_buf = pkg_malloc(max_len);
382         if (!cwd_buf) {
383                 ERR("core_pwd: No memory left\n");
384                 rpc->fault(c, 500, "Server Ran Out of Memory");
385                 return;
386         }
387
388         if (getcwd(cwd_buf, max_len)) {
389                 rpc->add(c, "s", cwd_buf);
390         } else {
391                 rpc->fault(c, 500, "getcwd Failed");
392         }
393         pkg_free(cwd_buf);
394 }
395
396
397 static const char* core_arg_doc[] = {
398         "Returns the list of command line arguments used on SER startup.",  /* Documentation string */
399         0                                                                   /* Method signature(s) */
400 };
401
402
403 static void core_arg(rpc_t* rpc, void* c)
404 {
405         int p;
406
407         for (p = 0; p < my_argc; p++) {
408                 if (rpc->add(c, "s", my_argv[p]) < 0) return;
409         }
410 }
411
412
413 static const char* core_kill_doc[] = {
414         "Sends the given signal to SER.",  /* Documentation string */
415         0                                  /* Method signature(s) */
416 };
417
418
419 static void core_kill(rpc_t* rpc, void* c)
420 {
421         int sig_no = 15;
422         rpc->scan(c, "d", &sig_no);
423         rpc->send(c);
424         kill(0, sig_no);
425 }
426
427 static void core_shmmem(rpc_t* rpc, void* c)
428 {
429         struct mem_info mi;
430         void *handle;
431
432         shm_info(&mi);
433         rpc->add(c, "{", &handle);
434         rpc->struct_add(handle, "dddddd",
435                 "total", (unsigned int)mi.total_size,
436                 "free", (unsigned int)mi.free,
437                 "used", (unsigned int)mi.used,
438                 "real_used",(unsigned int)mi.real_used,
439                 "max_used", (unsigned int)mi.max_used,
440                 "fragments", (unsigned int)mi.total_frags
441         );
442 }
443
444 static const char* core_shmmem_doc[] = {
445         "Returns shared memory info.",  /* Documentation string */
446         0                               /* Method signature(s) */
447 };
448
449
450 #if defined(SF_MALLOC) || defined(LL_MALLOC)
451 static void core_sfmalloc(rpc_t* rpc, void* c)
452 {
453         void *handle;
454         int i,r;
455         unsigned long frags, main_s_frags, main_b_frags, pool_frags;
456         unsigned long misses;
457         unsigned long max_misses;
458         unsigned long max_frags;
459         unsigned long max_mem;
460         int max_frags_pool, max_frags_hash;
461         int max_misses_pool, max_misses_hash;
462         int max_mem_pool, max_mem_hash;
463         unsigned long mem;
464
465         if (rpc->scan(c, "d", &r) >= 1) {
466                 if (r>=(int)SF_HASH_POOL_SIZE){
467                         rpc->fault(c, 500, "invalid hash number %d (max %d)",
468                                                                 r, (unsigned int)SF_HASH_POOL_SIZE-1);
469                         return;
470                 }else if (r<0) goto all;
471                 rpc->add(c, "{", &handle);
472                 rpc->struct_add(handle, "dd",
473                                 "hash  ", r,
474                                 "size  ", r*SF_ROUNDTO);
475                 for (i=0; i<SFM_POOLS_NO; i++){
476                         rpc->struct_add(handle, "dddd",
477                                 "pool  ", i,
478                                 "frags ", (unsigned int)shm_block->pool[i].pool_hash[r].no,
479                                 "misses", (unsigned int)shm_block->pool[i].pool_hash[r].misses,
480                                 "mem   ",   (unsigned int)shm_block->pool[i].pool_hash[r].no *
481                                                         r*SF_ROUNDTO
482                         );
483                 }
484         }
485         return;
486 all:
487         max_frags=max_misses=max_mem=0;
488         max_frags_pool=max_frags_hash=0;
489         max_misses_pool=max_misses_hash=0;
490         max_mem_pool=max_mem_hash=0;
491         pool_frags=0;
492         for (i=0; i<SFM_POOLS_NO; i++){
493                 frags=0;
494                 misses=0;
495                 mem=0;
496                 for (r=0; r<SF_HASH_POOL_SIZE; r++){
497                         frags+=shm_block->pool[i].pool_hash[r].no;
498                         misses+=shm_block->pool[i].pool_hash[r].misses;
499                         mem+=shm_block->pool[i].pool_hash[r].no*r*SF_ROUNDTO;
500                         if (shm_block->pool[i].pool_hash[r].no>max_frags){
501                                 max_frags=shm_block->pool[i].pool_hash[r].no;
502                                 max_frags_pool=i;
503                                 max_frags_hash=r;
504                         }
505                         if (shm_block->pool[i].pool_hash[r].misses>max_misses){
506                                 max_misses=shm_block->pool[i].pool_hash[r].misses;
507                                 max_misses_pool=i;
508                                 max_misses_hash=r;
509                         }
510                         if (shm_block->pool[i].pool_hash[r].no*r*SF_ROUNDTO>max_mem){
511                                 max_mem=shm_block->pool[i].pool_hash[r].no*r*SF_ROUNDTO;
512                                 max_mem_pool=i;
513                                 max_mem_hash=r;
514                         }
515                 }
516                 rpc->add(c, "{", &handle);
517                 rpc->struct_add(handle, "dddddd",
518                         "pool  ", i,
519                         "frags ", (unsigned int)frags,
520                         "t. misses", (unsigned int)misses,
521                         "mem   ", (unsigned int)mem,
522                         "missed", (unsigned int)shm_block->pool[i].missed,
523                         "hits",   (unsigned int)shm_block->pool[i].hits
524                 );
525                 pool_frags+=frags;
526         }
527         main_s_frags=0;
528         for (r=0; r<SF_HASH_POOL_SIZE; r++){
529                 main_s_frags+=shm_block->free_hash[r].no;
530         }
531         main_b_frags=0;
532         for (; r<SF_HASH_SIZE; r++){
533                 main_b_frags+=shm_block->free_hash[r].no;
534         }
535         rpc->add(c, "{", &handle);
536         rpc->struct_add(handle, "ddddddddddddd",
537                 "max_frags      ", (unsigned int)max_frags,
538                 "max_frags_pool ", max_frags_pool,
539                 "max_frags_hash", max_frags_hash,
540                 "max_misses     ", (unsigned int)max_misses,
541                 "max_misses_pool", max_misses_pool,
542                 "max_misses_hash", max_misses_hash,
543                 "max_mem        ", (unsigned int)max_mem,
544                 "max_mem_pool   ", max_mem_pool,
545                 "max_mem_hash   ", max_mem_hash,
546                 "in_pools_frags ", (unsigned int)pool_frags,
547                 "main_s_frags   ", (unsigned int)main_s_frags,
548                 "main_b_frags   ", (unsigned int)main_b_frags,
549                 "main_frags     ", (unsigned int)(main_b_frags+main_s_frags)
550         );
551 }
552
553
554
555 static const char* core_sfmalloc_doc[] = {
556         "Returns sfmalloc debugging  info.",  /* Documentation string */
557         0                                     /* Method signature(s) */
558 };
559
560 #endif
561
562
563
564 static const char* core_tcpinfo_doc[] = {
565         "Returns tcp related info.",    /* Documentation string */
566         0                               /* Method signature(s) */
567 };
568
569 static void core_tcpinfo(rpc_t* rpc, void* c)
570 {
571 #ifdef USE_TCP
572         void *handle;
573         struct tcp_gen_info ti;
574
575         if (!tcp_disable){
576                 tcp_get_info(&ti);
577                 rpc->add(c, "{", &handle);
578                 rpc->struct_add(handle, "dddd",
579                         "readers", ti.tcp_readers,
580                         "max_connections", ti.tcp_max_connections,
581                         "opened_connections", ti.tcp_connections_no,
582                         "write_queued_bytes", ti.tcp_write_queued
583                 );
584         }else{
585                 rpc->fault(c, 500, "tcp support disabled");
586         }
587 #else
588         rpc->fault(c, 500, "tcp support not compiled");
589 #endif
590 }
591
592
593
594 static const char* core_tcp_options_doc[] = {
595         "Returns active tcp options.",    /* Documentation string */
596         0                                 /* Method signature(s) */
597 };
598
599 static void core_tcp_options(rpc_t* rpc, void* c)
600 {
601 #ifdef USE_TCP
602         void *handle;
603         struct cfg_group_tcp t;
604
605         if (!tcp_disable){
606                 tcp_options_get(&t);
607                 rpc->add(c, "{", &handle);
608                 rpc->struct_add(handle, "dddddddddddddddddddddd",
609                         "connect_timeout", t.connect_timeout_s,
610                         "send_timeout",  TICKS_TO_S(t.send_timeout),
611                         "connection_lifetime",  TICKS_TO_S(t.con_lifetime),
612                         "max_connections(soft)", t.max_connections,
613                         "no_connect",   t.no_connect,
614                         "fd_cache",             t.fd_cache,
615                         "async",                t.async,
616                         "connect_wait", t.tcp_connect_wait,
617                         "conn_wq_max",  t.tcpconn_wq_max,
618                         "wq_max",               t.tcp_wq_max,
619                         "defer_accept", t.defer_accept,
620                         "delayed_ack",  t.delayed_ack,
621                         "syncnt",               t.syncnt,
622                         "linger2",              t.linger2,
623                         "keepalive",    t.keepalive,
624                         "keepidle",             t.keepidle,
625                         "keepintvl",    t.keepintvl,
626                         "keepcnt",              t.keepcnt,
627                         "crlf_ping",    t.crlf_ping,
628                         "accept_aliases", t.accept_aliases,
629                         "alias_flags",  t.alias_flags,
630                         "new_conn_alias_flags", t.new_conn_alias_flags
631                 );
632         }else{
633                 rpc->fault(c, 500, "tcp support disabled");
634         }
635 #else
636         rpc->fault(c, 500, "tcp support not compiled");
637 #endif
638 }
639
640
641
642 static const char* core_sctp_options_doc[] = {
643         "Returns active sctp options.",    /* Documentation string */
644         0                                 /* Method signature(s) */
645 };
646
647 static void core_sctp_options(rpc_t* rpc, void* c)
648 {
649 #ifdef USE_SCTP
650         void *handle;
651         struct sctp_cfg_options t;
652
653         if (!sctp_disable){
654                 sctp_options_get(&t);
655                 rpc->add(c, "{", &handle);
656                 rpc->struct_add(handle, "dddd",
657                         "sctp_autoclose",               t.sctp_autoclose,
658                         "sctp_send_ttl",        t.sctp_autoclose,
659                         "sctp_socket_rcvbuf",   t.sctp_so_rcvbuf,
660                         "sctp_socket_sndbuf",   t.sctp_so_sndbuf
661                 );
662         }else{
663                 rpc->fault(c, 500, "sctp support disabled");
664         }
665 #else
666         rpc->fault(c, 500, "sctp support not compiled");
667 #endif
668 }
669
670
671
672 static const char* core_sctpinfo_doc[] = {
673         "Returns sctp related info.",    /* Documentation string */
674         0                               /* Method signature(s) */
675 };
676
677 static void core_sctpinfo(rpc_t* rpc, void* c)
678 {
679 #ifdef USE_SCTP
680         void *handle;
681         struct sctp_gen_info i;
682
683         if (!sctp_disable){
684                 sctp_get_info(&i);
685                 rpc->add(c, "{", &handle);
686                 rpc->struct_add(handle, "ddd",
687                         "opened_connections", i.sctp_connections_no,
688                         "tracked_connections", i.sctp_tracked_no,
689                         "total_connections", i.sctp_total_connections
690                 );
691         }else{
692                 rpc->fault(c, 500, "sctp support disabled");
693         }
694 #else
695         rpc->fault(c, 500, "sctp support not compiled");
696 #endif
697 }
698
699
700
701 /*
702  * RPC Methods exported by this module
703  */
704 rpc_export_t core_rpc_methods[] = {
705         {"system.listMethods",     system_listMethods,     system_listMethods_doc,     RET_ARRAY},
706         {"system.methodSignature", system_methodSignature, system_methodSignature_doc, 0        },
707         {"system.methodHelp",      system_methodHelp,      system_methodHelp_doc,      0        },
708         {"core.prints",            core_prints,            core_prints_doc,            0        },
709         {"core.version",           core_version,           core_version_doc,           0        },
710         {"core.uptime",            core_uptime,            core_uptime_doc,            0        },
711         {"core.ps",                core_ps,                core_ps_doc,                RET_ARRAY},
712         {"core.pwd",               core_pwd,               core_pwd_doc,               RET_ARRAY},
713         {"core.arg",               core_arg,               core_arg_doc,               RET_ARRAY},
714         {"core.kill",              core_kill,              core_kill_doc,              0        },
715         {"core.shmmem",            core_shmmem,            core_shmmem_doc,            0        },
716 #if defined(SF_MALLOC) || defined(LL_MALLOC)
717         {"core.sfmalloc",          core_sfmalloc,          core_sfmalloc_doc,   0},
718 #endif
719         {"core.tcp_info",          core_tcpinfo,           core_tcpinfo_doc,    0},
720         {"core.tcp_options",       core_tcp_options,       core_tcp_options_doc,0},
721         {"core.sctp_options",      core_sctp_options,      core_sctp_options_doc,
722                 0},
723         {"core.sctp_info",         core_sctpinfo,          core_sctpinfo_doc,   0},
724 #ifdef USE_DNS_CACHE
725         {"dns.mem_info",          dns_cache_mem_info,     dns_cache_mem_info_doc,
726                 0       },
727         {"dns.debug",          dns_cache_debug,           dns_cache_debug_doc,
728                 0       },
729         {"dns.debug_all",      dns_cache_debug_all,       dns_cache_debug_all_doc,
730                 0       },
731         {"dns.view",               dns_cache_view,        dns_cache_view_doc,
732                 0       },
733         {"dns.lookup",             dns_cache_rpc_lookup,  dns_cache_rpc_lookup_doc,
734                 0       },
735         {"dns.delete_all",         dns_cache_delete_all,  dns_cache_delete_all_doc,
736                 0       },
737         {"dns.add_a",              dns_cache_add_a,       dns_cache_add_a_doc,
738                 0       },
739         {"dns.add_aaaa",           dns_cache_add_aaaa,    dns_cache_add_aaaa_doc,
740                 0       },
741         {"dns.add_srv",            dns_cache_add_srv,     dns_cache_add_srv_doc,
742                 0       },
743         {"dns.delete_a",           dns_cache_delete_a,    dns_cache_delete_a_doc,
744                 0       },
745         {"dns.delete_aaaa",        dns_cache_delete_aaaa,
746                 dns_cache_delete_aaaa_doc, 0    },
747         {"dns.delete_srv",         dns_cache_delete_srv,
748                 dns_cache_delete_srv_doc,  0    },
749         {"dns.delete_naptr",         dns_cache_delete_naptr,
750                 dns_cache_delete_naptr_doc,  0  },
751         {"dns.delete_cname",         dns_cache_delete_cname,
752                 dns_cache_delete_cname_doc,  0  },
753         {"dns.delete_txt",         dns_cache_delete_txt,
754                 dns_cache_delete_txt_doc,  0    },
755         {"dns.delete_ebl",         dns_cache_delete_ebl,
756                 dns_cache_delete_ebl_doc,  0    },
757         {"dns.delete_ptr",         dns_cache_delete_ptr,
758                 dns_cache_delete_ptr_doc,  0    },
759 #ifdef USE_DNS_CACHE_STATS
760         {"dns.stats_get",    dns_cache_stats_get,   dns_cache_stats_get_doc,
761                 0       },
762 #endif /* USE_DNS_CACHE_STATS */
763 #ifdef DNS_WATCHDOG_SUPPORT
764         {"dns.set_server_state",   dns_set_server_state_rpc,
765                 dns_set_server_state_doc, 0 },
766         {"dns.get_server_state",   dns_get_server_state_rpc,
767                 dns_get_server_state_doc, 0 },
768 #endif
769 #endif
770 #ifdef USE_DST_BLACKLIST
771         {"dst_blacklist.mem_info",  dst_blst_mem_info,     dst_blst_mem_info_doc,
772                 0       },
773         {"dst_blacklist.debug",    dst_blst_debug,         dst_blst_debug_doc,
774                 0       },
775         {"dst_blacklist.view",     dst_blst_view,         dst_blst_view_doc,
776                 0       },
777         {"dst_blacklist.delete_all", dst_blst_delete_all, dst_blst_delete_all_doc,
778                 0       },
779         {"dst_blacklist.add",      dst_blst_add,          dst_blst_add_doc,
780                 0       },
781 #ifdef USE_DST_BLACKLIST_STATS
782         {"dst_blacklist.stats_get", dst_blst_stats_get, dst_blst_stats_get_doc, 0},
783 #endif /* USE_DST_BLACKLIST_STATS */
784 #endif
785         {0, 0, 0, 0}
786 };
787
788 int rpc_init_time(void)
789 {
790         char *t;
791         t=ctime(&up_since);
792         if (strlen(t)+1>=MAX_CTIME_LEN) {
793                 ERR("Too long data %d\n", (int)strlen(t));
794                 return -1;
795         }
796         memcpy(up_since_ctime,t,strlen(t)+1);
797         return 0;
798 }