Beispiel #1
0
int
main (int argc, char **argv)
{
	int size;
	FILE *f;
	char *filename, *jsonstr;

	filename = argv[1];
	if ((f = fopen (filename, "r")) == NULL) {
		fprintf (stderr, "error opening file\n");
		return (1);
	}

	fseek (f, 0, SEEK_END);
	size = ftell (f);
	fseek (f, 0, SEEK_SET);
	if ((jsonstr = malloc (size+1)) == NULL) {
		fprintf (stderr, "out of memory\n");
		return (1);
	}
	size = fread (jsonstr, 1, size, f);
	jsonstr[size] = 0;

	json_print (json_decode (jsonstr));

	return (0);
}
Beispiel #2
0
static void get_gw_data(char *username, char *device, JsonNode *last)
{
	JsonNode *array;
	static char *types[] = { "batt", "ext", "status", NULL };
	char **t, *js;
	static UT_string *ts = NULL, *u = NULL, *d = NULL;

	if (last == NULL || last->tag != JSON_OBJECT)
		return;


	for (t = types; t && *t; t++) {
		utstring_renew(u);
		utstring_renew(d);
		utstring_printf(u, "%s", username);
		utstring_printf(d, "%s", device);
		lowercase(UB(u));
		lowercase(UB(d));
		utstring_renew(ts);
		utstring_printf(ts, "%s/last/%s/%s/%s.json",
					STORAGEDIR,
					UB(u),
					UB(d),
					*t);

		/* Read file into JSON array and append to `last' object */
		if ((js = slurp_file(UB(ts), TRUE)) != NULL) {
			if ((array = json_decode(js)) != NULL) {
				json_append_member(last, *t, array);
			}
			free(js);
		}
	}
}
Beispiel #3
0
static void events_queue(char *message) {
	logprintf(LOG_STACK, "%s(...)", __FUNCTION__);

	pthread_mutex_lock(&events_lock);
	if(eventsqueue_number < 1024) {
		struct eventsqueue_t *enode = MALLOC(sizeof(eventsqueue_t));
		if(enode == NULL) {
			logprintf(LOG_ERR, "out of memory");
			exit(EXIT_FAILURE);
		}
		enode->jconfig = json_decode(message);

		if(eventsqueue_number == 0) {
			eventsqueue = enode;
			eventsqueue_head = enode;
		} else {
			eventsqueue_head->next = enode;
			eventsqueue_head = enode;
		}

		eventsqueue_number++;
	} else {
		logprintf(LOG_ERR, "event queue full");
	}
	pthread_mutex_unlock(&events_lock);
	pthread_cond_signal(&events_signal);
}
Beispiel #4
0
static struct threadqueue_t *initDev(JsonNode *jdevice) {
	char *platform = GPIO_PLATFORM;

	if(config_setting_get_string("gpio-platform", 0, &platform) != 0) {
		logprintf(LOG_ERR, "no gpio-platform configured");
		return NULL;
	}
	if(strcmp(platform, "none") == 0) {
		FREE(platform);
		logprintf(LOG_ERR, "no gpio-platform configured");
		return NULL;
	}
	if(wiringXSetup(platform, logprintf1) < 0) {
		FREE(platform);
		return NULL;
	}
	FREE(platform);

	loop = 1;
	char *output = json_stringify(jdevice, NULL);
	JsonNode *json = json_decode(output);
	json_free(output);

