summaryrefslogtreecommitdiffstats
path: root/dev/lckdclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'dev/lckdclient.c')
-rw-r--r--dev/lckdclient.c163
1 files changed, 0 insertions, 163 deletions
diff --git a/dev/lckdclient.c b/dev/lckdclient.c
deleted file mode 100644
index 08d798f..0000000
--- a/dev/lckdclient.c
+++ /dev/null
@@ -1,163 +0,0 @@
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 <stdlib.h>
24#include <string.h>
25#include <readline/readline.h>
26#include <readline/history.h>
27
28#include <libimobiledevice/libimobiledevice.h>
29#include <libimobiledevice/lockdown.h>
30
31static char** get_tokens(const char *str)
32{
33 char *strcp = strdup(str);
34 char *p;
35 char res_max = 8;
36 char **result = NULL;
37 int cnt = 0;
38
39 p = strtok(strcp, " ");
40 if (!p) {
41 result = (char**)malloc(2 * sizeof(char*));
42 result[0] = strdup(str);
43 result[1] = NULL;
44 return result;
45 }
46
47 result = (char**)malloc(res_max * sizeof(char*));
48 memset(result, 0, res_max * sizeof(char*));
49
50 while (p) {
51 if (cnt >= res_max) {
52 res_max += 8;
53 result = (char**)realloc(result, res_max * sizeof(char*));
54 }
55 result[cnt] = strdup(p);
56 cnt++;
57 p = strtok(NULL, " ");
58 }
59
60 if (cnt >= res_max) {
61 res_max += 1;
62 result = (char**)realloc(result, res_max * sizeof(char*));
63 result[cnt] = NULL;
64 }
65
66 return result;
67}
68
69static void strfreev(char **strs)
70{
71 int i = 0;
72 while (strs && strs[i]) {
73 free(strs[i]);
74 i++;
75 }
76 free(strs);
77}
78
79int main(int argc, char *argv[])
80{
81 lockdownd_client_t client = NULL;
82 idevice_t phone = NULL;
83
84 idevice_set_debug_level(1);
85
86 if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) {
87 printf("No device found, is it plugged in?\n");
88 return -1;
89 }
90
91 char *udid = NULL;
92 if (IDEVICE_E_SUCCESS == idevice_get_udid(phone, &udid)) {
93 printf("DeviceUniqueID : %s\n", udid);
94 }
95 if (udid)
96 free(udid);
97
98 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "lckdclient")) {
99 idevice_free(phone);
100 return -1;
101 }
102
103 using_history();
104 int loop = 1;
105 while (loop) {
106 char *cmd = readline("> ");
107 if (cmd) {
108
109 char **args = get_tokens(cmd);
110
111 int len = 0;
112 while (args && args[len]) {
113 len++;
114 }
115
116 if (len > 0) {
117 add_history(cmd);
118 if (!strcmp(*args, "quit"))
119 loop = 0;
120
121 if (!strcmp(*args, "get") && len >= 2) {
122 plist_t value = NULL;
123 if (LOCKDOWN_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value))
124 {
125 char *xml = NULL;
126 uint32_t length;
127 plist_to_xml(value, &xml, &length);
128 printf("Success : value = %s\n", xml);
129 free(xml);
130 }
131 else
132 printf("Error\n");
133
134 if (value)
135 plist_free(value);
136 }
137
138 if (!strcmp(*args, "start") && len == 2) {
139 lockdownd_service_descriptor_t service = NULL;
140 if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &service)) {
141 printf("started service %s on port %i\n", *(args + 1), service->port);
142 if (service) {
143 lockdownd_service_descriptor_free(service);
144 service = NULL;
145 }
146 }
147 else
148 {
149 printf("failed to start service %s on device.\n", *(args + 1));
150 }
151 }
152 }
153 strfreev(args);
154 }
155 free(cmd);
156 cmd = NULL;
157 }
158 clear_history();
159 lockdownd_client_free(client);
160 idevice_free(phone);
161
162 return 0;
163}