Ejemplo n.º 1
0
Archivo: pbap.c Proyecto: Sork007/obexd
static ssize_t vobject_pull_read(void *object, void *buf, size_t count)
{
	struct pbap_object *obj = object;
	struct pbap_session *pbap = obj->session;
	int len, ret;

	DBG("buffer %p maxlistcount %d", obj->buffer,
						pbap->params->maxlistcount);

	if (!obj->buffer && !obj->aparams)
		return -EAGAIN;

	if (pbap->params->maxlistcount == 0)
		return -ENOSTR;

	len = string_read(obj->buffer, buf, count);
	if (len == 0 && !obj->lastpart) {
		/* in case when buffer is empty and we know that more
		 * data is still available in backend, requesting new
		 * data part via phonebook_pull_read and returning
		 * -EAGAIN to suspend request for now */
		ret = phonebook_pull_read(obj->request);
		if (ret)
			return -EPERM;

		return -EAGAIN;
	}

	return len;
}
Ejemplo n.º 2
0
Archivo: pbap.c Proyecto: Sork007/obexd
static void *vobject_pull_open(const char *name, int oflag, mode_t mode,
				void *context, size_t *size, int *err)
{
	struct pbap_session *pbap = context;
	phonebook_cb cb;
	int ret;
	void *request;

	DBG("name %s context %p maxlistcount %d", name, context,
						pbap->params->maxlistcount);

	if (oflag != O_RDONLY) {
		ret = -EPERM;
		goto fail;
	}

	if (name == NULL) {
		ret = -EBADR;
		goto fail;
	}

	if (pbap->params->maxlistcount == 0)
		cb = phonebook_size_result;
	else
		cb = query_result;

	request = phonebook_pull(name, pbap->params, cb, pbap, &ret);

	if (ret < 0)
		goto fail;

	/* reading first part of results from backend */
	ret = phonebook_pull_read(request);
	if (ret < 0)
		goto fail;

	if (err)
		*err = 0;

	return vobject_create(pbap, request);

fail:
	if (err)
		*err = ret;

	return NULL;
}
Ejemplo n.º 3
0
static void *irmc_connect(struct obex_session *os, int *err)
{
	struct irmc_session *irmc;
	struct apparam_field *param;
	int ret;

	DBG("");

	manager_register_session(os);

	irmc = g_new0(struct irmc_session, 1);
	irmc->os = os;

	/* FIXME:
	 * Ideally get capabilities info here and use that to define
	 * IrMC DID and SN etc parameters.
	 * For now lets used hostname and some 'random' value
	 */
	gethostname(irmc->did, DID_LEN);
	strncpy(irmc->sn, "12345", DID_LEN);
	strncpy(irmc->manu, "obex", DID_LEN);
	strncpy(irmc->model, "mymodel", DID_LEN);

	/* We need to know the number of contact/cal/nt entries
	 * somewhere so why not do it now.
	 */
	param = g_new0(struct apparam_field, 1);
	param->maxlistcount = 0; /* to count the number of vcards... */
	param->filter = 0x200085; /* UID TEL N VERSION */
	irmc->params = param;
	irmc->request = phonebook_pull("telecom/pb.vcf", irmc->params,
					phonebook_size_result, irmc, err);
	ret = phonebook_pull_read(irmc->request);
	if (err)
		*err = ret;

	return irmc;
}
Ejemplo n.º 4
0
static void *irmc_open_pb(const char *name, struct irmc_session *irmc,
								int *err)
{
	GString *mybuf;
	int ret;

	if (!g_strcmp0(name, ".vcf")) {
		/* how can we tell if the vcard count call already finished? */
		irmc->request = phonebook_pull("telecom/pb.vcf", irmc->params,
						query_result, irmc, &ret);
		if (ret < 0) {
			DBG("phonebook_pull failed...");
			goto fail;
		}

		ret = phonebook_pull_read(irmc->request);
		if (ret < 0) {
			DBG("phonebook_pull_read failed...");
			goto fail;
		}

		return irmc;
	}

	if (!g_strcmp0(name, "/info.log")) {
		mybuf = g_string_new("");
		g_string_printf(mybuf, "Total-Records:%d\r\n"
				"Maximum-Records:%d\r\n"
				"IEL:2\r\n"
				"DID:%s\r\n",
				irmc->params->maxlistcount,
				irmc->params->maxlistcount, irmc->did);
	} else if (!strncmp(name, "/luid/", 6)) {
		name += 6;
		if (!g_strcmp0(name, "cc.log")) {
			mybuf = g_string_new("");
			g_string_printf(mybuf, "%d\r\n",
						irmc->params->maxlistcount);
		} else {
			int l = strlen(name);
			/* FIXME:
			 * Reply the same to any *.log so we hopefully force a
			 * full phonebook dump.
			 * Is IEL:2 ok?
			 */
			if (l > 4 && !g_strcmp0(name + l - 4, ".log")) {
				DBG("changelog request, force whole book");
				mybuf = g_string_new("");
				g_string_printf(mybuf, "SN:%s\r\n"
							"DID:%s\r\n"
							"Total-Records:%d\r\n"
							"Maximum-Records:%d\r\n"
							"*\r\n",
						irmc->sn, irmc->did,
						irmc->params->maxlistcount,
						irmc->params->maxlistcount);
			} else {
				ret = -EBADR;
				goto fail;
			}
		}
	} else {
		ret = -EBADR;
		goto fail;
	}

	if (!irmc->buffer)
		irmc->buffer = mybuf;
	else {
		irmc->buffer = g_string_append(irmc->buffer, mybuf->str);
		g_string_free(mybuf, TRUE);
	}

	return irmc;

fail:
	if (err)
		*err = ret;

	return NULL;
}