	struct protocol_threads_t *node = protocol_thread_init(gpio_switch, json);
	return threads_register("gpio_switch", &thread, (void *)node, 0);
}
Beispiel #5
0
static JsonNode *line_to_location(char *line)
{
	JsonNode *json, *o, *j;
	char *ghash;
	char tstamp[64], *bp;
	double lat, lon;
	long tst;

	snprintf(tstamp, 21, "%s", line);

	if ((bp = strchr(line, '{')) == NULL)
		return (NULL);

	if ((json = json_decode(bp)) == NULL) {
		return (NULL);
	}

	if ((j = json_find_member(json, "_type")) == NULL) {
		json_delete(json);
		return (NULL);
	}
	if (j->tag != JSON_STRING || strcmp(j->string_, "location") != 0) {
		json_delete(json);
		return (NULL);
	}

	o = json_mkobject();

	if (json_copy_to_object(o, json, FALSE) == FALSE) {
		json_delete(o);
		json_delete(json);
		return (NULL);
	}
	json_delete(json);	/* Done with this -- we've copied it. */

	lat = lon = 0.0;
	if ((j = json_find_member(o, "lat")) != NULL) {
		lat = j->number_;
	}
	if ((j = json_find_member(o, "lon")) != NULL) {
		lon = j->number_;
	}

	if ((ghash = geohash_encode(lat, lon, geohash_prec())) != NULL) {
		json_append_member(o, "ghash", json_mkstring(ghash));
		get_geo(o, ghash);
		free(ghash);
	}

	json_append_member(o, "isorcv", json_mkstring(tstamp));

	tst = 0L;
	if ((j = json_find_member(o, "tst")) != NULL) {
		tst = j->number_;
	}
	json_append_member(o, "isotst", json_mkstring(isotime(tst)));

	return (o);
}
Beispiel #6
0
struct threadqueue_t *programInitDev(JsonNode *jdevice) {
	program_loop = 1;
	char *output = json_stringify(jdevice, NULL);
	JsonNode *json = json_decode(output);
	sfree((void *)&output);

	struct protocol_threads_t *node = protocol_thread_init(program, json);	
	return threads_register("program", &programParse, (void *)node, 0);
}
Beispiel #7
0
struct threadqueue_t *ds18b20InitDev(JsonNode *jdevice) {
	ds18b20_loop = 1;
	char *output = json_stringify(jdevice, NULL);
	JsonNode *json = json_decode(output);
	sfree((void *)&output);

	struct protocol_threads_t *node = protocol_thread_init(ds18b20, json);
	return threads_register("ds18b20", &ds18b20Parse, (void *)node, 0);
}
Beispiel #8
0
static struct threadqueue_t *initDev(JsonNode *jdevice) {
	loop = 1;
	char *output = json_stringify(jdevice, NULL);
	JsonNode *json = json_decode(output);
	json_free(output);

	struct protocol_threads_t *node = protocol_thread_init(ds18s20, json);
	return threads_register("ds18s20", &thread, (void *)node, 0);
}
Beispiel #9
0
struct threadqueue_t *xbmcInitDev(JsonNode *jdevice) {
	xbmc_loop = 1;
	char *output = json_stringify(jdevice, NULL);
	JsonNode *json = json_decode(output);
	sfree((void *)&output);

	struct protocol_threads_t *node = protocol_thread_init(xbmc, json);	
	return threads_register("xbmc", &xbmcParse, (void *)node, 0);
}
Beispiel #10
0
static struct threadqueue_t *dht22InitDev(JsonNode *jdevice) {
	dht22_loop = 1;
	wiringXSetup();
	char *output = json_stringify(jdevice, NULL);
	JsonNode *json = json_decode(output);
	json_free(output);

