Пример #1
0
void append_card_to_object(JsonNode *obj, char *user, char *device)
{
	char path[BUFSIZ], path1[BUFSIZ], *cardfile = NULL;
	JsonNode *card;

	if (!user || !*user)
		return;


	snprintf(path, BUFSIZ, "%s/cards/%s/%s/%s-%s.json",
		STORAGEDIR, user, device, user, device);
	if (access(path, R_OK) == 0) {
		cardfile = path;
	} else {
		snprintf(path1, BUFSIZ, "%s/cards/%s/%s.json",
			STORAGEDIR, user, user);

		if (access(path1, R_OK) == 0) {
			cardfile = path1;
		}
	}

	card = json_mkobject();
	if (cardfile && json_copy_from_file(card, cardfile) == TRUE) {
		json_copy_to_object(obj, card, FALSE);
	}
	json_delete(card);
}
Пример #2
0
void append_device_details(JsonNode *userlist, char *user, char *device)
{
	char path[BUFSIZ];
	JsonNode *node, *last, *card;

	snprintf(path, BUFSIZ, "%s/last/%s/%s/%s-%s.json",
		STORAGEDIR, user, device, user, device);

	last = json_mkobject();
	if (json_copy_from_file(last, path) == TRUE) {
		JsonNode *tst;

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

		json_append_element(userlist, last);
	} else {
		json_delete(last);
	}

	snprintf(path, BUFSIZ, "%s/cards/%s/%s.json",
		STORAGEDIR, user, user);

	card = json_mkobject();
	if (json_copy_from_file(card, path) == TRUE) {
		json_copy_to_object(last, card, FALSE);
	}
	json_delete(card);

	if ((node = json_find_member(last, "ghash")) != NULL) {
		if (node->tag == JSON_STRING) {
			get_geo(last, node->string_);
		}
	}
}
Пример #3
0
void append_device_details(JsonNode *userlist, char *user, char *device)
{
	char path[BUFSIZ];
	JsonNode *node, *last;

	snprintf(path, BUFSIZ, "%s/last/%s/%s/%s-%s.json",
		STORAGEDIR, user, device, user, device);

	last = json_mkobject();
	if (json_copy_from_file(last, path) == TRUE) {
		JsonNode *tst;

		if ((tst = json_find_member(last, "tst")) != NULL) {
			json_append_member(last, "isotst", json_mkstring(isotime(tst->number_)));
			json_append_member(last, "disptst", json_mkstring(disptime(tst->number_)));
		}
	}

	append_card_to_object(last, user, device);


	if ((node = json_find_member(last, "ghash")) != NULL) {
		if (node->tag == JSON_STRING) {
			get_geo(last, node->string_);
		}
	}

	/* Extra data */
	snprintf(path, BUFSIZ, "%s/last/%s/%s/extra.json",
		STORAGEDIR, user, device);
	json_copy_from_file(last, path);
#if WITH_GREENWICH
	get_gw_data(user, device, last);
#endif
	json_append_element(userlist, last);
}