diff --git a/src/session.c b/src/session.c
index 4f1009b2e24c883fbc7cba4d67c09e0e2f550980..acf4a581c1c6bb6d58af4b4f650e2c9ce7ad2566 100644 (file)
--- a/src/session.c
+++ b/src/session.c
+/* $Id$ */
+
+/***
+ 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
+#include <config.h>
+#endif
+
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include <ne_socket.h>
#include <ne_auth.h>
#include <ne_dates.h>
+#include <ne_redirect.h>
#include "session.h"
-
+#include "fusedav.h"
static pthread_once_t session_once = PTHREAD_ONCE_INIT;
static pthread_key_t session_tsd_key;
-static ne_uri uri;
+ne_uri uri;
static int b_uri = 0;
-static const char *username = NULL, *password = NULL;
-const char *base_directory = NULL;
+char *username = NULL;
+static char *password = NULL;
+char *base_directory = NULL;
static pthread_mutex_t credential_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-static char* ask_user(char *p, int hidden) {
+static char* ask_user(const char *p, int hidden) {
char q[256], *r;
struct termios t;
int c = 0, l;
return r ? strdup(r) : NULL;
}
-static int ssl_verify_cb(void *userdata, int failures, const ne_ssl_certificate *cert) {
+static int ssl_verify_cb(__unused void *userdata, __unused int failures, __unused const ne_ssl_certificate *cert) {
return 0;
}
-static int ne_auth_creds_cb(void *userdata, const char *realm, int attempt, char *u, char *p) {
+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) {
- fprintf(stderr, "Authenication failure!\n");
+ fprintf(stderr, "Authentication failure!\n");
free((void*) username);
free((void*) password);
username = password = NULL;
}
+
+ if (!username || !password)
+ fprintf(stderr, "Realm '%s' requires authentication.\n", realm);
if (!username)
username = ask_user("Username", 0);
@@ -98,10 +131,12 @@ static int ne_auth_creds_cb(void *userdata, const char *realm, int attempt, char
return r;
}
-static ne_session *session_open(void) {
- char *scheme = NULL;
+static ne_session *session_open(int with_lock) {
+ const char *scheme = NULL;
ne_session *session;
+ extern ne_lock_store *lock_store;
+
if (!b_uri)
return NULL;
ne_ssl_set_verify(session, ssl_verify_cb, NULL);
ne_set_server_auth(session, ne_auth_creds_cb, NULL);
+ ne_redirect_register(session);
+
+ if (with_lock && lock_store)
+ ne_lockstore_register(lock_store, session);
+
return session;
}
pthread_key_create(&session_tsd_key, session_destroy);
}
-ne_session *session_get(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)))
return session;
- session = session_open();
+ session = session_open(with_lock);
pthread_setspecific(session_tsd_key, session);
return session;
}
int session_set_uri(const char *s, const char *u, const char *p) {
- assert(!b_uri && !username && !password);
int l;
+ assert(!b_uri);
+ assert(!username);
+ assert(!password);
+
if (ne_uri_parse(s, &uri)) {
fprintf(stderr, "Invalid URI <%s>\n", s);
goto finish;
username = password = base_directory = NULL;
}
+int session_is_local(const ne_uri *u) {
+ assert(u);
+ assert(b_uri);
+
+ return
+ strcmp(u->scheme, uri.scheme) == 0 &&
+ strcmp(u->host, uri.host) == 0 &&
+ u->port == uri.port;
+}
+