summaryrefslogtreecommitdiffstats
path: root/src/session.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-03-01 00:46:23 +0000
committerLennart Poettering <lennart@poettering.net>2006-03-01 00:46:23 +0000
commit30d538a07ca018d1f39ca95be5d802c7194fb86d (patch)
tree92c2e641aa2d3638bfbb2eed5390090ba8ae38c8 /src/session.c
parent5a4bf7b3970df04b1a7f92173b2ade42cc19ecde (diff)
* update for current FUSE and current NEON
* assorted other updates git-svn-id: file:///home/lennart/svn/public/fusedav/trunk@10 e35a362c-bbd6-0310-a59f-a4efcb1729c4
Diffstat (limited to 'src/session.c')
-rw-r--r--src/session.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/session.c b/src/session.c
index 75c37c8..60b1fd4 100644
--- a/src/session.c
+++ b/src/session.c
@@ -38,23 +38,23 @@
#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;
+static char *username = NULL, *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;
@@ -89,22 +89,23 @@ static char* ask_user(char *p, int hidden) {
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;
}
+
+ fprintf(stderr, "Realm '%s' requires authentication.\n", realm);
if (!username)
username = ask_user("Username", 0);
@@ -122,10 +123,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;
@@ -138,6 +141,11 @@ static ne_session *session_open(void) {
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;
}
@@ -151,7 +159,7 @@ static void session_tsd_key_init(void) {
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);
@@ -159,16 +167,19 @@ ne_session *session_get(void) {
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;
@@ -218,3 +229,13 @@ void session_free(void) {
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;
+}
+