aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-12-14 11:20:26 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-12-14 11:20:26 +0100
commitdfd49d8fe0bcbc4d794b5a8d56447dd7129aa853 (patch)
treeb073d388db0170216e8bedb7e9b64bffa1636f09
parent69df60bd6622a56200d2d03e1b7d899569adf650 (diff)
afm-db: Search applications case insensitively
Makes the identifier of the application case insensitive. Being case correct is the fast track. Having the wrong case is not an error but just less efficient. Change-Id: Id18f1cfcf49c9f9f336947ebb08bba335a0adc6a Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afm-db.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/afm-db.c b/src/afm-db.c
index 869a0f0..8cf3b37 100644
--- a/src/afm-db.c
+++ b/src/afm-db.c
@@ -482,10 +482,31 @@ struct json_object *afm_db_application_list(struct afm_db *afdb)
*/
struct json_object *afm_db_get_application(struct afm_db *afdb, const char *id)
{
+ int i;
struct json_object *result;
- if (!afm_db_ensure_applications(afdb) && json_object_object_get_ex(
- afdb->applications.direct, id, &result))
+
+ if (afm_db_ensure_applications(afdb))
+ return NULL;
+
+ /* search case sensitively */
+ if (json_object_object_get_ex( afdb->applications.direct, id, &result))
return json_object_get(result);
+
+ /* fallback to a case insensitive search */
+ i = json_object_array_length(afdb->applications.pubarr);
+ while (i) {
+ result = json_object_array_get_idx(afdb->applications.pubarr, --i);
+ if (result
+ && json_object_object_get_ex(result, "id", &result)
+ && !strcasecmp(id, json_object_get_string(result))) {
+ if (json_object_object_get_ex( afdb->applications.direct,
+ json_object_get_string(result),
+ &result))
+ return json_object_get(result);
+ else
+ return NULL;
+ }
+ }
return NULL;
}