	struct protocol_threads_t *node = protocol_thread_init(dht22, json);
	return threads_register("dht22", &dht22Parse, (void *)node, 0);
}
Beispiel #11
0
static JsonNode *registry_sync(int level, const char *display) {
	if(registry != NULL) {
		char *content = json_stringify(registry, NULL);
		struct JsonNode *jret = json_decode(content);
		json_free(content);
		return jret;
	} else {
		return NULL;
	}
}
Beispiel #12
0
static int registry_parse(JsonNode *root) {
	if(root->tag == JSON_OBJECT) {
		char *content = json_stringify(root, NULL);
		registry = json_decode(content);
		json_free(content);
	} else {
		logprintf(LOG_ERR, "config registry should be of an object type");
		return -1;
	}
	return 0;
}
Beispiel #13
0
static int ldecode(lua_State *L) {
    if(!lua_isstring(L, 1)) {
        printf("is not string\n");
        return 0;
    }
    char *str = (char *)lua_tostring(L, 1);
    if(json_decode(L, str) == 0) {
        printf("decode fail\n");
        return 0;
    }
    return 1;
}
Beispiel #14
0
void test_gen(const char* in_file,
              const char* out_dir)
{
/* get the pathname to the json file*/
  slist* jlist=json_decode(in_file);
  if(!jlist)
    return;
  /*enter the json symbols into lisp symbol table*/
  run_gen_script(out_dir,jlist);
  //process_json(jlist);
  slist_destroy(jlist,free);  
}
Beispiel #15
0
int LuaDB_JsonDecode(lua_State *L) {
    size_t len;
    const char *str = luaL_checklstring(L, 1, &len);

    JsonNode *json = json_decode(str);
    if (!json) {
        lua_pushnil(L);
        return 1;
    }

    JsonToLuaValue(L, json);
    json_delete(json);
    return 1;
}
Beispiel #16
0
int
main (int argc, char **argv)
{
	FILE *f;
	char *infile, *outfile, buf[1000], jsonstr[10000];
	struct json *inp_json, *outp_json;

	if (argc != 2)
		usage ();

	infile = argv[1];

	if ((f = fopen (infile, "r")) == NULL) {
		fprintf (stderr, "error opening file\n");
		return (1);
	}

	memset (&jsonstr, 0, sizeof jsonstr);
	while (fgets (buf, sizeof buf, f) != NULL) {
		sprintf (jsonstr, "%s%s", jsonstr, buf);
	}
	
	inp_json = json_decode (jsonstr);

	fclose (f);

	outp_json = json_dup (inp_json);

	if (strcmp (json_objref_str (inp_json, "first"), "1") == 0) {
		init (outp_json);
	} else {
		alert ();
		rerun (outp_json);
	}

	outfile = json_objref_str (inp_json, "outfile");
	if ((f = fopen (outfile, "w")) == NULL) {
		fprintf (stderr, "error opening %s for writing: %m\n", outfile);
		return (1);
	}

	char *newjson;
	newjson = json_encode (outp_json);
	fwrite (newjson, 1, strlen (newjson), f);
	fwrite ("\n", 1, 1, f);
	fclose (f);

	return (0);
}
Beispiel #17
0
void OdinIO::onMessage(n::WebSocket *ws, const n::WebSocket::Data &data) {
  auto evt= json_decode(data);
  c::RefPtr<OdinEvent>
  ref(evt);

  switch (evt->getType()) {
    case MType::NETWORK:
    case MType::SESSION:
      onEvent(evt);
    break;
    default:
      CCLOG("unhandled server event: %d, code: %d",
          (int) evt->getType(), (int) evt->getCode());
  }
}
bool json_decode_object(std::istrstream& is, T& object)
{
    object = T(); // empty it.
    try
    {
        json_spirit::Value value;
        read(is, value);
        const json_spirit::Object& root = value.get_obj();
        return json_decode(root, object);
    }
    catch (std::exception& e)
    {
        BOOST_LOG_TRIVIAL(error) << "json_decode(std::istream&, " << typeid(T).name() << " exception: " << e.what();
        return false;
    }
}
Beispiel #19
0
int config_read(void) {
    logprintf(LOG_STACK, "%s(...)", __FUNCTION__);

    FILE *fp = NULL;
    char *content = NULL;
    size_t bytes = 0;
    struct JsonNode *root = NULL;
    struct stat st;

    /* Read JSON config file */
    if(!(fp = fopen(configfile, "rb"))) {
        logprintf(LOG_ERR, "cannot read config file: %s", configfile);
        return EXIT_FAILURE;
    }

    fstat(fileno(fp), &st);
    bytes = (size_t)st.st_size;

    if(!(content = CALLOC(bytes+1, sizeof(char)))) {
        logprintf(LOG_ERR, "out of memory");
        fclose(fp);
        return EXIT_FAILURE;
    }

    if(fread(content, sizeof(char), bytes, fp) == -1) {
        logprintf(LOG_ERR, "cannot read config file: %s", configfile);
    }
    fclose(fp);

    /* Validate JSON and turn into JSON object */
    if(json_validate(content) == false) {
        logprintf(LOG_ERR, "config is not in a valid json format");
        FREE(content);
        return EXIT_FAILURE;
    }
    root = json_decode(content);

    if(config_parse(root) != EXIT_SUCCESS) {
        FREE(content);
        json_delete(root);
        return EXIT_FAILURE;
    }
    json_delete(root);
    config_write(1, "all");
    FREE(content);
    return EXIT_SUCCESS;
}
Beispiel #20
0
JsonNode *vnode(char *str, int flags)
{

	if (strlen(str) == 0) {
		return json_mknull();
	}

	/* If str begins with a double quote, keep it a string */

	if (*str == '"') {
		char *bp = str + strlen(str) - 1;

		if (bp > str && *bp == '"')
			*bp = 0;		/* Chop closing double quote */
		return json_mkstring(str + 1);
	}

	char *endptr;
	double num = strtod(str, &endptr);

	if (!*endptr && isfinite(num)) {
		return json_mknumber(num);
	}

	if (!(flags & FLAG_NOBOOL)) {
		if (strcmp(str, "true") == 0) {
			return json_mkbool(true);
		} else if (strcmp(str, "false") == 0) {
			return json_mkbool(false);
		}
	}

	if (*str == '{' || *str == '[') {
		JsonNode *obj = json_decode(str);

		if (obj == NULL) {
			/* JSON cannot be decoded; return the string */
			// fprintf(stderr, "Cannot decode JSON from %s\n", str);

			obj = json_mkstring(str);
		}

		return (obj);
	}

	return json_mkstring(str);
}
Beispiel #21
0
int settings_read(void) {
    FILE *fp;
    char *content;
    size_t bytes;
    JsonNode *root;
    struct stat st;

    /* Read JSON config file */
    if(!(fp = fopen(settingsfile, "rb"))) {
        logprintf(LOG_ERR, "cannot read settings file: %s", settingsfile);
        return EXIT_FAILURE;
    }

    fstat(fileno(fp), &st);
    bytes = (size_t)st.st_size;

    if(!(content = calloc(bytes+1, sizeof(char)))) {
        logprintf(LOG_ERR, "out of memory");
        fclose(fp);
        return EXIT_FAILURE;
    }

    if(fread(content, sizeof(char), bytes, fp) == -1) {
        logprintf(LOG_ERR, "cannot read settings file: %s", settingsfile);
    }
    fclose(fp);

    /* Validate JSON and turn into JSON object */
    if(json_validate(content) == false) {
        logprintf(LOG_ERR, "settings are not in a valid json format", content);
        sfree((void *)&content);
        return EXIT_FAILURE;
    }

    root = json_decode(content);

    if(settings_parse(root) != 0) {
        sfree((void *)&content);
        return EXIT_FAILURE;
    }
    char *output = json_stringify(root, "\t");
    settings_write(output);
    json_delete(root);
    sfree((void *)&output);
    sfree((void *)&content);
    return EXIT_SUCCESS;
}
Beispiel #22
0
/**
 * Get/set root hints set.
 *
 * Input:  { name: [addr_list], ... }
 * Output: current list
 *
 */
