コード例 #1
0
ファイル: client.c プロジェクト: kscanne/caighdean
void parse_json(char* j) {
    while (isspace(*j)) j++;
    if (*j != '[') error("Malformed JSON.");
    j++;
    while (isspace(*j)) j++;
    while (*j == '[') {
        j++;
        while (isspace(*j)) j++;
        if (*j != '"') error("Malformed JSON.");
        j++;
        j = print_json_string(j);
        printf(" => ");
        while (isspace(*j)) j++;
        if (*j != ',') error("Malformed JSON.");
        j++;
        while (isspace(*j)) j++;
        if (*j != '"') error("Malformed JSON.");
        j++;
        j = print_json_string(j);
        printf("\n");
        while (isspace(*j)) j++;
        if (*j != ']') error("Malformed JSON.");
        j++;
        while (isspace(*j)) j++;
        if (*j == ']') break;
        if (*j != ',') error("Malformed JSON.");
        j++;
        while (isspace(*j)) j++;
    }
}
コード例 #2
0
ファイル: sketch_hiredis03.c プロジェクト: rdpoor/mu
void print_json_aux(json_t *element, int indent) {
  switch json_typeof(element) {
    case JSON_OBJECT:
      print_json_object(element, indent);
      break;
    case JSON_ARRAY:
      print_json_array(element, indent);
      break;
    case JSON_STRING:
      print_json_string(element, indent);
      break;
    case JSON_INTEGER:
      print_json_integer(element, indent);
      break;
    case JSON_REAL:
      print_json_real(element, indent);;
      break;
    case JSON_TRUE:
      print_json_true(element, indent);;
      break;
    case JSON_FALSE:
      print_json_false(element, indent);;
      break;
    case JSON_NULL:
      print_json_null(element, indent);;
      break;
    default:
      fprintf(stderr, "unrecognized JSON type %d\n", json_typeof(element));
    }
}
コード例 #3
0
static void cb_Notify(DBusConnection *connection, DBusMessage *message)
{
	DBusMessage *message_reply = NULL;
	DBusMessageIter arguments;
	int current_type = DBUS_TYPE_INVALID;
	unsigned int argument_count = 0;
	char *notification_app_name = NULL;
	unsigned long int notification_replaces_id = 0;
	char *notification_summary = NULL;
	char *notification_body = NULL;
	long int notification_expire_timeout = 0;
	
	if(!dbus_message_iter_init(message, &arguments))
	{
		fprintf(stderr, "Failed to read notify arguments.\n");
		return;
	}
	
	while((current_type = dbus_message_iter_get_arg_type(&arguments)) != DBUS_TYPE_INVALID)
	{
		if(argument_count == 0 && current_type == DBUS_TYPE_STRING)
		{
			dbus_message_iter_get_basic(&arguments, &notification_app_name);
		}
		else if(argument_count == 1 && current_type == DBUS_TYPE_UINT32)
		{
			dbus_message_iter_get_basic(&arguments, &notification_replaces_id);
		}
		else if(argument_count == 3 && current_type == DBUS_TYPE_STRING)
		{
			dbus_message_iter_get_basic(&arguments, &notification_body);
		}
		else if(argument_count == 4 && current_type == DBUS_TYPE_STRING)
		{
			dbus_message_iter_get_basic(&arguments, &notification_summary);
		}
		else if(argument_count == 7 && current_type == DBUS_TYPE_INT32)
		{
			dbus_message_iter_get_basic(&arguments, &notification_expire_timeout);
		}
		
		argument_count++;
		dbus_message_iter_next(&arguments);
	}
	
	printf("{\"app_name\":\"");
	print_json_string(notification_app_name);
	printf("\",\"body\":\"");
	print_json_string(notification_body);
	printf("\",\"summary\":\"");
	print_json_string(notification_summary);
	printf("\",\"expire_timeout\":%li}\n", notification_expire_timeout);
	
	message_reply = dbus_message_new_method_return(message);
	
	dbus_message_iter_init_append(message_reply, &arguments);
	if(!dbus_message_iter_append_basic(&arguments, DBUS_TYPE_UINT32, &notification_replaces_id))
	{
		fprintf(stderr, "Failed to append notify.\n");
		return;
	}
	
	if(!dbus_connection_send(connection, message_reply, NULL))
	{
		fprintf(stderr, "Failed to send notify.\n");
	}
	
	dbus_connection_flush(connection);
	
	dbus_message_unref(message_reply);
}