From 7156f26247194f542563f7e57dd18d8cd825a9e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Wed, 17 Feb 2010 20:32:32 +0100 Subject: [PATCH] Export ISDS server locators Library provides extern constant strings isds_locator and isds_testing_locator. Application can use them as isds_login() argument to select regular or testing ISDS server. Variable form (in contrast to preprocessor macro) has been choosed to allow server locator update delivered by library without application recompilation. All clients and tests has been adapted. --- client/common.c | 1 - client/common.h | 2 +- src/isds.c | 16 ++++++++++++++-- src/isds.h | 8 +++++++- src/isds_priv.h | 1 + test/login.c | 6 +++--- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/client/common.c b/client/common.c index 56d260f..b042c40 100644 --- a/client/common.c +++ b/client/common.c @@ -13,7 +13,6 @@ #include #include -char url[] = "https://www.czebox.cz/DS/"; /*char username[] = "jrfh7i";*/ /*char password[] = "Ab123456";*/ /*char password[] = "Ac123456";*/ diff --git a/client/common.h b/client/common.h index e13e619..cdd76c2 100644 --- a/client/common.h +++ b/client/common.h @@ -3,7 +3,7 @@ #include -extern char url[]; +#define url isds_testing_locator extern char username[]; extern char password[]; diff --git a/src/isds.c b/src/isds.c index d97fd46..f3caa0c 100644 --- a/src/isds.c +++ b/src/isds.c @@ -13,6 +13,13 @@ #include /* Because of ksba or gpgme */ #include "physxml.h" +/* Locators */ +/* Base URL of production ISDS instance */ +const char isds_locator[] = "https://www.mojedatovaschranka.cz/DS/"; + +/* Base URL of production ISDS instance */ +const char isds_testing_locator[] = "https://www.czebox.cz/DS/"; + /* Free isds_list with all member data. * @list list to free, on return will be NULL */ @@ -846,7 +853,9 @@ static isds_error discard_credentials(struct isds_ctx *context) { /* Connect and log in into ISDS server. - * @url is address of ISDS web service + * @url is base address of ISDS web service. Pass NULL or extern isds_locator + * variable to use production ISDS instance. You can pass extern + * isds_testing_locator variable to select testing instance. * @username is user name of ISDS user * @password is user's secret password * @certificate is NULL terminated string with PEM formated client's @@ -864,9 +873,12 @@ isds_error isds_login(struct isds_ctx *context, const char *url, xmlNodePtr response = NULL; if (!context) return IE_INVALID_CONTEXT; - if (!url || !username || !password) return IE_INVAL; + if (!username || !password) return IE_INVAL; if (certificate || key) return IE_NOTSUP; + /* Default locator is offical system */ + if (!url) url = isds_locator; + /* Store configuration */ context->type = CTX_TYPE_ISDS; free(context->url); diff --git a/src/isds.h b/src/isds.h index 4f95ed7..c5d71e4 100644 --- a/src/isds.h +++ b/src/isds.h @@ -19,6 +19,10 @@ extern "C" { #define _deprecated #endif +/* Service locators */ +extern const char isds_locator[]; /* Base URL of production ISDS instance */ +extern const char isds_testing_locator[]; /* B. URL of testing ISDS instance */ + struct isds_ctx; /* Context for specific ISDS box */ @@ -577,7 +581,9 @@ isds_error isds_set_tls(struct isds_ctx *context, const isds_tls_option option, ...); /* Connect and log in into ISDS server. - * @url is address of ISDS web service + * @url is base address of ISDS web service. Pass NULL or extern isds_locator + * variable to use production ISDS instance. You can pass extern + * isds_testing_locator variable to select testing instance. * @username is user name of ISDS user * @password is user's secret password * @certificate is NULL terminated string with PEM formated client's diff --git a/src/isds_priv.h b/src/isds_priv.h index 4e45a62..2988800 100644 --- a/src/isds_priv.h +++ b/src/isds_priv.h @@ -23,6 +23,7 @@ #define SCHEMA_NS "http://www.w3.org/2001/XMLSchema" #define DEPOSIT_NS "urn:uschovnaWSDL" + /* Used to choose proper name space for message elements. * See register_namespaces(). */ typedef enum { diff --git a/test/login.c b/test/login.c index 2f8147d..f35a932 100644 --- a/test/login.c +++ b/test/login.c @@ -32,7 +32,7 @@ int main(int argc, char **argv) { INIT_TEST("login"); struct isds_ctx *context = NULL; - char url[] = "https://www.czebox.cz/DS/"; + const char *url = isds_testing_locator; char username[] = "5s59sd"; char password[] = "Ac123456"; @@ -45,8 +45,8 @@ int main(int argc, char **argv) { TEST("invalid context", test_login, IE_INVALID_CONTEXT, NULL, url, username, password, NULL, NULL); - TEST("NULL url", test_login, IE_INVAL, context, - NULL, username, password, NULL, NULL); + TEST("NULL url with invalid credentials", test_login, IE_NOT_LOGGED_IN, + context, NULL, username, password, NULL, NULL); TEST("NULL username", test_login, IE_INVAL, context, url, NULL, password, NULL, NULL); TEST("NULL password", test_login, IE_INVAL, context, -- 2.11.4.GIT