initial commit
[project/rpcd.git] / main.c
1 /*
2 * luci-rpcd - LuCI UBUS RPC server
3 *
4 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
5 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #include <unistd.h>
21
22 #include <libubox/blobmsg_json.h>
23 #include <libubus.h>
24
25 #include "session.h"
26 #include "file.h"
27
28 static struct ubus_context *ctx;
29
30 int main(int argc, char **argv)
31 {
32 const char *ubus_socket = NULL;
33 int ch;
34
35 while ((ch = getopt(argc, argv, "s:")) != -1) {
36 switch (ch) {
37 case 's':
38 ubus_socket = optarg;
39 break;
40 default:
41 break;
42 }
43 }
44
45 argc -= optind;
46 argv += optind;
47
48 uloop_init();
49
50 ctx = ubus_connect(ubus_socket);
51 if (!ctx) {
52 fprintf(stderr, "Failed to connect to ubus\n");
53 return -1;
54 }
55
56 ubus_add_uloop(ctx);
57
58 rpc_session_api_init(ctx);
59 rpc_file_api_init(ctx);
60
61 uloop_run();
62 ubus_free(ctx);
63 uloop_done();
64
65 return 0;
66 }