2006-10-15 22:21:58 +00:00
|
|
|
/*
|
|
|
|
* server.c
|
2007-11-16 20:18:45 -06:00
|
|
|
*
|
2006-10-15 22:21:58 +00:00
|
|
|
* Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
|
2007-11-16 20:18:45 -06:00
|
|
|
*
|
2006-10-15 22:21:58 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 22:55:22 -06:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-15 22:21:58 +00:00
|
|
|
*/
|
|
|
|
|
2007-03-05 22:13:33 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-10-15 22:21:58 +00:00
|
|
|
#include <stdlib.h>
|
2007-10-22 21:33:47 -07:00
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
2006-10-15 22:21:58 +00:00
|
|
|
#include <string.h>
|
2007-10-22 21:33:47 -07:00
|
|
|
#include <limits.h>
|
2006-10-15 22:21:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2007-01-18 16:52:57 +00:00
|
|
|
#include <download.h>
|
2006-10-15 22:21:58 +00:00
|
|
|
|
2007-03-05 22:13:33 +00:00
|
|
|
/* libalpm */
|
2006-10-15 22:21:58 +00:00
|
|
|
#include "server.h"
|
2007-03-05 22:13:33 +00:00
|
|
|
#include "alpm_list.h"
|
2006-10-15 22:21:58 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "alpm.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "handle.h"
|
2007-02-10 09:36:36 +00:00
|
|
|
#include "package.h"
|
2006-10-15 22:21:58 +00:00
|
|
|
|
2006-11-08 08:14:29 +00:00
|
|
|
pmserver_t *_alpm_server_new(const char *url)
|
2006-10-15 22:21:58 +00:00
|
|
|
{
|
2006-10-31 06:39:59 +00:00
|
|
|
struct url *u;
|
2006-10-15 22:21:58 +00:00
|
|
|
pmserver_t *server;
|
|
|
|
|
2007-01-30 08:14:10 +00:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-10-29 01:00:52 -05:00
|
|
|
CALLOC(server, 1, sizeof(pmserver_t), RET_ERR(PM_ERR_MEMORY, NULL));
|
2006-10-15 22:21:58 +00:00
|
|
|
|
2006-11-14 07:58:42 +00:00
|
|
|
u = downloadParseURL(url);
|
2006-10-31 06:39:59 +00:00
|
|
|
if(!u) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("url '%s' is invalid, ignoring\n"), url);
|
2007-02-09 10:10:49 +00:00
|
|
|
RET_ERR(PM_ERR_SERVER_BAD_URL, NULL);
|
2006-10-15 22:21:58 +00:00
|
|
|
}
|
2006-10-31 06:39:59 +00:00
|
|
|
if(strlen(u->scheme) == 0) {
|
2007-08-23 22:26:55 -04:00
|
|
|
_alpm_log(PM_LOG_WARNING, _("url scheme not specified, assuming http\n"));
|
2006-10-31 06:39:59 +00:00
|
|
|
strcpy(u->scheme, "http");
|
2006-10-15 22:21:58 +00:00
|
|
|
}
|
2006-10-31 06:39:59 +00:00
|
|
|
|
|
|
|
if(strcmp(u->scheme,"ftp") == 0 && strlen(u->user) == 0) {
|
|
|
|
strcpy(u->user, "anonymous");
|
|
|
|
strcpy(u->pwd, "libalpm@guest");
|
2006-10-15 22:21:58 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:17:52 -05:00
|
|
|
/* remove trailing slashes, just to clean up the rest of the code */
|
|
|
|
for(int i = strlen(u->doc) - 1; u->doc[i] == '/'; --i)
|
|
|
|
u->doc[i] = '\0';
|
|
|
|
|
2006-10-31 06:39:59 +00:00
|
|
|
server->s_url = u;
|
|
|
|
|
|
|
|
return server;
|
2006-10-15 22:21:58 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 20:23:03 -04:00
|
|
|
void _alpm_server_free(pmserver_t *server)
|
2006-10-15 22:21:58 +00:00
|
|
|
{
|
2007-01-30 08:14:10 +00:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-10-15 22:21:58 +00:00
|
|
|
if(server == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free memory */
|
2006-11-14 07:58:42 +00:00
|
|
|
downloadFreeURL(server->s_url);
|
2006-10-31 06:39:59 +00:00
|
|
|
FREE(server);
|
2006-10-15 22:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|