~ubuntu-branches/ubuntu/lucid/libimobiledevice/lucid

« back to all changes in this revision

Viewing changes to dev/lckdclient.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-02-02 21:19:51 UTC
  • Revision ID: james.westby@ubuntu.com-20100202211951-qv87ejwmucigqezf
Tags: upstream-0.9.7
ImportĀ upstreamĀ versionĀ 0.9.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <glib.h>
 
26
#include <readline/readline.h>
 
27
#include <readline/history.h>
 
28
 
 
29
#include <libimobiledevice/libimobiledevice.h>
 
30
#include <libimobiledevice/lockdown.h>
 
31
 
 
32
int main(int argc, char *argv[])
 
33
{
 
34
        lockdownd_client_t client = NULL;
 
35
        idevice_t phone = NULL;
 
36
 
 
37
        idevice_set_debug_level(1);
 
38
 
 
39
        if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) {
 
40
                printf("No device found, is it plugged in?\n");
 
41
                return -1;
 
42
        }
 
43
 
 
44
        char *uuid = NULL;
 
45
        if (IDEVICE_E_SUCCESS == idevice_get_uuid(phone, &uuid)) {
 
46
                printf("DeviceUniqueID : %s\n", uuid);
 
47
        }
 
48
        if (uuid)
 
49
                free(uuid);
 
50
 
 
51
        if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "lckdclient")) {
 
52
                idevice_free(phone);
 
53
                return -1;
 
54
        }
 
55
 
 
56
        using_history();
 
57
        int loop = TRUE;
 
58
        while (loop) {
 
59
                char *cmd = readline("> ");
 
60
                if (cmd) {
 
61
 
 
62
                        gchar **args = g_strsplit(cmd, " ", 0);
 
63
 
 
64
                        int len = 0;
 
65
                        if (args) {
 
66
                                while (*(args + len)) {
 
67
                                        g_strstrip(*(args + len));
 
68
                                        len++;
 
69
                                }
 
70
                        }
 
71
 
 
72
                        if (len > 0) {
 
73
                                add_history(cmd);
 
74
                                if (!strcmp(*args, "quit"))
 
75
                                        loop = FALSE;
 
76
 
 
77
                                if (!strcmp(*args, "get") && len >= 2) {
 
78
                                        plist_t value = NULL;
 
79
                                        if (LOCKDOWN_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL,  len == 3 ? *(args + 2):*(args + 1), &value))
 
80
                                        {
 
81
                                                char *xml = NULL;
 
82
                                                uint32_t length;
 
83
                                                plist_to_xml(value, &xml, &length);
 
84
                                                printf("Success : value = %s\n", xml);
 
85
                                                free(xml);
 
86
                                        }
 
87
                                        else
 
88
                                                printf("Error\n");
 
89
 
 
90
                                        if (value)
 
91
                                                plist_free(value);
 
92
                                }
 
93
 
 
94
                                if (!strcmp(*args, "start") && len == 2) {
 
95
                                        uint16_t port = 0;
 
96
                                        if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &port)) {
 
97
                                                printf("started service %s on port %i\n", *(args + 1), port);
 
98
                                        }
 
99
                                        else
 
100
                                        {
 
101
                                                printf("failed to start service %s on device.\n", *(args + 1));
 
102
                                        }
 
103
                                }
 
104
                        }
 
105
                        g_strfreev(args);
 
106
                }
 
107
                free(cmd);
 
108
                cmd = NULL;
 
109
        }
 
110
        clear_history();
 
111
        lockdownd_client_free(client);
 
112
        idevice_free(phone);
 
113
 
 
114
        return 0;
 
115
}