STATE_START,
STATE_APPLICATION,
STATE_ID,
+ STATE_PKGNAME,
STATE_LICENCE,
STATE_NAME,
STATE_SUMMARY,
STATE_OL_LI,
STATE_URL,
STATE_GROUP,
+ STATE_KEYWORDS,
+ STATE_KEYWORD,
NUMSTATES
};
/* !! must be sorted by first column !! */
static struct stateswitch stateswitches[] = {
- { STATE_START, "applications", STATE_START, 0 },
+ { STATE_START, "applications", STATE_START, 0 },
+ { STATE_START, "components", STATE_START, 0 },
{ STATE_START, "application", STATE_APPLICATION, 0 },
+ { STATE_START, "component", STATE_APPLICATION, 0 },
{ STATE_APPLICATION, "id", STATE_ID, 1 },
- { STATE_APPLICATION, "licence", STATE_LICENCE, 1 },
+ { STATE_APPLICATION, "pkgname", STATE_PKGNAME, 1 },
+ { STATE_APPLICATION, "product_license", STATE_LICENCE, 1 },
{ STATE_APPLICATION, "name", STATE_NAME, 1 },
{ STATE_APPLICATION, "summary", STATE_SUMMARY, 1 },
{ STATE_APPLICATION, "description", STATE_DESCRIPTION, 0 },
{ STATE_APPLICATION, "url", STATE_URL, 1 },
{ STATE_APPLICATION, "project_group", STATE_GROUP, 1 },
+ { STATE_APPLICATION, "keywords", STATE_KEYWORDS, 0 },
{ STATE_DESCRIPTION, "p", STATE_P, 1 },
{ STATE_DESCRIPTION, "ul", STATE_UL, 0 },
{ STATE_DESCRIPTION, "ol", STATE_OL, 0 },
{ STATE_UL, "li", STATE_UL_LI, 1 },
{ STATE_OL, "li", STATE_OL_LI, 1 },
+ { STATE_KEYWORDS, "keyword", STATE_KEYWORD, 1 },
{ NUMSTATES }
};
char *description;
int licnt;
+ int skip_depth;
+ int flags;
+ char *desktop_file;
+ int havesummary;
};
pd->lcontent = 0;
*pd->content = 0;
+ if (!pd->skip_depth && find_attr("xml:lang", atts))
+ pd->skip_depth = pd->depth;
+ if (pd->skip_depth)
+ {
+ pd->docontent = 0;
+ return;
+ }
+
switch(pd->state)
{
case STATE_APPLICATION:
s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
pd->handle = s - pool->solvables;
+ pd->havesummary = 0;
break;
case STATE_DESCRIPTION:
pd->description = solv_free(pd->description);
break;
case STATE_OL:
+ case STATE_UL:
pd->licnt = 0;
break;
default:
}
}
+static void
+add_missing_tags_from_desktop_file(struct parsedata *pd, Solvable *s, const char *desktop_file)
+{
+ Pool *pool = pd->pool;
+ FILE *fp;
+ const char *filepath;
+ char buf[1024];
+ char *p, *p2, *p3;
+ int inde = 0;
+
+ filepath = pool_tmpjoin(pool, "/usr/share/applications/", desktop_file, 0);
+ if (pd->flags & REPO_USE_ROOTDIR)
+ filepath = pool_prepend_rootdir_tmp(pool, filepath);
+ if (!(fp = fopen(filepath, "r")))
+ return;
+ while (fgets(buf, sizeof(buf), fp) > 0)
+ {
+ int c, l = strlen(buf);
+ if (!l)
+ continue;
+ if (buf[l - 1] != '\n')
+ {
+ /* ignore overlong lines */
+ while ((c = getc(fp)) != EOF)
+ if (c == '\n')
+ break;
+ if (c == EOF)
+ break;
+ continue;
+ }
+ buf[--l] = 0;
+ while (l && (buf[l - 1] == ' ' || buf[l - 1] == '\t'))
+ buf[--l] = 0;
+ p = buf;
+ while (*p == ' ' || *p == '\t')
+ p++;
+ if (!*p || *p == '#')
+ continue;
+ if (*p == '[')
+ inde = 0;
+ if (!strcmp(p, "[Desktop Entry]"))
+ {
+ inde = 1;
+ continue;
+ }
+ if (!inde)
+ continue;
+ p2 = strchr(p, '=');
+ if (!p2 || p2 == p)
+ continue;
+ *p2 = 0;
+ for (p3 = p2 - 1; *p3 == ' ' || *p3 == '\t'; p3--)
+ *p3 = 0;
+ p2++;
+ while (*p2 == ' ' || *p2 == '\t')
+ p2++;
+ if (!*p2)
+ continue;
+ if (!s->name && !strcmp(p, "Name"))
+ s->name = pool_str2id(pool, pool_tmpjoin(pool, "application:", p2, 0), 1);
+ else if (!pd->havesummary && !strcmp(p, "Comment"))
+ {
+ pd->havesummary = 1;
+ repodata_set_str(pd->data, pd->handle, SOLVABLE_SUMMARY, p2);
+ }
+ else
+ continue;
+ if (s->name && pd->havesummary)
+ break; /* our work is done */
+ }
+ fclose(fp);
+}
+
static void XMLCALL
endElement(void *userData, const char *name)
{
pd->depth--;
pd->statedepth--;
+ if (pd->skip_depth && pd->depth + 1 >= pd->skip_depth)
+ {
+ if (pd->depth + 1 == pd->skip_depth)
+ pd->skip_depth = 0;
+ pd->state = pd->sbtab[pd->state];
+ pd->docontent = 0;
+ return;
+ }
+ pd->skip_depth = 0;
+
switch (pd->state)
{
case STATE_APPLICATION:
s->arch = ARCH_NOARCH;
if (!s->evr)
s->evr = ID_EMPTY;
+ if ((!s->name || !pd->havesummary) && (pd->flags & APPDATA_CHECK_DESKTOP_FILE) != 0 && pd->desktop_file)
+ add_missing_tags_from_desktop_file(pd, s, pd->desktop_file);
+ if (!s->name && pd->desktop_file)
+ {
+ char *name = pool_tmpjoin(pool, "application:", pd->desktop_file, 0);
+ int l = strlen(name);
+ if (l > 8 && !strcmp(".desktop", name + l - 8))
+ l -= 8;
+ s->name = pool_strn2id(pool, name, l, 1);
+ }
if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
s->provides = repo_addid_dep(pd->repo, s->provides, pool_rel2id(pd->pool, s->name, s->evr, REL_EQ, 1), 0);
pd->solvable = 0;
+ pd->desktop_file = solv_free(pd->desktop_file);
break;
case STATE_ID:
+ pd->desktop_file = solv_strdup(pd->content);
+ /* guess the appdata.xml file name from the id element */
if (pd->lcontent > 8 && !strcmp(".desktop", pd->content + pd->lcontent - 8))
pd->content[pd->lcontent - 8] = 0;
- id = pool_str2id(pd->pool, pool_tmpjoin(pool, "appdata(", pd->content, ")"), 1);
+ else if (pd->lcontent > 4 && !strcmp(".ttf", pd->content + pd->lcontent - 4))
+ pd->content[pd->lcontent - 4] = 0;
+ else if (pd->lcontent > 4 && !strcmp(".otf", pd->content + pd->lcontent - 4))
+ pd->content[pd->lcontent - 4] = 0;
+ else if (pd->lcontent > 4 && !strcmp(".xml", pd->content + pd->lcontent - 4))
+ pd->content[pd->lcontent - 4] = 0;
+ else if (pd->lcontent > 3 && !strcmp(".db", pd->content + pd->lcontent - 3))
+ pd->content[pd->lcontent - 3] = 0;
+ id = pool_str2id(pd->pool, pool_tmpjoin(pool, "appdata(", pd->content, ".appdata.xml)"), 1);
s->requires = repo_addid_dep(pd->repo, s->requires, id, 0);
- id = pool_str2id(pd->pool, pool_tmpjoin(pool, "application-appdata(", pd->content, ")"), 1);
+ id = pool_str2id(pd->pool, pool_tmpjoin(pool, "application-appdata(", pd->content, ".appdata.xml)"), 1);
s->provides = repo_addid_dep(pd->repo, s->provides, id, 0);
break;
case STATE_NAME:
repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_LICENSE, pd->content);
break;
case STATE_SUMMARY:
+ pd->havesummary = 1;
repodata_set_str(pd->data, pd->handle, SOLVABLE_SUMMARY, pd->content);
break;
case STATE_URL:
case STATE_OL:
pd->description = solv_dupappend(pd->description, "\n", 0);
break;
+ case STATE_PKGNAME:
+ id = pool_str2id(pd->pool, pd->content, 1);
+ s->requires = repo_addid_dep(pd->repo, s->requires, id, 0);
+ break;
+ case STATE_KEYWORD:
+ repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_KEYWORDS, pd->content);
+ break;
default:
break;
}
pd.repo = repo;
pd.pool = repo->pool;
pd.data = data;
+ pd.flags = flags;
pd.content = malloc(256);
pd.acontent = 256;
l = fread(buf, 1, sizeof(buf), fp);
if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
{
- pool_error(pool, -1, "repo_appdata: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+ pool_error(pool, -1, "repo_appdata: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+ if (pd.solvable)
+ {
+ repo_free_solvable(repo, pd.solvable - pd.pool->solvables, 1);
+ pd.solvable = 0;
+ }
ret = -1;
break;
}
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
- free(pd.content);
+ solv_free(pd.content);
+ solv_free(pd.desktop_file);
+ solv_free(pd.description);
return ret;
}
pool_error(repo->pool, 0, "%s: %s", n, strerror(errno));
continue;
}
- repo_add_appdata(repo, fp, flags | REPO_NO_INTERNALIZE | REPO_REUSE_REPODATA);
+ repo_add_appdata(repo, fp, flags | REPO_NO_INTERNALIZE | REPO_REUSE_REPODATA | APPDATA_CHECK_DESKTOP_FILE);
fclose(fp);
}
+ closedir(dir);
}
+ solv_free(dirpath);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
return 0;