From b2f96adfc752eeed12b72f04b67cbecca58b6690 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 22 Jan 2008 21:21:24 +0000 Subject: [PATCH] * use the hash to store our config. --- webcit/context_loop.c | 14 ++--- webcit/preferences.c | 132 +++++++++++++++++++----------------------- webcit/webcit.h | 13 +---- 3 files changed, 68 insertions(+), 91 deletions(-) diff --git a/webcit/context_loop.c b/webcit/context_loop.c index b7d556c50..79687511c 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -92,20 +92,17 @@ void do_housekeeping(void) pthread_mutex_lock(&sessions_to_kill->SessionMutex); close(sessions_to_kill->serv_sock); close(sessions_to_kill->chat_sock); - while (sessions_to_kill->first_pref != NULL) { - struct wcpref *ptr; - ptr = sessions_to_kill->first_pref->next; - free(sessions_to_kill->first_pref->pref_key); - free(sessions_to_kill->first_pref->pref_value); - free(sessions_to_kill->first_pref); - sessions_to_kill->first_pref = ptr; - } +// if (sessions_to_kill->preferences != NULL) { +// free(sessions_to_kill->preferences); +// } if (sessions_to_kill->cache_fold != NULL) { free(sessions_to_kill->cache_fold); } free_attachments(sessions_to_kill); free_march_list(sessions_to_kill); clear_substs(sessions_to_kill); + DeleteHash(&(sessions_to_kill->hash_prefs)); + pthread_mutex_unlock(&sessions_to_kill->SessionMutex); sptr = sessions_to_kill->next; free(sessions_to_kill); @@ -476,6 +473,7 @@ void context_loop(int sock) strcpy(TheSession->httpauth_user, httpauth_user); strcpy(TheSession->httpauth_pass, httpauth_pass); + TheSession->hash_prefs = NewHash(); /* Get a hash table for the user preferences */ pthread_mutex_init(&TheSession->SessionMutex, NULL); pthread_mutex_lock(&SessionListMutex); TheSession->nonce = rand(); diff --git a/webcit/preferences.c b/webcit/preferences.c index 8991c0c13..87026fe8b 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -1,54 +1,29 @@ /* * $Id$ - * - * Manage user preferences with a little help from the Citadel server. + */ +/** + * \defgroup ManagePrefs Manage user preferences with a little help from the Citadel server. + * \ingroup CitadelConfig * */ - +/*@{*/ #include "webcit.h" #include "webserver.h" #include "groupdav.h" -/* This function is for private use -- callers should use set_preference() instead - */ -void store_preference(char *key, char *value) { - - struct wcpref *ptr = NULL; - - if (WC->first_pref == NULL) { - WC->first_pref = malloc(sizeof(struct wcpref)); - WC->first_pref->next = NULL; - WC->first_pref->pref_key = strdup(key); - WC->first_pref->pref_value = strdup(value); - return; - } - - for (ptr = WC->first_pref; ptr != NULL; ptr = ptr->next) { - if (!strcasecmp(ptr->pref_key, key)) { - free(ptr->pref_value); - ptr->pref_value = strdup(value); - return; - } - } - - ptr = malloc(sizeof(struct wcpref)); - ptr->pref_key = strdup(key); - ptr->pref_value = strdup(value); - ptr->next = WC->first_pref; - WC->first_pref = ptr; -} - +//// tmp +#include -/* - * display preferences dialog +/** + * \brief display preferences dialog */ void load_preferences(void) { char buf[SIZ]; - char key[SIZ]; - char value[SIZ]; long msgnum = 0L; - + char key[SIZ], value[SIZ]; + char *pBuf; + serv_printf("GOTO %s", USERCONFIGROOM); serv_getln(buf, sizeof buf); if (buf[0] != '2') return; @@ -74,20 +49,21 @@ void load_preferences(void) { while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { extract_token(key, buf, 0, '|', sizeof key); extract_token(value, buf, 1, '|', sizeof value); - store_preference(key, value); + if (!IsEmptyStr(key)) + Put(WC->hash_prefs, key, strlen(key), strdup(value), free); } } } } - /* Go back to the room we're supposed to be in */ + /** Go back to the room we're supposed to be in */ serv_printf("GOTO %s", WC->wc_roomname); serv_getln(buf, sizeof buf); } -/* - * Goto the user's configuration room, creating it if necessary. - * return 0 on success or nonzero upon failure. +/** + * \brief Goto the user's configuration room, creating it if necessary. + * \return 0 on success or nonzero upon failure. */ int goto_config_room(void) { char buf[SIZ]; @@ -104,14 +80,13 @@ int goto_config_room(void) { return(0); } -/* - * save the modifications +/** + * \brief save the modifications */ void save_preferences(void) { char buf[SIZ]; long msgnum = 0L; - struct wcpref *ptr; - + if (goto_config_room() != 0) return; /* oh well. */ serv_puts("MSGS ALL|0|1"); serv_getln(buf, sizeof buf); @@ -131,55 +106,68 @@ void save_preferences(void) { serv_printf("ENT0 1||0|1|__ WebCit Preferences __|"); serv_getln(buf, sizeof buf); if (buf[0] == '4') { - for (ptr = WC->first_pref; ptr != NULL; ptr = ptr->next) { - serv_printf("%s|%s", ptr->pref_key, ptr->pref_value); + long len; + HashPos *HashPos; + HashList *Hash; + char *Value; + char *Key; + + Hash = WC->hash_prefs; + PrintHash(Hash); + HashPos = GetNewHashPos(); + printf("_______> writing entries\n"); + while (GetNextHashPos(Hash, HashPos, &len, &Key, (void**)&Value)!=0) + { + printf("__________>%s -> %s \n", Key, Value); + serv_printf("%s|%s", Key, Value); } serv_puts(""); serv_puts("000"); + DeleteHashPos(&HashPos); } - /* Go back to the room we're supposed to be in */ + /** Go back to the room we're supposed to be in */ serv_printf("GOTO %s", WC->wc_roomname); serv_getln(buf, sizeof buf); } -/* - * query the actual setting of key in the citadel database - * key config key to query - * value value to the key to get - * value_len length of the value string +/** + * \brief query the actual setting of key in the citadel database + * \param key config key to query + * \param value value to the key to get + * \param value_len length of the value string */ void get_preference(char *key, char *value, size_t value_len) { - struct wcpref *ptr; - + void *hash_value = NULL; + strcpy(value, ""); - - for (ptr = WC->first_pref; ptr != NULL; ptr = ptr->next) { - if (!strcasecmp(ptr->pref_key, key)) { - safestrncpy(value, ptr->pref_value, value_len); - return; - } - } + PrintHash(WC->hash_prefs); + if (GetHash(WC->hash_prefs, key, strlen(key), &hash_value) == 0) + return; + + if(hash_value) + safestrncpy(value, hash_value, value_len); } -/* - *Write a key into the webcit preferences database for this user +/** + * \brief Write a key into the webcit preferences database for this user * - * key key whichs value is to be modified - * value value to set - * save_to_server 1 = flush all data to the server, 0 = cache it for now + * \params key key whichs value is to be modified + * \param value value to set + * \param save_to_server 1 = flush all data to the server, 0 = cache it for now */ void set_preference(char *key, char *value, int save_to_server) { - - store_preference(key, value); + + Put(WC->hash_prefs, key, strlen(key), strdup(value), free); + if (save_to_server) save_preferences(); } -/* - * display form for changing your preferences and settings +/** + * \brief display form for changing your preferences and settings */ void display_preferences(void) { diff --git a/webcit/webcit.h b/webcit/webcit.h index 1c8397df9..6b865e4f9 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -100,7 +100,7 @@ extern locale_t wc_locales[]; #undef PACKAGE_BUGREPORT #include "sysdep.h" - +////////#include "hash.h" #ifdef HAVE_OPENSSL /* Work around RedHat's b0rken OpenSSL includes */ @@ -326,15 +326,6 @@ struct folder { int num_rooms; /**< If this is a floor, how many rooms does it have */ }; - -/* Linked list member for a list of webcit preferences for a user - */ -struct wcpref { - struct wcpref *next; - char *pref_key; - char *pref_value; -}; - /** * \brief One of these is kept for each active Citadel session. * HTTP transactions are bound to on e at a time. @@ -384,6 +375,7 @@ struct wcsession { struct wcsubst *vars; /**< HTTP variable substitutions for this page */ char this_page[512]; /**< URL of current page */ char http_host[512]; /**< HTTP Host: header */ + HashList *hash_prefs; /**< WebCit preferences for this user */ #ifdef WEBCIT_WITH_CALENDAR_SERVICE /** \brief ical???? */ struct disp_cal { @@ -413,7 +405,6 @@ struct wcsession { time_t last_pager_check; /**< last time we polled for instant msgs */ int nonce; /**< session nonce (to prevent session riding) */ int time_format_cache; /**< which timeformat does our user like? */ - struct wcpref *first_pref; /* linked list of preferences */ }; /** values for WC->current_iconbar */ -- 2.30.2