mailmap: add mail alias
[transsip-mirror.git] / src / clicmds.c
blob2dc382859c524b8b720db11af9e51ab50e80b599
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 * Subject to the GPL, version 2.
6 */
8 #include <errno.h>
10 #include "clicmds.h"
11 #include "xutils.h"
12 #include "xmalloc.h"
13 #include "die.h"
15 static int tsocki, tsocko;
17 int cmd_call(char *arg)
19 int argc;
20 ssize_t ret;
21 char **argv = strntoargv(arg, strlen(arg), &argc);
22 struct cli_pkt cpkt;
24 if (argc != 2) {
25 whine("Missing arguments: call <ipv4/ipv6/host> <port>\n");
26 xfree(argv);
27 return -EINVAL;
29 if (strlen(argv[0]) > ADDRSIZ || strlen(argv[1]) > PORTSIZ) {
30 whine("Arguments too long!\n");
31 xfree(argv);
32 return -EINVAL;
35 memset(&cpkt, 0, sizeof(cpkt));
36 cpkt.ring = 1;
37 strlcpy(cpkt.address, argv[0], sizeof(cpkt.address));
38 strlcpy(cpkt.port, argv[1], sizeof(cpkt.port));
40 ret = write(tsocko, &cpkt, sizeof(cpkt));
41 ret = write(tsocko, &cpkt, sizeof(cpkt)); //XXX
42 if (ret != sizeof(cpkt)) {
43 whine("Error notifying thread!\n");
44 return -EIO;
47 printf("Calling ... hang up the line with: hangup\n");
49 xfree(argv);
50 return 0;
53 int cmd_hangup(char *arg)
55 ssize_t ret;
56 struct cli_pkt cpkt;
58 memset(&cpkt, 0, sizeof(cpkt));
59 cpkt.fin = 1;
61 ret = write(tsocko, &cpkt, sizeof(cpkt));
62 if (ret != sizeof(cpkt)) {
63 whine("Error notifying thread!\n");
64 return -EIO;
67 return 0;
70 int cmd_take(char *arg)
72 ssize_t ret;
73 struct cli_pkt cpkt;
75 memset(&cpkt, 0, sizeof(cpkt));
76 cpkt.take = 1;
78 ret = write(tsocko, &cpkt, sizeof(cpkt));
79 if (ret != sizeof(cpkt)) {
80 whine("Error notifying thread!\n");
81 return -EIO;
84 return 0;
87 void init_cli_cmds(int ti, int to)
89 tsocki = ti;
90 tsocko = to;