summaryrefslogtreecommitdiffstats
path: root/dev/lckdclient.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-10-05 20:22:03 +0200
committerGravatar Martin Szulecki2012-03-19 01:44:53 +0100
commit90a4d980e645098d70f193581b55081b0686928c (patch)
tree1218013bf4a114136fa8b85a14def2c23f7f7b10 /dev/lckdclient.c
parent249ac33e36753daaeda7973a0d3cc7cb1f72948a (diff)
downloadlibimobiledevice-90a4d980e645098d70f193581b55081b0686928c.tar.gz
libimobiledevice-90a4d980e645098d70f193581b55081b0686928c.tar.bz2
Removed glib stuff from dev/lckdclient and idevicebackup/idevicebackup2
Diffstat (limited to 'dev/lckdclient.c')
-rw-r--r--dev/lckdclient.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/dev/lckdclient.c b/dev/lckdclient.c
index 773de9f..5ca72f8 100644
--- a/dev/lckdclient.c
+++ b/dev/lckdclient.c
@@ -22,13 +22,60 @@
22#include <stdio.h> 22#include <stdio.h>
23#include <stdlib.h> 23#include <stdlib.h>
24#include <string.h> 24#include <string.h>
25#include <glib.h>
26#include <readline/readline.h> 25#include <readline/readline.h>
27#include <readline/history.h> 26#include <readline/history.h>
28 27
29#include <libimobiledevice/libimobiledevice.h> 28#include <libimobiledevice/libimobiledevice.h>
30#include <libimobiledevice/lockdown.h> 29#include <libimobiledevice/lockdown.h>
31 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
32int main(int argc, char *argv[]) 79int main(int argc, char *argv[])
33{ 80{
34 lockdownd_client_t client = NULL; 81 lockdownd_client_t client = NULL;
@@ -54,25 +101,22 @@ int main(int argc, char *argv[])
54 } 101 }
55 102
56 using_history(); 103 using_history();
57 int loop = TRUE; 104 int loop = 1;
58 while (loop) { 105 while (loop) {
59 char *cmd = readline("> "); 106 char *cmd = readline("> ");
60 if (cmd) { 107 if (cmd) {
61 108
62 gchar **args = g_strsplit(cmd, " ", 0); 109 char **args = get_tokens(cmd);
63 110
64 int len = 0; 111 int len = 0;
65 if (args) { 112 while (args && args[len]) {
66 while (*(args + len)) { 113 len++;
67 g_strstrip(*(args + len));
68 len++;
69 }
70 } 114 }
71 115
72 if (len > 0) { 116 if (len > 0) {
73 add_history(cmd); 117 add_history(cmd);
74 if (!strcmp(*args, "quit")) 118 if (!strcmp(*args, "quit"))
75 loop = FALSE; 119 loop = 0;
76 120
77 if (!strcmp(*args, "get") && len >= 2) { 121 if (!strcmp(*args, "get") && len >= 2) {
78 plist_t value = NULL; 122 plist_t value = NULL;
@@ -102,7 +146,7 @@ int main(int argc, char *argv[])
102 } 146 }
103 } 147 }
104 } 148 }
105 g_strfreev(args); 149 strfreev(args);
106 } 150 }
107 free(cmd); 151 free(cmd);
108 cmd = NULL; 152 cmd = NULL;