Example #1
0
static void script_exited(GPid pid, int status, void *data)
{
	struct capability_object *object = data;
	char buf[128];

	object->pid = -1;

	DBG("pid: %d status: %d", pid, status);

	g_spawn_close_pid(pid);

	/* free the object if aborted */
	if (object->aborted) {
		if (object->buffer != NULL)
			g_string_free(object->buffer, TRUE);

		g_free(object);
		return;
	}

	if (WEXITSTATUS(status) != EXIT_SUCCESS) {
		memset(buf, 0, sizeof(buf));
		if (read(object->err, buf, sizeof(buf)) > 0)
			error("%s", buf);
		obex_object_set_io_flags(data, G_IO_ERR, -EPERM);
	} else
		obex_object_set_io_flags(data, G_IO_IN, 0);
}
Example #2
0
static gboolean reply_signal(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct synce_context *context = data;
	const char *path = dbus_message_get_path(msg);
	DBusMessageIter iter, array_iter;
	char *value;
	int length;

	if (strcmp(context->conn_obj, path) != 0) {
		obex_object_set_io_flags(context, G_IO_ERR, -EPERM);
		context->lasterr = -EPERM;
		return FALSE;
	}

	dbus_message_iter_init(msg, &iter);

	dbus_message_iter_recurse(&iter, &array_iter);
	dbus_message_iter_get_fixed_array(&array_iter, &value, &length);

	context->buffer = g_string_new_len(value, length);
	obex_object_set_io_flags(context, G_IO_IN, 0);
	context->lasterr = 0;

	return TRUE;
}
Example #3
0
static void get_folder_listing_cb(void *session, int err, uint16_t size,
					const char *name, void *user_data)
{
	struct mas_session *mas = user_data;
	uint16_t max = 1024;

	if (err < 0 && err != -EAGAIN) {
		obex_object_set_io_flags(mas, G_IO_ERR, err);
		return;
	}

	if (mas->inparams)
		g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT,
									&max);

	if (max == 0) {
		if (err != -EAGAIN)
			mas->outparams = g_obex_apparam_set_uint16(
						mas->outparams,
						MAP_AP_FOLDERLISTINGSIZE,
						size);

		if (!name)
			mas->finished = TRUE;

		goto proceed;
	}

	if (!mas->nth_call) {
		g_string_append(mas->buffer, XML_DECL);
		g_string_append(mas->buffer, FL_DTD);
		if (!name) {
			g_string_append(mas->buffer, FL_BODY_EMPTY);
			mas->finished = TRUE;
			goto proceed;
		}
		g_string_append(mas->buffer, FL_BODY_BEGIN);
		mas->nth_call = TRUE;
	}

	if (!name) {
		g_string_append(mas->buffer, FL_BODY_END);
		mas->finished = TRUE;
		goto proceed;
	}

	if (g_strcmp0(name, "..") == 0)
		g_string_append(mas->buffer, FL_PARENT_FOLDER_ELEMENT);
	else
		g_string_append_escaped_printf(mas->buffer, FL_FOLDER_ELEMENT,
									name);

