docs: removed whitespace
[transsip.git] / src / clicmds.c
blobe59a5f0f7f08a9ee02cc23d3fe872ed4f683876a
1 /*
2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
7 */
9 #include <errno.h>
11 #include "clicmds.h"
12 #include "xutils.h"
13 #include "xmalloc.h"
14 #include "die.h"
16 static int tsocki, tsocko;
18 int cmd_call(char *arg)
20 int argc;
21 ssize_t ret;
22 char **argv = strntoargv(arg, strlen(arg), &argc);
23 struct cli_pkt cpkt;
25 if (argc != 2) {
26 whine("Missing arguments: call <ipv4/ipv6/host> <port>\n");
27 xfree(argv);
28 return -EINVAL;
30 if (strlen(argv[0]) > ADDRSIZ || strlen(argv[1]) > PORTSIZ) {
31 whine("Arguments too long!\n");
32 xfree(argv);
33 return -EINVAL;
36 memset(&cpkt, 0, sizeof(cpkt));
37 cpkt.ring = 1;
38 strlcpy(cpkt.address, argv[0], sizeof(cpkt.address));
39 strlcpy(cpkt.port, argv[1], sizeof(cpkt.port));
41 ret = write(tsocko, &cpkt, sizeof(cpkt));
42 ret = write(tsocko, &cpkt, sizeof(cpkt)); //XXX
43 if (ret != sizeof(cpkt)) {
44 whine("Error notifying thread!\n");
45 return -EIO;
48 printf("Calling ... hang up the line with: hangup\n");
50 xfree(argv);
51 return 0;
54 int cmd_hangup(char *arg)
56 ssize_t ret;
57 struct cli_pkt cpkt;
59 memset(&cpkt, 0, sizeof(cpkt));
60 cpkt.fin = 1;
62 ret = write(tsocko, &cpkt, sizeof(cpkt));
63 if (ret != sizeof(cpkt)) {
64 whine("Error notifying thread!\n");
65 return -EIO;
68 return 0;
71 int cmd_take(char *arg)
73 ssize_t ret;
74 struct cli_pkt cpkt;
76 memset(&cpkt, 0, sizeof(cpkt));
77 cpkt.take = 1;
79 ret = write(tsocko, &cpkt, sizeof(cpkt));
80 if (ret != sizeof(cpkt)) {
81 whine("Error notifying thread!\n");
82 return -EIO;
85 return 0;
88 void init_cli_cmds(int ti, int to)
90 tsocki = ti;
91 tsocko = to;