X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgt-info.c;h=ade3830a226ad359af425a3daf24d727e2dfe6dc;hb=a855d14583b2ac2629dfac696fea788826bacc4d;hp=4d6b37d7ac4506318a75301a15c4980ed7d97f4d;hpb=a8f72186c447ba9b917c7f24a00497ae36dbc71f;p=src%2Fapp-framework-main.git diff --git a/src/wgt-info.c b/src/wgt-info.c index 4d6b37d..ade3830 100644 --- a/src/wgt-info.c +++ b/src/wgt-info.c @@ -1,5 +1,5 @@ /* - Copyright 2015 IoT.bzh + Copyright (C) 2015-2020 IoT.bzh author: José Bollo @@ -20,12 +20,14 @@ #include #include #include +#include #include #include "verbose.h" #include "wgt.h" #include "wgt-config.h" +#include "wgt-strings.h" #include "wgt-info.h" struct wgt_info { @@ -75,32 +77,60 @@ static xmlChar *optcontent(xmlNodePtr node) return node ? xmlNodeGetContent(node) : NULL; } -static char *mkidaver(char *id, char *version) +static char *mkver(char *version) { - int lid, lver; + unsigned int lver; char c, *r; - if (id && version) { - lid = strlen(id); + if (version) { c = version[lver = 0]; - while(c && c != ' ') { - if (c != '.') + while(c && c != ' ' && c != '.') + c = version[++lver]; + if (c == '.') { + c = version[++lver]; + while(c && c != ' ' && c != '.') c = version[++lver]; - else { - do { - c = version[++lver]; - } while (c && c != ' ' && c != '.'); - break; - } } + r = malloc(lver + 1); + if (r) { + memcpy(r, version, lver); + r[lver] = 0; + return r; + } + } + return NULL; +} + +static char *mkidaver(char *id, char *ver) +{ +#if DISTINCT_VERSIONS + size_t lid, lver; + char *r; + if (id && ver) { + lid = strlen(id); + lver = strlen(ver); r = malloc(2 + lid + lver); if (r) { memcpy(r, id, lid); r[lid] = '@'; - memcpy(r + lid + 1, version, lver + 1); + memcpy(r + lid + 1, ver, lver); + r[lid + lver + 1] = 0; return r; } } return NULL; +#else + return strdup(id); +#endif +} + +static void make_lowercase(char *s) +{ + if (s) { + while(*s) { + *s = (char)tolower(*s); + s++; + } + } } static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, int want_preferences) @@ -117,39 +147,42 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i errno = EINVAL; return -1; } - desc->id = xmlGetProp(node, wgt_config_string_id); - desc->version = xmlGetProp(node, wgt_config_string_version); - desc->idaver = mkidaver(desc->id, desc->version); - desc->width = getpropnum(node, wgt_config_string_width, 0); - desc->height = getpropnum(node, wgt_config_string_height, 0); - desc->viewmodes = xmlGetProp(node, wgt_config_string_viewmodes); - desc->defaultlocale = xmlGetProp(node, wgt_config_string_defaultlocale); + desc->id = xmlGetProp(node, string_id); + make_lowercase(desc->id); + desc->version = xmlGetProp(node, string_version); + desc->ver = mkver(desc->version); + make_lowercase(desc->ver); + desc->idaver = mkidaver(desc->id, desc->ver); + desc->width = getpropnum(node, string_width, 0); + desc->height = getpropnum(node, string_height, 0); + desc->viewmodes = xmlGetProp(node, string_viewmodes); + desc->defaultlocale = xmlGetProp(node, string_defaultlocale); node = wgt_config_name(); desc->name = optcontent(node); - desc->name_short = optprop(node, wgt_config_string_short); + desc->name_short = optprop(node, string_short); node = wgt_config_description(); desc->description = optcontent(node); node = wgt_config_author(); desc->author = optcontent(node); - desc->author_href = optprop(node, wgt_config_string_href); - desc->author_email = optprop(node, wgt_config_string_email); + desc->author_href = optprop(node, string_href); + desc->author_email = optprop(node, string_email); node = wgt_config_license(); desc->license = optcontent(node); - desc->license_href = optprop(node, wgt_config_string_href); + desc->license_href = optprop(node, string_href); node = wgt_config_content(); - desc->content_src = optprop(node, wgt_config_string_src); + desc->content_src = optprop(node, string_src); if (node && desc->content_src == NULL) { WARNING("content without src"); errno = EINVAL; return -1; } - desc->content_type = optprop(node, wgt_config_string_type); - desc->content_encoding = optprop(node, wgt_config_string_encoding); + desc->content_type = optprop(node, string_type); + desc->content_encoding = optprop(node, string_encoding); if (want_icons) { icontail = &desc->icons; @@ -160,9 +193,9 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i errno = ENOMEM; return -1; } - icon->src = xmlGetProp(node, wgt_config_string_src); - icon->width = getpropnum(node, wgt_config_string_width, 0); - icon->height = getpropnum(node, wgt_config_string_height, 0); + icon->src = xmlGetProp(node, string_src); + icon->width = getpropnum(node, string_width, 0); + icon->height = getpropnum(node, string_height, 0); icon->next = NULL; *icontail = icon; @@ -186,8 +219,8 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i errno = ENOMEM; return -1; } - feature->name = xmlGetProp(node, wgt_config_string_name); - feature->required = getpropbool(node, wgt_config_string_required, 1); + feature->name = xmlGetProp(node, string_name); + feature->required = getpropbool(node, string_required, 1); feature->params = NULL; feature->next = NULL; @@ -207,8 +240,8 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i errno = ENOMEM; return -1; } - param->name = xmlGetProp(pnode, wgt_config_string_name); - param->value = xmlGetProp(pnode, wgt_config_string_value); + param->name = xmlGetProp(pnode, string_name); + param->value = xmlGetProp(pnode, string_value); param->next = NULL; *paramtail = param; @@ -237,9 +270,9 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i errno = ENOMEM; return -1; } - preference->name = xmlGetProp(node, wgt_config_string_name); - preference->value = xmlGetProp(node, wgt_config_string_value); - preference->readonly = getpropbool(node, wgt_config_string_readonly, 0); + preference->name = xmlGetProp(node, string_name); + preference->value = xmlGetProp(node, string_value); + preference->readonly = getpropbool(node, string_readonly, 0); *preferencetail = preference; preference->next = NULL; @@ -266,6 +299,7 @@ static void free_desc(struct wgt_desc *desc) xmlFree(desc->id); xmlFree(desc->version); + free(desc->ver); free(desc->idaver); xmlFree(desc->viewmodes); xmlFree(desc->defaultlocale); @@ -320,6 +354,7 @@ static void dump_desc(struct wgt_desc *desc, FILE *f, const char *prefix) if (desc->id) fprintf(f, "%sid: %s\n", prefix, desc->id); if (desc->version) fprintf(f, "%sversion: %s\n", prefix, desc->version); + if (desc->ver) fprintf(f, "%sver: %s\n", prefix, desc->ver); if (desc->idaver) fprintf(f, "%sidaver: %s\n", prefix, desc->idaver); if (desc->width) fprintf(f, "%swidth: %d\n", prefix, desc->width); if (desc->height) fprintf(f, "%sheight: %d\n", prefix, desc->height); @@ -470,6 +505,7 @@ const char *wgt_info_param(const struct wgt_desc_feature *feature, const char *n while(param) { if (0 == strcmp(name, param->name)) return param->value; + param = param->next; } return NULL; }