X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsession.c;h=ca5b89be3c34961eb90d76fb8dbd4b663b13dd93;hb=f8835b143558f38cfb7a01a71adc525598f12d05;hp=b4d66e0cd77cc2de1e4442dcbbabc9cf7675c2a2;hpb=ca41acd1045a372ccfd1d8f7d02d575b51cfb86e;p=fusedav.git diff --git a/src/session.c b/src/session.c index b4d66e0..ca5b89b 100644 --- a/src/session.c +++ b/src/session.c @@ -1,21 +1,25 @@ -/* $Id$ */ - /*** - This file is part of fusedav. - - fusedav 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. - - fusedav 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 - along with fusedav; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Copyright (c) 2004-2006 Lennart Poettering + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. ***/ #ifdef HAVE_CONFIG_H @@ -74,7 +78,7 @@ static char* ask_user(const char *p, int hidden) { } } } - + fprintf(stderr, "%s: ", p); r = fgets(q, sizeof(q), stdin); l = strlen(q); @@ -86,7 +90,7 @@ static char* ask_user(const char *p, int hidden) { tcsetattr(fileno(stdin), TCSANOW, &t); fprintf(stderr, "\n"); } - + return r ? strdup(r) : NULL; } @@ -96,7 +100,7 @@ static int ssl_verify_cb(__unused void *userdata, __unused int failures, __unuse static int ne_auth_creds_cb(__unused void *userdata, const char *realm, int attempt, char *u, char *p) { int r = -1; - + pthread_mutex_lock(&credential_mutex); if (attempt) { @@ -108,10 +112,10 @@ static int ne_auth_creds_cb(__unused void *userdata, const char *realm, int atte if (!username || !password) fprintf(stderr, "Realm '%s' requires authentication.\n", realm); - + if (!username) username = ask_user("Username", 0); - + if (username && !password) password = ask_user("Password", 1); @@ -135,7 +139,7 @@ static ne_session *session_open(int with_lock) { return NULL; scheme = uri.scheme ? uri.scheme : "http"; - + if (!(session = ne_session_create(scheme, uri.host, uri.port ? uri.port : ne_uri_defaultport(scheme)))) { fprintf(stderr, "Failed to create session\n"); return NULL; @@ -147,7 +151,7 @@ static ne_session *session_open(int with_lock) { if (with_lock && lock_store) ne_lockstore_register(lock_store, session); - + return session; } @@ -163,7 +167,7 @@ static void session_tsd_key_init(void) { ne_session *session_get(int with_lock) { ne_session *session; - + pthread_once(&session_once, session_tsd_key_init); if ((session = pthread_getspecific(session_tsd_key))) @@ -177,7 +181,7 @@ ne_session *session_get(int with_lock) { int session_set_uri(const char *s, const char *u, const char *p) { int l; - + assert(!b_uri); assert(!username); assert(!password); @@ -206,9 +210,9 @@ int session_set_uri(const char *s, const char *u, const char *p) { password = strdup(p); return 0; - + finish: - + if (b_uri) { ne_uri_free(&uri); b_uri = 0; @@ -240,4 +244,3 @@ int session_is_local(const ne_uri *u) { strcmp(u->host, uri.host) == 0 && u->port == uri.port; } -