X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=ext%2Frepo_products.c;h=f7a36e11912b968b1b1bc0bdf2b9b25b9edfddb9;hb=bbdec95b275a74bd44244ba6a1d93e0fc21ef810;hp=598b2ab64f889499aab14b490e916b57e17b2df8;hpb=765ead528d2b791e43e2a90212b5e4a0c2ad1302;p=platform%2Fupstream%2Flibsolv.git diff --git a/ext/repo_products.c b/ext/repo_products.c index 598b2ab..f7a36e1 100644 --- a/ext/repo_products.c +++ b/ext/repo_products.c @@ -11,6 +11,9 @@ * for further information */ +#define _GNU_SOURCE +#define _XOPEN_SOURCE +#include #include #include #include @@ -58,6 +61,9 @@ enum state { STATE_TARGET, STATE_REGRELEASE, STATE_PRODUCTLINE, + STATE_REGUPDATES, + STATE_REGUPDREPO, + STATE_ENDOFLIFE, NUMSTATES }; @@ -86,10 +92,13 @@ static struct stateswitch stateswitches[] = { { STATE_PRODUCT, "linguas", STATE_LINGUAS, 0 }, { STATE_PRODUCT, "updaterepokey", STATE_UPDATEREPOKEY, 1 }, { STATE_PRODUCT, "cpeid", STATE_CPEID, 1 }, + { STATE_PRODUCT, "endoflife", STATE_ENDOFLIFE, 1 }, { STATE_URLS, "url", STATE_URL, 1 }, { STATE_LINGUAS, "lang", STATE_LANG, 0 }, { STATE_REGISTER, "target", STATE_TARGET, 1 }, { STATE_REGISTER, "release", STATE_REGRELEASE, 1 }, + { STATE_REGISTER, "updates", STATE_REGUPDATES, 0 }, + { STATE_REGUPDATES, "repository", STATE_REGUPDREPO, 0 }, { NUMSTATES } }; @@ -148,6 +157,29 @@ find_attr(const char *txt, const char **atts) return 0; } +static time_t +datestr2timestamp(const char *date) +{ + const char *p; + struct tm tm; + + if (!date || !*date) + return 0; + for (p = date; *p >= '0' && *p <= '9'; p++) + ; + if (!*p) + return atoi(date); + memset(&tm, 0, sizeof(tm)); + p = strptime(date, "%F%T", &tm); + if (!p) + { + memset(&tm, 0, sizeof(tm)); + p = strptime(date, "%F", &tm); + if (!p || *p) + return 0; + } + return timegm(&tm); +} /* * XML callback: startElement @@ -218,6 +250,17 @@ startElement(void *userData, const char *name, const char **atts) case STATE_URL: pd->urltype = pool_str2id(pd->pool, find_attr("name", atts), 1); break; + case STATE_REGUPDREPO: + { + const char *repoid = find_attr("repoid", atts); + if (repoid && *repoid) + { + Id h = repodata_new_handle(pd->data); + repodata_set_str(pd->data, h, PRODUCT_UPDATES_REPOID, repoid); + repodata_add_flexarray(pd->data, pd->handle, PRODUCT_UPDATES, h); + } + break; + } default: break; } @@ -324,8 +367,17 @@ endElement(void *userData, const char *name) repodata_set_str(pd->data, pd->handle, PRODUCT_REGISTER_RELEASE, pd->content); break; case STATE_CPEID: - if (pd->content) + if (*pd->content) repodata_set_str(pd->data, pd->handle, SOLVABLE_CPEID, pd->content); + break; + case STATE_ENDOFLIFE: + if (*pd->content) + { + time_t t = datestr2timestamp(pd->content); + if (t) + repodata_set_num(pd->data, pd->handle, PRODUCT_ENDOFLIFE, (unsigned long long)t); + } + break; default: break; } @@ -384,7 +436,7 @@ add_code11_product(struct parsedata *pd, FILE *fp) else { pd->currentproduct = pd->baseproduct + 1; /* make it != baseproduct if stat fails */ - perror("fstat"); + pool_error(pd->pool, 0, "fstat: %s", strerror(errno)); pd->ctime = 0; } @@ -399,8 +451,12 @@ add_code11_product(struct parsedata *pd, FILE *fp) if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR) { pool_debug(pd->pool, SOLV_ERROR, "%s: %s at line %u:%u\n", pd->filename, XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser)); - pool_debug(pd->pool, SOLV_ERROR, "skipping this product\n"); XML_ParserFree(parser); + if (pd->solvable) + { + repo_free_solvable(pd->repo, pd->solvable - pd->pool->solvables, 1); + pd->solvable = 0; + } return; } if (l == 0) @@ -461,7 +517,7 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags) fp = fopen(fullpath, "r"); if (!fp) { - perror(fullpath); + pool_error(repo->pool, 0, "%s: %s", fullpath, strerror(errno)); continue; } pd.filename = fullpath;