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 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <glib.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
+static char** get_tokens(const char *str)
+{
+ char *strcp = strdup(str);
+ char *p;
+ char res_max = 8;
+ char **result = NULL;
+ int cnt = 0;
+
+ p = strtok(strcp, " ");
+ if (!p) {
+ result = (char**)malloc(2 * sizeof(char*));
+ result[0] = strdup(str);
+ result[1] = NULL;
+ return result;
+ }
+
+ result = (char**)malloc(res_max * sizeof(char*));
+ memset(result, 0, res_max * sizeof(char*));
+
+ while (p) {
+ if (cnt >= res_max) {
+ res_max += 8;
+ result = (char**)realloc(result, res_max * sizeof(char*));
+ }
+ result[cnt] = strdup(p);
+ cnt++;
+ p = strtok(NULL, " ");
+ }
+
+ if (cnt >= res_max) {
+ res_max += 1;
+ result = (char**)realloc(result, res_max * sizeof(char*));
+ result[cnt] = NULL;
+ }
+
+ return result;
+}
+
+static void strfreev(char **strs)
+{
+ int i = 0;
+ while (strs && strs[i]) {
+ free(strs[i]);
+ i++;
+ }
+ free(strs);
+}
+
int main(int argc, char *argv[])
{
lockdownd_client_t client = NULL;
@@ -54,25 +101,22 @@ int main(int argc, char *argv[])
}
using_history();
- int loop = TRUE;
+ int loop = 1;
while (loop) {
char *cmd = readline("> ");
if (cmd) {
- gchar **args = g_strsplit(cmd, " ", 0);
+ char **args = get_tokens(cmd);
int len = 0;
- if (args) {
- while (*(args + len)) {
- g_strstrip(*(args + len));
- len++;
- }
+ while (args && args[len]) {
+ len++;
}
if (len > 0) {
add_history(cmd);
if (!strcmp(*args, "quit"))
- loop = FALSE;
+ loop = 0;
if (!strcmp(*args, "get") && len >= 2) {
plist_t value = NULL;
@@ -102,7 +146,7 @@ int main(int argc, char *argv[])
}
}
}
- g_strfreev(args);
+ strfreev(args);
}
free(cmd);
cmd = NULL;