proceed:
	if (err != -EAGAIN)
		obex_object_set_io_flags(mas, G_IO_IN, err);
}
Example #4
0
static void set_status_cb(void *session, int err, void *user_data)
{
	struct mas_session *mas = user_data;

	DBG("");

	mas->finished = TRUE;

	if (err < 0)
		obex_object_set_io_flags(mas, G_IO_ERR, err);
	else
		obex_object_set_io_flags(mas, G_IO_OUT, 0);
}
Example #5
0
File: pbap.c Project: Sork007/obexd
static void phonebook_size_result(const char *buffer, size_t bufsize,
					int vcards, int missed,
					gboolean lastpart, void *user_data)
{
	struct pbap_session *pbap = user_data;
	uint16_t phonebooksize;

	if (pbap->obj->request) {
		phonebook_req_finalize(pbap->obj->request);
		pbap->obj->request = NULL;
	}

	if (vcards < 0)
		vcards = 0;

	DBG("vcards %d", vcards);

	phonebooksize = htons(vcards);

	pbap->obj->aparams = g_byte_array_new();
	pbap->obj->aparams = append_aparam_header(pbap->obj->aparams,
					PHONEBOOKSIZE_TAG, &phonebooksize);

	if (missed > 0)	{
		DBG("missed %d", missed);

		pbap->obj->aparams = append_aparam_header(pbap->obj->aparams,
						NEWMISSEDCALLS_TAG, &missed);
	}

	obex_object_set_io_flags(pbap->obj, G_IO_IN, 0);
}
Example #6
0
static void phonebook_size_result(const char *buffer, size_t bufsize,
					int vcards, int missed,
					gboolean lastpart, void *user_data)
{
	struct pbap_session *pbap = user_data;
	uint16_t phonebooksize;

	if (pbap->obj->request) {
		phonebook_req_finalize(pbap->obj->request);
		pbap->obj->request = NULL;
	}

	if (vcards < 0)
		vcards = 0;

	DBG("vcards %d", vcards);

	phonebooksize = vcards;

	pbap->obj->apparam = g_obex_apparam_set_uint16(NULL, PHONEBOOKSIZE_TAG,
								phonebooksize);

	pbap->obj->firstpacket = TRUE;

	if (missed > 0)	{
		DBG("missed %d", missed);

		pbap->obj->apparam = g_obex_apparam_set_uint16(
							pbap->obj->apparam,
							NEWMISSEDCALLS_TAG,
							missed);
	}

	obex_object_set_io_flags(pbap->obj, G_IO_IN, 0);
}
Example #7
0
static gboolean abort_signal(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct synce_context *context = data;

	obex_object_set_io_flags(context, G_IO_ERR, -EPERM);
	context->lasterr = -EPERM;

	return TRUE;
}
Example #8
0
static void query_result(const char *buffer, size_t bufsize, int vcards,
				int missed, gboolean lastpart, void *user_data)
{
	struct pbap_session *pbap = user_data;

	DBG("");

	if (pbap->obj->request && lastpart) {
		phonebook_req_finalize(pbap->obj->request);
		pbap->obj->request = NULL;
	}

	pbap->obj->lastpart = lastpart;

	if (vcards < 0) {
		obex_object_set_io_flags(pbap->obj, G_IO_ERR, -ENOENT);
		return;
	}

	if (!pbap->obj->buffer)
		pbap->obj->buffer = g_string_new_len(buffer, bufsize);
	else
		pbap->obj->buffer = g_string_append_len(pbap->obj->buffer,
							buffer,	bufsize);

	if (missed > 0)	{
		DBG("missed %d", missed);

		pbap->obj->firstpacket = TRUE;

		pbap->obj->apparam = g_obex_apparam_set_uint16(
							pbap->obj->apparam,
							NEWMISSEDCALLS_TAG,
							missed);
	}

	obex_object_set_io_flags(pbap->obj, G_IO_IN, 0);
}
Example #9
0
static void get_message_cb(void *session, int err, gboolean fmore,
	const char *chunk, void *user_data)
{
	struct mas_session *mas = user_data;

	DBG("");

	if (err < 0 && err != -EAGAIN) {
		obex_object_set_io_flags(mas, G_IO_ERR, err);
		return;
	}

	if (!chunk) {
		mas->finished = TRUE;
		goto proceed;
	}

	g_string_append(mas->buffer, chunk);

proceed:
	if (err != -EAGAIN)
		obex_object_set_io_flags(mas, G_IO_IN, 0);
}
Example #10
0
File: pbap.c Project: Sork007/obexd
static void cache_entry_done(void *user_data)
{
	struct pbap_session *pbap = user_data;
	const char *id;
	int ret;

	DBG("");

	pbap->cache.valid = TRUE;

	id = cache_find(&pbap->cache, pbap->find_handle);
	if (id == NULL) {
		DBG("Entry %d not found on cache", pbap->find_handle);
		obex_object_set_io_flags(pbap->obj, G_IO_ERR, -ENOENT);
		return;
	}

	phonebook_req_finalize(pbap->obj->request);
	pbap->obj->request = phonebook_get_entry(pbap->folder, id,
				pbap->params, query_result, pbap, &ret);
	if (ret < 0)
		obex_object_set_io_flags(pbap->obj, G_IO_ERR, ret);
}
Example #11
0
File: pbap.c Project: Sork007/obexd
static void cache_ready_notify(void *user_data)
{
	struct pbap_session *pbap = user_data;

	DBG("");

	phonebook_req_finalize(pbap->obj->request);
	pbap->obj->request = NULL;

	pbap->cache.valid = TRUE;

	generate_response(pbap);
	obex_object_set_io_flags(pbap->obj, G_IO_IN, 0);
}
Example #12
0
static void process_cb(DBusPendingCall *call, void *user_data)
{
	struct synce_context *context = user_data;
	DBusMessage *reply;
	DBusError derr;

	reply = dbus_pending_call_steal_reply(call);
	dbus_error_init(&derr);
	if (dbus_set_error_from_message(&derr, reply)) {
		error("process_cb(): syncevolution replied with an error:"
					" %s, %s", derr.name, derr.message);
		dbus_error_free(&derr);

		obex_object_set_io_flags(context, G_IO_ERR, -EPERM);
		context->lasterr = -EPERM;
		goto done;
	}

	obex_object_set_io_flags(context, G_IO_OUT, 0);
	context->lasterr = 0;

done:
	dbus_message_unref(reply);
}
Example #13
0
static void query_result(const char *buffer, size_t bufsize, int vcards,
				int missed, gboolean lastpart, void *user_data)
{
	struct irmc_session *irmc = user_data;
	const char *s, *t;

	DBG("bufsize %zu vcards %d missed %d", bufsize, vcards, missed);

	if (irmc->request) {
		phonebook_req_finalize(irmc->request);
		irmc->request = NULL;
	}

	/* first add a 'owner' vcard */
	if (!irmc->buffer)
		irmc->buffer = g_string_new(owner_vcard);
	else
		irmc->buffer = g_string_append(irmc->buffer, owner_vcard);

	if (buffer == NULL)
		goto done;

	/* loop around buffer and add X-IRMC-LUID attribs */
	s = buffer;
	while ((t = strstr(s, "UID:")) != NULL) {
		/* add upto UID: into buffer */
		irmc->buffer = g_string_append_len(irmc->buffer, s, t-s);
		/*
		 * add UID: line into buffer
		 * Not sure if UID is still needed if X-IRMC-LUID is there
		 */
		s = t;
		t = strstr(s, "\r\n");
		t += 2;
		irmc->buffer = g_string_append_len(irmc->buffer, s, t-s);
		/* add X-IRMC-LUID with same number as UID */
		irmc->buffer = g_string_append_len(irmc->buffer,
							"X-IRMC-LUID:", 12);
		s += 4; /* point to uid number */
		irmc->buffer = g_string_append_len(irmc->buffer, s, t-s);
		s = t;
	}
	/* add remaining bit of buffer */
	irmc->buffer = g_string_append(irmc->buffer, s);

done:
	obex_object_set_io_flags(irmc, G_IO_IN, 0);
}
Example #14
0
static void connect_cb(DBusPendingCall *call, void *user_data)
{
	struct synce_context *context = user_data;
	DBusConnection *conn;
	DBusMessage *reply;
	DBusError err;
	char *path;

	conn = context->dbus_conn;

	reply = dbus_pending_call_steal_reply(call);

	dbus_error_init(&err);
	if (dbus_message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH, &path,
						DBUS_TYPE_INVALID) == FALSE) {
		error("%s", err.message);
		dbus_error_free(&err);
		goto failed;
	}

	DBG("Got conn object %s from syncevolution", path);
	context->conn_obj = g_strdup(path);

	context->reply_watch = g_dbus_add_signal_watch(conn, NULL, path,
						SYNCE_CONN_INTERFACE, "Reply",
						reply_signal, context, NULL);

	context->abort_watch = g_dbus_add_signal_watch(conn, NULL, path,
						SYNCE_CONN_INTERFACE, "Abort",
						abort_signal, context, NULL);

	dbus_message_unref(reply);

	return;

