2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* alpm.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2006-10-15 15:31:03 -04:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
|
|
|
|
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2005-03-14 20:51:43 -05: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 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-12-15 19:57:31 -05:00
|
|
|
#ifdef HAVE_LIBCURL
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#endif
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
/* libalpm */
|
|
|
|
#include "alpm.h"
|
|
|
|
#include "alpm_list.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "handle.h"
|
2007-06-03 23:57:38 -04:00
|
|
|
#include "util.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-03-16 17:06:31 -05:00
|
|
|
/* Globals */
|
2007-01-30 02:47:19 -05:00
|
|
|
enum _pmerrno_t pm_errno SYMEXPORT;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
/** \addtogroup alpm_interface Interface Functions
|
2007-01-11 12:32:49 -05:00
|
|
|
* @brief Functions to initialize and release libalpm
|
2005-10-09 03:42:06 -04:00
|
|
|
* @{
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
2005-10-09 03:42:06 -04:00
|
|
|
/** Initializes the library. This must be called before any other
|
|
|
|
* functions are called.
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2007-07-06 12:11:55 -04:00
|
|
|
int SYMEXPORT alpm_initialize(void)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2005-03-16 17:10:05 -05:00
|
|
|
ASSERT(handle == NULL, RET_ERR(PM_ERR_HANDLE_NOT_NULL, -1));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
handle = _alpm_handle_new();
|
2005-04-24 14:58:34 -04:00
|
|
|
if(handle == NULL) {
|
2005-04-24 16:11:10 -04:00
|
|
|
RET_ERR(PM_ERR_MEMORY, -1);
|
2005-04-24 14:58:34 -04:00
|
|
|
}
|
2011-01-28 18:41:15 -05:00
|
|
|
if(_alpm_db_register_local() == NULL) {
|
|
|
|
/* error code should be set */
|
2011-02-28 11:46:00 -05:00
|
|
|
_alpm_handle_free(handle);
|
|
|
|
handle = NULL;
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2011-01-28 18:41:15 -05:00
|
|
|
}
|
2007-10-23 00:52:55 -04:00
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
2007-07-06 17:59:08 -04:00
|
|
|
bindtextdomain("libalpm", LOCALEDIR);
|
2007-10-23 00:52:55 -04:00
|
|
|
#endif
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2010-12-15 19:57:31 -05:00
|
|
|
#ifdef HAVE_LIBCURL
|
|
|
|
curl_global_init(CURL_GLOBAL_SSL);
|
|
|
|
handle->curl = curl_easy_init();
|
|
|
|
#endif
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2005-10-09 03:42:06 -04:00
|
|
|
/** Release the library. This should be the last alpm call you make.
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2007-07-06 12:11:55 -04:00
|
|
|
int SYMEXPORT alpm_release(void)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2005-03-16 17:10:05 -05:00
|
|
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-07-09 11:02:29 -04:00
|
|
|
if(alpm_db_unregister_all() == -1) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-04-26 20:29:12 -04:00
|
|
|
_alpm_handle_free(handle);
|
2010-01-19 22:52:54 -05:00
|
|
|
handle = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2010-12-15 19:57:31 -05:00
|
|
|
#ifdef HAVE_LIBCURL
|
|
|
|
curl_global_cleanup();
|
|
|
|
#endif
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-01-11 12:32:49 -05:00
|
|
|
/** @} */
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-06-03 23:57:38 -04:00
|
|
|
/** @defgroup alpm_misc Miscellaneous Functions
|
2006-02-01 12:58:02 -05:00
|
|
|
* @brief Various libalpm functions
|
2006-10-15 15:31:03 -04:00
|
|
|
*/
|
2007-02-04 03:26:52 -05:00
|
|
|
|
2008-02-29 15:52:57 -05:00
|
|
|
/* Get the version of library */
|
|
|
|
const char SYMEXPORT *alpm_version(void) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return LIB_VERSION;
|
2008-02-29 15:52:57 -05:00
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|