예제 #1
0
파일: ripcurl.c 프로젝트: dluco/ripcurl
void cb_inputbar_activate(GtkEntry *entry, Browser *b)
{
	char *input, **tokens, *command;
	char identifier;
	int i, n;
	gboolean ret = FALSE;
	gboolean processed = FALSE;
	GList *list;

	input = strdup(gtk_entry_get_text(entry));

	if (strlen(input) <= 1) {
		/* no input */
		free(input);
		/* hide inputbar */
		isc_abort(b, NULL);
		return;
	}

	identifier = input[0];

	/* special commands */
	for (i = 0; i < LENGTH(special_commands); i++) {
		if (identifier == special_commands[i].identifier) {
			ret = special_commands[i].func(b, input + 1, &(special_commands[i].arg), TRUE);

			gtk_widget_grab_focus(GTK_WIDGET(b->UI.scrolled_window));
			/* ret == TRUE: hide inputbar */
			if (ret) {
				isc_abort(b, NULL);
			}
			free(input);
			return;
		}
	}

	/* append input to command history */
	if (!private_browsing) {
		ripcurl->Global.command_history = g_list_append(ripcurl->Global.command_history, strdup(input));
	}

	/* tokenize input, skipping first char */
	tokens = tokenize(input + 1, " ");
	free(input);
	command = tokens[0];
	n = strlenv(tokens);

	/* search commands */
	for (i = 0; i < LENGTH(commands); i++) {
		if ((strcmp_s(command, commands[i].name) == 0)
				|| (strcmp_s(command, commands[i].abbrv) == 0)) {
			ret = commands[i].func(b, n - 1, tokens + 1);
			processed = TRUE;
			break;
		}
	}

	if (!processed) {
		browser_notify(b, ERROR, "Unknown command");
	}

	/* check if b was destroyed by a command */
	for (list = ripcurl->Global.browsers; list; list = g_list_next(list)) {
		if (list->data == b) {
			/* browser found - grab focus */
			gtk_widget_grab_focus(GTK_WIDGET(b->UI.scrolled_window));

			/* ret == TRUE: hide inputbar */
			if (ret) {
				isc_abort(b, NULL);
			}
		}
	}

	strfreev(tokens);
}
예제 #2
0
int main(int argc, char *argv[])
{
	lockdownd_client_t client = NULL;
	idevice_t phone = NULL;

	idevice_set_debug_level(1);

	if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) {
		printf("No device found, is it plugged in?\n");
		return -1;
	}

	char *udid = NULL;
	if (IDEVICE_E_SUCCESS == idevice_get_udid(phone, &udid)) {
		printf("DeviceUniqueID : %s\n", udid);
	}
	if (udid)
		free(udid);

	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "lckdclient")) {
		idevice_free(phone);
		return -1;
	}

	using_history();
	int loop = 1;
	while (loop) {
		char *cmd = readline("> ");
		if (cmd) {

			char **args = get_tokens(cmd);

			int len = 0;
			while (args && args[len]) {
				len++;
			}

			if (len > 0) {
				add_history(cmd);
				if (!strcmp(*args, "quit"))
					loop = 0;

				if (!strcmp(*args, "get") && len >= 2) {
					plist_t value = NULL;
					if (LOCKDOWN_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL,  len == 3 ? *(args + 2):*(args + 1), &value))
					{
						char *xml = NULL;
						uint32_t length;
						plist_to_xml(value, &xml, &length);
						printf("Success : value = %s\n", xml);
						free(xml);
					}
					else
						printf("Error\n");

					if (value)
						plist_free(value);
				}

				if (!strcmp(*args, "start") && len == 2) {
					uint16_t port = 0;
					if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &port)) {
						printf("started service %s on port %i\n", *(args + 1), port);
					}
					else
					{
						printf("failed to start service %s on device.\n", *(args + 1));
					}
				}
			}
			strfreev(args);
		}
		free(cmd);
		cmd = NULL;
	}
	clear_history();
	lockdownd_client_free(client);
	idevice_free(phone);

	return 0;
}