void lr_internalmirrorlist_append_mirrorlist(lr_InternalMirrorlist iml, lr_Mirrorlist ml) { int nom_old; int current_id; if (!iml || !ml || ml->nou == 0) return; nom_old = iml->nom; iml->nom += ml->nou; iml->mirrors = lr_realloc(iml->mirrors, sizeof(lr_InternalMirror *) * iml->nom); current_id = nom_old; for (int x=0; x < ml->nou; x++) { lr_InternalMirror im; char *url = ml->urls[x]; if (!url || !strlen(url)) { iml->nom--; continue; // No url present } im = lr_malloc(sizeof(struct _lr_InternalMirror)); im->url = lr_strdup(ml->urls[x]); im->preference = 100; im->fails = 0; iml->mirrors[current_id] = im; current_id++; } }
/** Append path to the repository object. * @param repo Yum repo object. * @param type Type of file. E.g. "primary", "filelists", ... * @param path Path to the file. */ static void lr_yum_repo_append(LrYumRepo *repo, const char *type, const char *path) { assert(repo); assert(type); assert(path); LrYumRepoPath *yumrepopath = lr_malloc(sizeof(LrYumRepoPath)); yumrepopath->type = g_strdup(type); yumrepopath->path = g_strdup(path); repo->paths = g_slist_append(repo->paths, yumrepopath); }
void lr_yum_repo_append(lr_YumRepo repo, const char *type, const char *path) { assert(repo); assert(type); assert(path); repo->paths = lr_realloc(repo->paths, (repo->nop+1) * sizeof(lr_YumRepoMd)); repo->paths[repo->nop] = lr_malloc(sizeof(struct _lr_YumRepoPath)); repo->paths[repo->nop]->type = lr_strdup(type); repo->paths[repo->nop]->path = lr_strdup(path); repo->nop++; }
void lr_internalmirrorlist_append_url(lr_InternalMirrorlist iml, const char *url) { lr_InternalMirror im; if (!iml || !url) return; im = lr_malloc(sizeof(struct _lr_InternalMirror)); im->url = lr_strdup(url); im->preference = 100; im->fails = 0; iml->nom++; iml->mirrors = lr_realloc(iml->mirrors, sizeof(lr_InternalMirror *) * iml->nom); iml->mirrors[iml->nom-1] = im; }
void lr_internalmirrorlist_append_metalink(lr_InternalMirrorlist iml, lr_Metalink ml, const char *suffix) { int nom_old; // Number of mirrors in internal mirror list before append int current_id; // Id of currently inserted element into the internal mirrorlist size_t suffix_len = 0; if (!iml || !ml || ml->nou == 0) return; if (suffix) suffix_len = strlen(suffix); nom_old = iml->nom; iml->nom += ml->nou; iml->mirrors = lr_realloc(iml->mirrors, sizeof(lr_InternalMirror *) * iml->nom); current_id = nom_old; for (int x=0; x < ml->nou; x++) { lr_InternalMirror im; char *url = ml->urls[x]->url; if (!url || !strlen(url)) { iml->nom--; continue; // No url present } im = lr_malloc(sizeof(struct _lr_InternalMirror)); im->url = lr_strdup(url); if (suffix_len) { /* Remove suffix if necessary */ size_t url_len = strlen(url); if (url_len >= suffix_len && !strcmp(url+(url_len-suffix_len), suffix)) im->url[url_len-suffix_len] = '\0'; } im->preference = ml->urls[x]->preference; im->fails = 0; iml->mirrors[current_id] = im; current_id++; } }
int lr_metalink_parse_file(lr_Metalink metalink, int fd, const char *filename) { int ret = LRE_OK; XML_Parser parser; ParserData pd; lr_StatesSwitch *sw; assert(metalink); DEBUGASSERT(fd >= 0); /* Parser configuration */ parser = XML_ParserCreate(NULL); XML_SetUserData(parser, (void *) &pd); XML_SetElementHandler(parser, lr_metalink_start_handler, lr_metalink_end_handler); XML_SetCharacterDataHandler(parser, lr_metalink_char_handler); /* Initialization of parser data */ memset(&pd, 0, sizeof(pd)); pd.ret = LRE_OK; pd.depth = 0; pd.state = STATE_START; pd.statedepth = 0; pd.docontent = 0; pd.content = lr_malloc(CONTENT_REALLOC_STEP); pd.lcontent = 0; pd.acontent = CONTENT_REALLOC_STEP; pd.parser = &parser; pd.metalink = metalink; pd.filename = (char *) filename; pd.ignore = 1; pd.found = 0; for (sw = stateswitches; sw->from != NUMSTATES; sw++) { if (!pd.swtab[sw->from]) pd.swtab[sw->from] = sw; pd.sbtab[sw->to] = sw->from; } /* Parse */ for (;;) { char *buf; int len; buf = XML_GetBuffer(parser, CHUNK_SIZE); if (!buf) lr_out_of_memory(); len = read(fd, (void *) buf, CHUNK_SIZE); if (len < 0) { DPRINTF("%s: Cannot read for parsing : %s\n", __func__, strerror(errno)); ret = LRE_IO; break; } if (!XML_ParseBuffer(parser, len, len == 0)) { DPRINTF("%s: parsing error: %s\n", __func__, XML_ErrorString(XML_GetErrorCode(parser))); ret = LRE_MLXML; break; } if (len == 0) break; if (pd.ret != LRE_OK) { ret = pd.ret; break; } } /* Parser data cleanup */ lr_free(pd.content); XML_ParserFree(parser); if (!pd.found) return LRE_MLBAD; /* The wanted file was not found in metalink */ return ret; }