Example #1
0
static void get_messages_listing_resp(const char **reply, void *user_data)
{
	struct session *session = user_data;
	struct request *request = session->request;
	struct messages_message *msg_data;

	DBG("reply %p", reply);

	if (reply == NULL)
		goto done;

	if (session->aborted)
		goto aborted;

	msg_data = pull_message_data(reply);

	request->size++;

	if (!msg_data->read)
			request->new_message = TRUE;

	if (request->count == TRUE) {
		free_msg_data(msg_data);
		return;
	}

	if (request->size > request->offset && filter_message(msg_data,
							request->filter))
		request->cb.messages_list(session, -EAGAIN, 1,
						request->new_message, msg_data,
						request->user_data);

	free_msg_data(msg_data);
	return;

done:
	request->cb.messages_list(session, 0, request->size,
						request->new_message, NULL,
						request->user_data);

aborted:
	g_free(request->filter->period_begin);
	g_free(request->filter->period_end);
	g_free(request->filter->originator);
	g_free(request->filter->recipient);
	g_free(request->filter);

	g_free(request);
}
// terminate all profiling by critical error
// TODO: don't send data to host
static void terminate_error(char *errstr, int send_to_host)
{
	LOGE("termination all with err '%s'\n", errstr);
	struct msg_data_t *msg = NULL;
	if (send_to_host != 0) {
		msg = gen_message_error(errstr);
		if (msg) {
			if (write_to_buf(msg) != 0)
				LOGE("write to buf fail\n");
			free_msg_data(msg);
		} else {
			LOGI("cannot generate error message\n");
		}
	}
	terminate_all();
}