main.c
/*
 * Look up a repository, queueing it for discovery if not found.
 */
Look up a repository, queueing it for discovery if not found.
Look up a repository queueing it for discovery if not found .
static const struct repo *
repo_lookup(int fd, struct repotab *rt, const char *uri)
{
	const char	*host, *mod;
	size_t		 hostsz, modsz, i;
	struct repo	*rp;
	if (!rsync_uri_parse(&host, &hostsz,
	    &mod, &modsz, NULL, NULL, NULL, uri))
		errx(1, "%s: malformed", uri);
	for (i = 0; i < rt->reposz; i++) {
		if (strlen(rt->repos[i].host) != hostsz)
			continue;
		if (strlen(rt->repos[i].module) != modsz)
			continue;
		if (strncasecmp(rt->repos[i].host, host, hostsz))
			continue;
		if (strncasecmp(rt->repos[i].module, mod, modsz))
			continue;
		return &rt->repos[i];
	}
	rt->repos = reallocarray(rt->repos,
		rt->reposz + 1, sizeof(struct repo));
	if (rt->repos == NULL)
		err(1, "reallocarray");
	rp = &rt->repos[rt->reposz++];
	memset(rp, 0, sizeof(struct repo));
	rp->id = rt->reposz - 1;
	if ((rp->host = strndup(host, hostsz)) == NULL ||
	    (rp->module = strndup(mod, modsz)) == NULL)
		err(1, "strndup");
	i = rt->reposz - 1;
	logx("%s/%s: loading", rp->host, rp->module);
	io_simple_write(fd, &i, sizeof(size_t));
	io_str_write(fd, rp->host);
	io_str_write(fd, rp->module);
	return rp;
}
static const struct repo * repo_lookup ( int fd , struct repotab * rt , const char * uri ) { const char * host , * mod ; size_t hostsz , modsz , i ; struct repo * rp ; if ( ! rsync_uri_parse ( & host , & hostsz , & mod , & modsz , NULL , NULL , NULL , uri ) ) errx ( 1 , " " , uri ) ; for ( i = 0 ; i < rt -> reposz ; i ++ ) { if ( strlen ( rt -> repos [ i ] . host ) != hostsz ) continue ; if ( strlen ( rt -> repos [ i ] . module ) != modsz ) continue ; if ( strncasecmp ( rt -> repos [ i ] . host , host , hostsz ) ) continue ; if ( strncasecmp ( rt -> repos [ i ] . module , mod , modsz ) ) continue ; return & rt -> repos [ i ] ; } rt -> repos = reallocarray ( rt -> repos , rt -> reposz + 1 , sizeof ( struct repo ) ) ; if ( rt -> repos == NULL ) err ( 1 , " " ) ; rp = & rt -> repos [ rt -> reposz ++ ] ; memset ( rp , 0 , sizeof ( struct repo ) ) ; rp -> id = rt -> reposz - 1 ; if ( ( rp -> host = strndup ( host , hostsz ) ) == NULL || ( rp -> module = strndup ( mod , modsz ) ) == NULL ) err ( 1 , " " ) ; i = rt -> reposz - 1 ; logx ( " " , rp -> host , rp -> module ) ; io_simple_write ( fd , & i , sizeof ( size_t ) ) ; io_str_write ( fd , rp -> host ) ; io_str_write ( fd , rp -> module ) ; return rp ; }
Look up a repository, queueing it for discovery if not found.
Look up a repository queueing it for discovery if not found .
/* Look up in repository table. */