Code

git: remove $Id$ svn cruft
[fusedav.git] / src / session.c
index 60b1fd4e4431ef41f1615a15c1b01468475f3923..ca5b89be3c34961eb90d76fb8dbd4b663b13dd93 100644 (file)
@@ -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
@@ -49,7 +53,8 @@ static pthread_key_t session_tsd_key;
 ne_uri uri;
 static int b_uri = 0;
 
-static char *username = NULL, *password = NULL;
+char *username = NULL;
+static char *password = NULL;
 char *base_directory = NULL;
 
 static pthread_mutex_t credential_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -73,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);
@@ -85,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;
 }
 
@@ -95,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) {
@@ -105,11 +110,12 @@ static int ne_auth_creds_cb(__unused void *userdata, const char *realm, int atte
         username = password = NULL;
     }
 
-    fprintf(stderr, "Realm '%s' requires authentication.\n", realm);
-    
+    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);
 
@@ -133,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;
@@ -145,7 +151,7 @@ static ne_session *session_open(int with_lock) {
 
     if (with_lock && lock_store)
         ne_lockstore_register(lock_store, session);
-    
+
     return session;
 }
 
@@ -161,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)))
@@ -175,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);
@@ -204,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;
@@ -238,4 +244,3 @@ int session_is_local(const ne_uri *u) {
         strcmp(u->host, uri.host) == 0 &&
         u->port == uri.port;
 }
-