Diff between a806141efdcb704a92711cc811dd74f59b10f280 and 62ebf8d0f345e7722334d852cf7a010b202647e7

Changed Files

File Additions Deletions Status
obexd/plugins/irmc.c +78 -78 modified
obexd/plugins/phonebook.h +7 -0 modified

Full Patch

diff --git a/obexd/plugins/irmc.c b/obexd/plugins/irmc.c
index 2574b22..2a8c543 100644
--- a/obexd/plugins/irmc.c
+++ b/obexd/plugins/irmc.c
@@ -304,77 +304,22 @@ static void *irmc_open_devinfo(struct irmc_session *irmc, int *err)
 	return irmc;
 }
 
-static void *irmc_open_pb(const char *name, struct irmc_session *irmc,
-								int *err)
+static void *irmc_open_pb(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(PB_CONTACTS, irmc->params,
+	/* how can we tell if the vcard count call already finished? */
+	irmc->request = phonebook_pull(PB_CONTACTS, 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;
+	if (ret < 0) {
+		DBG("phonebook_pull failed...");
 		goto fail;
 	}
 
-	if (!irmc->buffer)
-		irmc->buffer = mybuf;
-	else {
-		irmc->buffer = g_string_append(irmc->buffer, mybuf->str);
-		g_string_free(mybuf, TRUE);
+	ret = phonebook_pull_read(irmc->request);
+	if (ret < 0) {
+		DBG("phonebook_pull_read failed...");
+		goto fail;
 	}
 
 	return irmc;
@@ -386,8 +331,32 @@ fail:
 	return NULL;
 }
 
-static void *irmc_open_cal(const char *name, struct irmc_session *irmc,
-								int *err)
+static void *irmc_open_info(struct irmc_session *irmc, int *err)
+{
+	if (irmc->buffer == NULL)
+		irmc->buffer = g_string_new("");
+
+	g_string_printf(irmc->buffer, "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);
+
+	return irmc;
+}
+
+static void *irmc_open_cc(struct irmc_session *irmc, int *err)
+{
+	if (irmc->buffer == NULL)
+		irmc->buffer = g_string_new("");
+
+	g_string_printf(irmc->buffer, "%d\r\n", irmc->params->maxlistcount);
+
+	return irmc;
+}
+
+static void *irmc_open_cal(struct irmc_session *irmc, int *err)
 {
 	/* no suport yet. Just return an empty buffer. cal.vcs */
 	DBG("unsupported, returning empty buffer");
@@ -398,8 +367,7 @@ static void *irmc_open_cal(const char *name, struct irmc_session *irmc,
 	return irmc;
 }
 
-static void *irmc_open_nt(const char *name, struct irmc_session *irmc,
-								int *err)
+static void *irmc_open_nt(struct irmc_session *irmc, int *err)
 {
 	/* no suport yet. Just return an empty buffer. nt.vnt */
 	DBG("unsupported, returning empty buffer");
@@ -410,12 +378,30 @@ static void *irmc_open_nt(const char *name, struct irmc_session *irmc,
 	return irmc;
 }
 
+static void *irmc_open_luid(struct irmc_session *irmc, int *err)
+{
+	if (irmc->buffer == NULL)
+		irmc->buffer = g_string_new("");
+
+	DBG("changelog request, force whole book");
+	g_string_printf(irmc->buffer, "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);
+
+	return irmc;
+}
+
 static void *irmc_open(const char *name, int oflag, mode_t mode, void *context,
 							size_t *size, int *err)
 {
 	struct irmc_session *irmc = context;
 	int ret = 0;
-	const char *p;
+	char *path;
 
 	DBG("name %s context %p", name, context);
 
@@ -423,20 +409,34 @@ static void *irmc_open(const char *name, int oflag, mode_t mode, void *context,
 		ret = -EPERM;
 		goto fail;
 	}
-	if (name == NULL || strncmp(name, "telecom/", 8) != 0) {
+
+	if (name == NULL) {
 		ret = -EBADR;
 		goto fail;
 	}
 
-	p = name + 8;
-	if (!g_strcmp0(p, "devinfo.txt"))
+	/* Always contains the absolute path */
+	if (g_path_is_absolute(name))
+		path = g_strdup(name);
+	else
+		path = g_build_filename("/", name, NULL);
+
+	if (g_str_equal(path, PB_DEVINFO))
 		return irmc_open_devinfo(irmc, err);
-	else if (!strncmp(p, "pb", 2))
-		return irmc_open_pb(p+2, irmc, err);
-	else if (!strncmp(p, "cal", 3))
-		return irmc_open_cal(p+3, irmc, err);
-	else if (!strncmp(p, "nt", 2))
-		return irmc_open_nt(p+2, irmc, err);
+	else if (g_str_equal(path, PB_CONTACTS))
+		return irmc_open_pb(irmc, err);
+	else if (g_str_equal(path, PB_INFO_LOG))
+		return irmc_open_info(irmc, err);
+	else if (g_str_equal(path, PB_CC_LOG))
+		return irmc_open_cc(irmc, err);
+	else if (g_str_has_prefix(path, PB_CALENDAR_FOLDER))
+		return irmc_open_cal(irmc, err);
+	else if (g_str_has_prefix(path, PB_NOTES_FOLDER))
+		return irmc_open_nt(irmc, err);
+	else if (g_str_has_prefix(path, PB_LUID_FOLDER))
+		return irmc_open_luid(irmc, err);
+	else
+		ret = -EBADR;
 
 fail:
 	if (err)
diff --git a/obexd/plugins/phonebook.h b/obexd/plugins/phonebook.h
index 740557c..6e51c73 100644
--- a/obexd/plugins/phonebook.h
+++ b/obexd/plugins/phonebook.h
@@ -31,16 +31,23 @@
 
 #define PB_TELECOM_FOLDER "/telecom"
 #define PB_CONTACTS_FOLDER "/telecom/pb"
+#define PB_CALENDAR_FOLDER "/telecom/cal"
+#define PB_NOTES_FOLDER "/telecom/nt"
 #define PB_CALLS_COMBINED_FOLDER "/telecom/cch"
 #define PB_CALLS_INCOMING_FOLDER "/telecom/ich"
 #define PB_CALLS_MISSED_FOLDER "/telecom/mch"
 #define PB_CALLS_OUTGOING_FOLDER "/telecom/och"
+#define PB_LUID_FOLDER "/telecom/luid"
 
 #define PB_CONTACTS "/telecom/pb.vcf"
 #define PB_CALLS_COMBINED "/telecom/cch.vcf"
 #define PB_CALLS_INCOMING "/telecom/ich.vcf"
 #define PB_CALLS_MISSED "/telecom/mch.vcf"
 #define PB_CALLS_OUTGOING "/telecom/och.vcf"
+#define PB_DEVINFO "/telecom/devinfo.txt"
+#define PB_INFO_LOG "/telecom/pb/info.log"
+#define PB_CC_LOG "/telecom/pb/luid/cc.log"
+
 
 struct apparam_field {
 	/* list and pull attributes */