Esempio n. 1
0
static int register_repo(config_repo_t *repo)
{
	alpm_list_t *i;
	alpm_db_t *db;

	repo->siglevel = merge_siglevel(config->siglevel,
			repo->siglevel, repo->siglevel_mask);

	db = alpm_register_syncdb(config->handle, repo->name, repo->siglevel);
	if(db == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
				repo->name, alpm_strerror(alpm_errno(config->handle)));
		return 1;
	}

	pm_printf(ALPM_LOG_DEBUG,
			"setting usage of %d for %s repository\n",
			repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage,
			repo->name);
	alpm_db_set_usage(db, repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage);

	for(i = repo->servers; i; i = alpm_list_next(i)) {
		char *value = i->data;
		if(_add_mirror(db, value) != 0) {
			pm_printf(ALPM_LOG_ERROR,
					_("could not add mirror '%s' to database '%s' (%s)\n"),
					value, repo->name, alpm_strerror(alpm_errno(config->handle)));
			return 1;
		}
	}

	return 0;
}
Esempio n. 2
0
/**
 * Wrap up a section once we have reached the end of it. This should be called
 * when a subsequent section is encountered, or when we have reached the end of
 * the root config file. Once called, all existing saved config pieces on the
 * section struct are freed.
 * @param section the current parsed and saved section data
 * @param parse_options whether we are parsing options or repo data
 * @return 0 on success, 1 on failure
 */
static int finish_section(struct section_t *section, int parse_options)
{
	int ret = 0;
	alpm_list_t *i;
	alpm_db_t *db;

	pm_printf(ALPM_LOG_DEBUG, "config: finish section '%s'\n", section->name);

	/* parsing options (or nothing)- nothing to do except free the pieces */
	if(!section->name || parse_options || section->is_options) {
		goto cleanup;
	}

	/* if we are not looking at options sections only, register a db */
	db = alpm_register_syncdb(config->handle, section->name, section->siglevel);
	if(db == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
				section->name, alpm_strerror(alpm_errno(config->handle)));
		ret = 1;
		goto cleanup;
	}

	for(i = section->servers; i; i = alpm_list_next(i)) {
		char *value = i->data;
		if(_add_mirror(db, value) != 0) {
			pm_printf(ALPM_LOG_ERROR,
					_("could not add mirror '%s' to database '%s' (%s)\n"),
					value, section->name, alpm_strerror(alpm_errno(config->handle)));
			ret = 1;
			goto cleanup;
		}
		free(value);
	}

