summaryrefslogtreecommitdiffstats
path: root/src/lckdclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lckdclient.c')
-rw-r--r--src/lckdclient.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/lckdclient.c b/src/lckdclient.c
new file mode 100644
index 0000000..179ecae
--- /dev/null
+++ b/src/lckdclient.c
@@ -0,0 +1,105 @@
1/*
2 * lckdclient.c
3 * Rudimentary command line interface to the Lockdown protocol
4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <glib.h>
25#include <readline/readline.h>
26#include <readline/history.h>
27
28
29#include "usbmux.h"
30#include "iphone.h"
31#include <libiphone/libiphone.h>
32
33int debug = 1;
34
35int main(int argc, char *argv[])
36{
37 int bytes = 0, port = 0, i = 0;
38 iphone_lckd_client_t control = NULL;
39 iphone_device_t phone = NULL;
40
41
42 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
43 printf("No iPhone found, is it plugged in?\n");
44 return -1;
45 }
46
47 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
48 iphone_free_device(phone);
49 return -1;
50 }
51
52 char *uid = NULL;
53 if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) {
54 printf("DeviceUniqueID : %s\n", uid);
55 free(uid);
56 }
57
58 using_history();
59 int loop = TRUE;
60 while(loop)
61 {
62 char *cmd = readline("> ");
63 if (cmd)
64 {
65
66 gchar** args = g_strsplit(cmd, " ", 0);
67
68 int len = 0;
69 if (args) {
70 while ( *(args+len) ) {
71 g_strstrip(*(args+len));
72 len++;
73 }
74 }
75
76 if (len > 0) {
77 add_history(cmd);
78 if (!strcmp(*args, "quit"))
79 loop = FALSE;
80
81 if (!strcmp(*args, "get") && len == 3) {
82 char *value = NULL;
83 if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args+1), *(args+2), &value))
84 printf("Success : value = %s\n", value);
85 else
86 printf("Error\n");
87 }
88
89 if (!strcmp(*args, "start") && len == 2) {
90 int port = 0;
91 iphone_lckd_start_service(control, *(args+1), &port);
92 printf("%i\n", port);
93 }
94 }
95 g_strfreev(args);
96 }
97 free(cmd);
98 cmd = NULL;
99 }
100 clear_history();
101 iphone_lckd_free_client(control);
102 iphone_free_device(phone);
103
104 return 0;
105}