failed:
	obex_object_set_io_flags(context, G_IO_ERR, -EPERM);
	context->lasterr = -EPERM;
}
Example #15
0
static void get_messages_listing_cb(void *session, int err,
		uint16_t size, gboolean newmsg,
		const struct messages_message *entry,
		void *user_data)
{
	struct mas_session *mas = user_data;

	if (err < 0 && err != -EAGAIN) {
		obex_object_set_io_flags(mas, G_IO_ERR, err);
		return;
	}

	if (!mas->nth_call) {
		g_string_append(mas->buffer, ML_BODY_BEGIN);
		mas->nth_call = TRUE;
	}

	if (!entry) {
		g_string_append(mas->buffer, ML_BODY_END);
		mas->finished = TRUE;

		goto proceed;
	}

	g_string_append(mas->buffer, "<msg");

	g_string_append_escaped_printf(mas->buffer, " handle=\"%s\"",
								entry->handle);

	if (entry->mask & PMASK_SUBJECT)
		g_string_append_escaped_printf(mas->buffer, " subject=\"%s\"",
				entry->subject);

	if (entry->mask & PMASK_DATETIME)
		g_string_append_escaped_printf(mas->buffer, " datetime=\"%s\"",
				entry->datetime);

	if (entry->mask & PMASK_SENDER_NAME)
		g_string_append_escaped_printf(mas->buffer,
						" sender_name=\"%s\"",
						entry->sender_name);

	if (entry->mask & PMASK_SENDER_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" sender_addressing=\"%s\"",
						entry->sender_addressing);

	if (entry->mask & PMASK_REPLYTO_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" replyto_addressing=\"%s\"",
						entry->replyto_addressing);

	if (entry->mask & PMASK_RECIPIENT_NAME)
		g_string_append_escaped_printf(mas->buffer,
						" recipient_name=\"%s\"",
						entry->recipient_name);

	if (entry->mask & PMASK_RECIPIENT_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" recipient_addressing=\"%s\"",
						entry->recipient_addressing);

	if (entry->mask & PMASK_TYPE)
		g_string_append_escaped_printf(mas->buffer, " type=\"%s\"",
				entry->type);

	if (entry->mask & PMASK_RECEPTION_STATUS)
		g_string_append_escaped_printf(mas->buffer,
						" reception_status=\"%s\"",
						entry->reception_status);

	if (entry->mask & PMASK_SIZE)
		g_string_append_escaped_printf(mas->buffer, " size=\"%s\"",
				entry->size);

	if (entry->mask & PMASK_ATTACHMENT_SIZE)
		g_string_append_escaped_printf(mas->buffer,
						" attachment_size=\"%s\"",
						entry->attachment_size);

	if (entry->mask & PMASK_TEXT)
		g_string_append_escaped_printf(mas->buffer, " text=\"%s\"",
				yesorno(entry->text));

	if (entry->mask & PMASK_READ)
		g_string_append_escaped_printf(mas->buffer, " read=\"%s\"",
				yesorno(entry->read));

	if (entry->mask & PMASK_SENT)
		g_string_append_escaped_printf(mas->buffer, " sent=\"%s\"",
				yesorno(entry->sent));

	if (entry->mask & PMASK_PROTECTED)
		g_string_append_escaped_printf(mas->buffer, " protected=\"%s\"",
				yesorno(entry->protect));

	if (entry->mask & PMASK_PRIORITY)
		g_string_append_escaped_printf(mas->buffer, " priority=\"%s\"",
				yesorno(entry->priority));

	g_string_append(mas->buffer, "/>\n");

proceed:
	if (err != -EAGAIN)
		obex_object_set_io_flags(mas, G_IO_IN, 0);
}
Example #16
0
static void get_messages_listing_cb(void *session, int err, uint16_t size,
					gboolean newmsg,
					const struct messages_message *entry,
					void *user_data)
{
	struct mas_session *mas = user_data;
	uint16_t max = 1024;
	gchar *mse_time;

	if (err < 0 && err != -EAGAIN) {
		obex_object_set_io_flags(mas, G_IO_ERR, err);
		return;
	}

	if (mas->inparams)
		g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT,
									&max);

	if (max == 0) {
		if (!entry)
			mas->finished = TRUE;

		goto proceed;
	}

	if (!mas->nth_call) {
		g_string_append(mas->buffer, ML_BODY_BEGIN);
		mas->nth_call = TRUE;
	}

	if (!entry) {
		g_string_append(mas->buffer, ML_BODY_END);
		mas->finished = TRUE;

		goto proceed;
	}

	g_string_append(mas->buffer, "<msg");

	g_string_append_escaped_printf(mas->buffer, " handle=\"%s\"",
								entry->handle);

	if (entry->mask & PMASK_SUBJECT)
		g_string_append_escaped_printf(mas->buffer, " subject=\"%s\"",
				entry->subject);

	if (entry->mask & PMASK_DATETIME)
		g_string_append_escaped_printf(mas->buffer, " datetime=\"%s\"",
				entry->datetime);

	if (entry->mask & PMASK_SENDER_NAME)
		g_string_append_escaped_printf(mas->buffer,
						" sender_name=\"%s\"",
						entry->sender_name);

	if (entry->mask & PMASK_SENDER_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" sender_addressing=\"%s\"",
						entry->sender_addressing);

	if (entry->mask & PMASK_REPLYTO_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" replyto_addressing=\"%s\"",
						entry->replyto_addressing);

	if (entry->mask & PMASK_RECIPIENT_NAME)
		g_string_append_escaped_printf(mas->buffer,
						" recipient_name=\"%s\"",
						entry->recipient_name);

	if (entry->mask & PMASK_RECIPIENT_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" recipient_addressing=\"%s\"",
						entry->recipient_addressing);

	if (entry->mask & PMASK_TYPE)
		g_string_append_escaped_printf(mas->buffer, " type=\"%s\"",
				entry->type);

	if (entry->mask & PMASK_RECEPTION_STATUS)
		g_string_append_escaped_printf(mas->buffer,
						" reception_status=\"%s\"",
						entry->reception_status);

	if (entry->mask & PMASK_SIZE)
		g_string_append_escaped_printf(mas->buffer, " size=\"%s\"",
				entry->size);

	if (entry->mask & PMASK_ATTACHMENT_SIZE)
		g_string_append_escaped_printf(mas->buffer,
						" attachment_size=\"%s\"",
						entry->attachment_size);

	if (entry->mask & PMASK_TEXT)
		g_string_append_escaped_printf(mas->buffer, " text=\"%s\"",
				yesorno(entry->text));

	if (entry->mask & PMASK_READ)
		g_string_append_escaped_printf(mas->buffer, " read=\"%s\"",
				yesorno(entry->read));

	if (entry->mask & PMASK_SENT)
		g_string_append_escaped_printf(mas->buffer, " sent=\"%s\"",
				yesorno(entry->sent));

	if (entry->mask & PMASK_PROTECTED)
		g_string_append_escaped_printf(mas->buffer, " protected=\"%s\"",
				yesorno(entry->protect));

	if (entry->mask & PMASK_PRIORITY)
		g_string_append_escaped_printf(mas->buffer, " priority=\"%s\"",
				yesorno(entry->priority));

	g_string_append(mas->buffer, "/>\n");

proceed:
	if (!entry) {
		mas->outparams = g_obex_apparam_set_uint16(mas->outparams,
						MAP_AP_MESSAGESLISTINGSIZE,
						size);
		mas->outparams = g_obex_apparam_set_uint8(mas->outparams,
						MAP_AP_NEWMESSAGE,
						newmsg ? 1 : 0);
		/* Response to report the local time of MSE */
		mse_time = get_mse_timestamp();
		if (mse_time) {
			g_obex_apparam_set_string(mas->outparams,
						MAP_AP_MSETIME, mse_time);
			g_free(mse_time);
		}
	}

	if (err != -EAGAIN)
		obex_object_set_io_flags(mas, G_IO_IN, 0);
}