cleanup:
	alpm_list_free(section->servers);
	section->servers = NULL;
	section->siglevel = ALPM_SIG_USE_DEFAULT;
	free(section->name);
	section->name = NULL;
	return ret;
}
Esempio n. 3
0
static void _metalink_parse(void *context, int flags, const char *dir, const char *attr, const char *val, size_t len, size_t pos G_GNUC_WGET_UNUSED)
{
	_metalink_context_t *ctx = context;
	char value[len + 1];

	// info_printf("\n%02X %s %s '%s'\n", flags, dir, attr, value);
	if (!(flags & (XML_FLG_CONTENT | XML_FLG_ATTRIBUTE))) return; // ignore comments

	if (wget_strncasecmp_ascii(dir, "/metalink/file", 14)) return;

	dir += 14;

	memcpy(value, val, len);
	value[len] = 0;

	if (!wget_strncasecmp_ascii(dir, "s/file", 6)) {
		// metalink 3 XML format
		dir += 6;

		if (attr) {
			if (*dir == 0) { // /metalink/file
				if (!wget_strcasecmp_ascii(attr, "name")) {
					ctx->metalink->name = wget_strmemdup(val, len);
				}
			} else if (!wget_strcasecmp_ascii(dir, "/verification/pieces")) {
				if (!wget_strcasecmp_ascii(attr, "type")) {
					sscanf(value, "%15s", ctx->hash_type);
				} else if (!wget_strcasecmp_ascii(attr, "length")) {
					ctx->length = atoll(value);
				}
//			} else if (!wget_strcasecmp_ascii(dir, "/verification/pieces/hash")) {
//				if (!wget_strcasecmp_ascii(attr, "type")) {
//					ctx->id = atoi(value);
//				}
			} else if (!wget_strcasecmp_ascii(dir, "/verification/hash")) {
				if (!wget_strcasecmp_ascii(attr, "type")) {
					sscanf(value, "%15s", ctx->hash_type);
				}
			} else if (!wget_strcasecmp_ascii(dir, "/resources/url")) {
				if (!wget_strcasecmp_ascii(attr, "location")) {
					sscanf(value, " %2[a-zA-Z]", ctx->location); // ISO 3166-1 alpha-2 two letter country code
//				} else if (!wget_strcasecmp_ascii(attr, "protocol")) {
//					sscanf(value, " %7[a-zA-Z]", ctx->protocol); // type of URL, e.g. HTTP, HTTPS, FTP, ...
//				} else if (!wget_strcasecmp_ascii(attr, "type")) {
//					sscanf(value, " %2[a-zA-Z]", ctx->type); // type of URL, e.g. HTTP, FTP, ...
				} else if (!wget_strcasecmp_ascii(attr, "preference")) {
					sscanf(value, " %6d", &ctx->priority);
					if (ctx->priority < 1 || ctx->priority > 999999)
						ctx->priority = 999999;
				}
			}
		} else {
			if (!wget_strcasecmp_ascii(dir, "/verification/pieces/hash")) {
				_add_piece(ctx, value);
			} else if (!wget_strcasecmp_ascii(dir, "/verification/hash")) {
				_add_file_hash(ctx, value);
			} else if (!wget_strcasecmp_ascii(dir, "/size")) {
				ctx->metalink->size = atoll(value);
			} else if (!wget_strcasecmp_ascii(dir, "/resources/url")) {
				_add_mirror(ctx, value);
			}
		}
	} else {
		// metalink 4 XML format
		if (attr) {
			if (*dir == 0) { // /metalink/file
				if (!wget_strcasecmp_ascii(attr, "name")) {
					ctx->metalink->name = wget_strmemdup(val, len);
				}
			} else if (!wget_strcasecmp_ascii(dir, "/pieces")) {
				if (!wget_strcasecmp_ascii(attr, "type")) {
					sscanf(value, "%15s", ctx->hash_type);
				} else if (!wget_strcasecmp_ascii(attr, "length")) {
					ctx->length = atoll(value);
				}
			} else if (!wget_strcasecmp_ascii(dir, "/hash")) {
				if (!wget_strcasecmp_ascii(attr, "type")) {
					sscanf(value, "%15s", ctx->hash_type);
				}
			} else if (!wget_strcasecmp_ascii(dir, "/url")) {
				if (!wget_strcasecmp_ascii(attr, "location")) {
					sscanf(value, " %2[a-zA-Z]", ctx->location); // ISO 3166-1 alpha-2 two letter country code
				} else if (!wget_strcasecmp_ascii(attr, "priority") || !wget_strcasecmp_ascii(attr, "preference")) {
					sscanf(value, " %6d", &ctx->priority);
					if (ctx->priority < 1 || ctx->priority > 999999)
						ctx->priority = 999999;
				}
			}
		} else {
			if (!wget_strcasecmp_ascii(dir, "/pieces/hash")) {
				_add_piece(ctx, value);
			} else if (!wget_strcasecmp_ascii(dir, "/hash")) {
				_add_file_hash(ctx, value);
			} else if (!wget_strcasecmp_ascii(dir, "/size")) {
				ctx->metalink->size = atoll(value);
			} else if (!wget_strcasecmp_ascii(dir, "/url")) {
				_add_mirror(ctx, value);
			}
		}
	}
}