Ejemplo n.º 1
0
static void handle_get(GObex *obex, GObexPacket *req, gpointer user_data)
{
	GError *err = NULL;
	struct transfer_data *data;
	const char *type, *name;
	GObexHeader *hdr;
	gsize type_len;

	hdr = g_obex_packet_get_header(req, G_OBEX_HDR_TYPE);
	if (hdr != NULL) {
		g_obex_header_get_bytes(hdr, (const guint8 **) &type,
								&type_len);
		if (type[type_len - 1] != '\0') {
			g_printerr("non-nul terminated type header\n");
			type = NULL;
		}
	} else
		type = NULL;

	hdr = g_obex_packet_get_header(req, G_OBEX_HDR_NAME);
	if (hdr != NULL)
		g_obex_header_get_unicode(hdr, &name);
	else
		name = NULL;

	g_print("get type \"%s\" name \"%s\"\n", type ? type : "",
							name ? name : "");

	data = g_new0(struct transfer_data, 1);

	data->fd = open(name, O_RDONLY | O_NOCTTY, 0);
	if (data->fd < 0) {
		g_printerr("open(%s): %s\n", name, strerror(errno));
		g_free(data);
		g_obex_send_rsp(obex, G_OBEX_RSP_FORBIDDEN, NULL,
							G_OBEX_HDR_INVALID);
		return;
	}

	g_obex_get_rsp(obex, send_data, transfer_complete, data, &err,
							G_OBEX_HDR_INVALID);
	if (err != NULL) {
		g_printerr("Unable to send response: %s\n", err->message);
		g_error_free(err);
		g_free(data);
	}
}
Ejemplo n.º 2
0
Archivo: gobex.c Proyecto: Fiend90/obex
static void handle_request(GObex *obex, GObexPacket *req)
{
	GSList *match;
	int op;

	op = parse_request(obex, req);
	if (op < 0)
		goto fail;

	match = g_slist_find_custom(obex->req_handlers, GUINT_TO_POINTER(op),
							req_handler_cmpop);
	if (match) {
		struct req_handler *handler = match->data;
		handler->func(obex, req, handler->user_data);
		return;
	}

	op = -G_OBEX_RSP_NOT_IMPLEMENTED;

fail:
	g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", g_obex_strerror(-op));
	g_obex_send_rsp(obex, -op, NULL, G_OBEX_HDR_INVALID);
}