static char* hint_root(void *env, struct kr_module *module, const char *args)
{
	struct engine *engine = env;
	struct kr_context *ctx = &engine->resolver;
	/* Replace root hints if parameter is set */
	if (args && strlen(args) > 0) {
		JsonNode *node = NULL;
		JsonNode *root_node = json_decode(args);
		kr_zonecut_set(&ctx->root_hints, (const uint8_t *)"");
		json_foreach(node, root_node) {
			switch(node->tag) {
			case JSON_STRING: add_pair(&ctx->root_hints, node->key, node->string_); break;
			default: continue;
			}
		}
		json_delete(root_node);
	}
Beispiel #23
0
Result<Client::Request> ClientJson::to_request(Slice request) {
  auto request_str = request.str();
  TRY_RESULT(json_value, json_decode(request_str));
  if (json_value.type() != JsonValue::Type::Object) {
    return Status::Error("Expected an object");
  }
  TRY_RESULT(extra_field, get_json_object_field(json_value.get_object(), "@extra", JsonValue::Type::Null, true));
  std::uint64_t extra_id = extra_id_.fetch_add(1, std::memory_order_relaxed);
  auto extra_str = json_encode<string>(extra_field);
  if (!extra_str.empty()) {
    std::lock_guard<std::mutex> guard(mutex_);
    extra_[extra_id] = std::move(extra_str);
  }

  td_api::object_ptr<td_api::Function> func;
  TRY_STATUS(from_json(func, json_value));
  return Client::Request{extra_id, std::move(func)};
}
Beispiel #24
0
int
main (int argc, char *argv[])
{
    char *json = "{\"1\":{\"1a\":\"10\",\"1b\":\"20\"}, \"2\":{},"
	"\"3\":{\"3a\":\"30\"}}";
    char *json1 = "{}";
    ssr_t ssr;\
    json_t j[128];
    int    n;
    int    i;

    ssr.data = json;
    ssr.size = strlen(json);

    n = json_decode(&ssr, j, 128);

    for (i = 0; i < n; i++) {
	printf("Name: %.*s\n", (int)j[i].name.size, j[i].name.data);
	if (j[i].next) {
	    printf("Next = %.*s\n",
		   (int)j[i].next->name.size,
		   j[i].next->name.data);
	} else {
	    printf("No next\n");
	}
	switch(j[i].type) {
	case JSON_STRING:
	    printf("Value: %.*s\n",
		   (int)j[i].value.string.size, j[i].value.string.data);
	    break;
	case JSON_OBJECT:
	    if (j[i].value.object) {
		printf("Object, First child = %.*s\n",
		       (int)j[i].value.object->name.size,
		       j[i].value.object->name.data);
	    } else {
		printf("Empty object\n");
	    }
	    break;
	}
    }

    return (0);
}
Beispiel #25
0
/** Trampoline function for module properties. */
static int l_trampoline(lua_State *L)
{
	struct kr_module *module = lua_touserdata(L, lua_upvalueindex(1));
	void* callback = lua_touserdata(L, lua_upvalueindex(2));
	struct engine *engine = engine_luaget(L);
	if (!module) {
		lua_pushstring(L, "module closure missing upvalue");
		lua_error(L);
	}

	/* Now we only have property callback or config,
	 * if we expand the callables, we might need a callback_type.
	 */
	const char *args = NULL;
	auto_free char *cleanup_args = NULL;
	if (lua_gettop(L) > 0) {
		if (lua_istable(L, 1)) {
			cleanup_args = l_pack_json(L, 1);
			args = cleanup_args;
		} else {
			args = lua_tostring(L, 1);
		}
	}
	if (callback == module->config) {
		module->config(module, args);
	} else {
		kr_prop_cb *prop = (kr_prop_cb *)callback;
		auto_free char *ret = prop(engine, module, args);
		if (!ret) { /* No results */
			return 0;
		}
		JsonNode *root_node = json_decode(ret);
		if (root_node && (root_node->tag == JSON_OBJECT || root_node->tag == JSON_ARRAY)) {
			l_unpack_json(L, root_node);
		} else {
			lua_pushstring(L, ret);
		}
		json_delete(root_node);
		return 1;
	}

	/* No results */
	return 0;
}
Beispiel #26
0
int json_copy_from_file(JsonNode *obj, char *filename)
{
	char *js_string;
	JsonNode *node;

	if ((js_string = slurp_file(filename, TRUE)) == NULL) {
		return (FALSE);
	}

	if ((node = json_decode(js_string)) == NULL) {
		fprintf(stderr, "json_copy_from_file can't decode JSON from %s\n", filename);
		free(js_string);
		return (FALSE);
	}
	json_copy_to_object(obj, node, FALSE);
	json_delete(node);
	free(js_string);

	return (TRUE);
}
Beispiel #27
0
void
add_bday (struct json *json, char *jsonfile)
{
	FILE *f;
	char jsonstr[10000], buf[1000];
	struct json *inp_json;

	if ((f = fopen (jsonfile, "r")) == NULL) {
		fprintf (stderr, "error opening file\n");
		return;
	}

	memset (&jsonstr, 0, sizeof jsonstr);
	while (fgets (buf, sizeof buf, f) != NULL) {
		sprintf (jsonstr, "%s%s", jsonstr, buf);
	}

	inp_json = json_dup (json_decode (jsonstr));

	json_aset_json (json, json_array_size (json), inp_json);
}
int json_decode_odict(struct odict **op, uint32_t hash_size, const char *str,
		      size_t len, unsigned maxdepth)
{
	struct odict *o;
	int err;

	if (!op || !str)
		return EINVAL;

	err = odict_alloc(&o, hash_size);
	if (err)
		return err;

	err = json_decode(str, len, maxdepth, object_handler, array_handler,
			  object_entry_handler, array_entry_handler, o);
	if (err)
		mem_deref(o);
	else
		*op = o;

	return err;
}
Beispiel #29
0
JsonNode *gcache_json_get(struct gcache *gc, char *k)
{
	MDB_val key, data;
	MDB_txn *txn;
	int rc;
	JsonNode *json = NULL;

	if (gc == NULL)
		return (NULL);

	rc = mdb_txn_begin(gc->env, NULL, MDB_RDONLY, &txn);
	if (rc) {
		olog(LOG_ERR, "gcache_json_get: mdb_txn_begin: (%d) %s", rc, mdb_strerror(rc));
		return (NULL);
	}

	key.mv_data = k;
	key.mv_size = strlen(k);

	rc = mdb_get(txn, gc->dbi, &key, &data);
	if (rc != 0) {
		if (rc != MDB_NOTFOUND) {
			olog(LOG_ERR, "gcache_json_get(%s): %s", k, mdb_strerror(rc));
		} else {
			// printf(" [%s] not found\n", k);
			json = NULL;
		}
	} else {
		// printf("%s\n", (char *)data.mv_data);
		if ((json = json_decode((char *)data.mv_data)) == NULL) {
			olog(LOG_ERR, "gcache_json_get: Cannot decode JSON from lmdb");
		}
	}

	mdb_txn_commit(txn);

	return (json);
}
Beispiel #30
0
int main(int argc, char **argv) {
	// memtrack();

	atomicinit();
	gc_attach(main_gc);

	/* Catch all exit signals for gc */
	gc_catch();

	log_shell_enable();
	log_file_disable();

	log_level_set(LOG_NOTICE);

	if((progname = MALLOC(16)) == NULL) {
		fprintf(stderr, "out of memory\n");
		exit(EXIT_FAILURE);
	}
	strcpy(progname, "pilight-receive");
	struct options_t *options = NULL;
	struct ssdp_list_t *ssdp_list = NULL;

	char *server = NULL;
	unsigned short port = 0;
	unsigned short stats = 0;

	char *args = NULL;

	options_add(&options, 'H', "help", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL);
	options_add(&options, 'V', "version", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL);
	options_add(&options, 'S', "server", OPTION_HAS_VALUE, 0, JSON_NULL, NULL, "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
	options_add(&options, 'P', "port", OPTION_HAS_VALUE, 0, JSON_NULL, NULL, "[0-9]{1,4}");
	options_add(&options, 's', "stats", OPTION_NO_VALUE, 0, JSON_NULL, NULL, "[0-9]{1,4}");

	/* Store all CLI arguments for later usage
	   and also check if the CLI arguments where
	   used correctly by the user. This will also
	   fill all necessary values in the options struct */
	while(1) {
		int c;
		c = options_parse(&options, argc, argv, 1, &args);
		if(c == -1)
			break;
		if(c == -2)
			c = 'H';
		switch(c) {
			case 'H':
				printf("\t -H --help\t\t\tdisplay this message\n");
				printf("\t -V --version\t\t\tdisplay version\n");
				printf("\t -S --server=x.x.x.x\t\tconnect to server address\n");
				printf("\t -P --port=xxxx\t\t\tconnect to server port\n");
				printf("\t -s --stats\t\t\tshow CPU and RAM statistics\n");
				exit(EXIT_SUCCESS);
			break;
			case 'V':
				printf("%s v%s\n", progname, PILIGHT_VERSION);
				exit(EXIT_SUCCESS);
			break;
			case 'S':
				if((server = MALLOC(strlen(args)+1)) == NULL) {
					fprintf(stderr, "out of memory\n");
					exit(EXIT_FAILURE);
				}
				strcpy(server, args);
			break;
			case 'P':
				port = (unsigned short)atoi(args);
			break;
			case 's':
				stats = 1;
			break;
			default:
				printf("Usage: %s -l location -d device\n", progname);
				exit(EXIT_SUCCESS);
			break;
		}
	}
	options_delete(options);

	if(server != NULL && port > 0) {
		if((sockfd = socket_connect(server, port)) == -1) {
			logprintf(LOG_ERR, "could not connect to pilight-daemon");
			return EXIT_FAILURE;
		}
	} else if(ssdp_seek(&ssdp_list) == -1) {
		logprintf(LOG_NOTICE, "no pilight ssdp connections found");
		goto close;
	} else {
		if((sockfd = socket_connect(ssdp_list->ip, ssdp_list->port)) == -1) {
			logprintf(LOG_ERR, "could not connect to pilight-daemon");
			goto close;
		}
	}
	if(ssdp_list != NULL) {
		ssdp_free(ssdp_list);
	}
	if(server != NULL) {
		FREE(server);
	}

	struct JsonNode *jclient = json_mkobject();
	struct JsonNode *joptions = json_mkobject();
	json_append_member(jclient, "action", json_mkstring("identify"));
	json_append_member(joptions, "receiver", json_mknumber(1, 0));
	json_append_member(joptions, "stats", json_mknumber(stats, 0));
	json_append_member(jclient, "options", joptions);
	char *out = json_stringify(jclient, NULL);
	socket_write(sockfd, out);
	json_free(out);
	json_delete(jclient);

	if(socket_read(sockfd, &recvBuff, 0) != 0 ||
     strcmp(recvBuff, "{\"status\":\"success\"}") != 0) {
		goto close;
	}

	while(main_loop) {
		if(socket_read(sockfd, &recvBuff, 0) != 0) {
			goto close;
		}
		char **array = NULL;
		unsigned int n = explode(recvBuff, "\n", &array), i = 0;
		for(i=0;i<n;i++) {
			struct JsonNode *jcontent = json_decode(array[i]);
			struct JsonNode *jtype = json_find_member(jcontent, "type");
			if(jtype != NULL) {
				json_remove_from_parent(jtype);
				json_delete(jtype);
			}
			char *content = json_stringify(jcontent, "\t");
			printf("%s\n", content);
			json_delete(jcontent);
			json_free(content);
		}
		array_free(&array, n);
	}

close:
	if(sockfd > 0) {
		socket_close(sockfd);
	}
	if(recvBuff != NULL) {
		FREE(recvBuff);
		recvBuff = NULL;
	}
	options_gc();
	log_shell_disable();
	log_gc();
	FREE(progname);
	return EXIT_SUCCESS;
}