Back to index

webcit  8.12-dfsg
Defines | Typedefs | Enumerations | Functions
preferences.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define RegisterPreference(a, b, c, d)   _RegisterPreference(a, sizeof(a) -1, b, c, d, #d)
#define get_preference(a, b)   get_PREFERENCE(a, sizeof(a) - 1, b)
#define get_pref(a, b)   get_PREFERENCE(SKEY(a), b)
#define set_preference(a, b, c)   set_PREFERENCE(a, sizeof(a) - 1, b, c)
#define set_pref(a, b, c)   set_PREFERENCE(SKEY(a), b, c)
#define get_pref_long(a, b, c)   get_PREF_LONG(a, sizeof(a) - 1, b, c)
#define set_pref_long(a, b, c)   set_PREF_LONG(a, sizeof(a) - 1, b, c)
#define get_pref_yesno(a, b, c)   get_PREF_YESNO(a, sizeof(a) - 1, b, c)
#define set_pref_yesno(a, b, c)   set_PREF_YESNO(a, sizeof(a) - 1, b, c)
#define get_room_pref(a)   get_ROOM_PREFS(a, sizeof(a) - 1)
#define set_room_pref(a, b, c)   set_ROOM_PREFS(a, sizeof(a) - 1, b, c)
#define get_room_pref_long(a, b, c)   get_ROOM_PREFS_LONG(a, sizeof(a) - 1, b, c)
#define get_x_pref(a, b)   get_ROOM_PREFS(a, sizeof(a) - 1, b, sizeof(b) - 1)
#define set_x_pref(a, b, c)   set_ROOM_PREFS(a, sizeof(a) - 1, b, sizeof(b) - 1, c, d)

Typedefs

typedef enum _ePrefType ePrefType
typedef void(* PrefEvalFunc )(StrBuf *Preference, long lvalue)

Enumerations

enum  _ePrefType {
  PRF_UNSET = 0, PRF_STRING = 1, PRF_INT = 2, PRF_QP_STRING = 3,
  PRF_YESNO = 4
}

Functions

void _RegisterPreference (const char *Setting, long SettingLen, const char *PrefStr, ePrefType Type, PrefEvalFunc OnLoad, const char *OnLoadName)
void load_preferences (void)
void save_preferences (void)
int get_PREFERENCE (const char *key, size_t keylen, StrBuf **value)
void set_PREFERENCE (const char *key, size_t keylen, StrBuf *value, int save_to_server)
int get_PREF_LONG (const char *key, size_t keylen, long *value, long Default)
void set_PREF_LONG (const char *key, size_t keylen, long value, int save_to_server)
int get_PREF_YESNO (const char *key, size_t keylen, int *value, int Default)
void set_PREF_YESNO (const char *key, size_t keylen, long value, int save_to_server)
StrBuf * get_ROOM_PREFS (const char *key, size_t keylen)
void set_ROOM_PREFS (const char *key, size_t keylen, StrBuf *value, int save_to_server)
long get_ROOM_PREFS_LONG (const char *key, size_t keylen, long *value, long Default)
const StrBuf * get_X_PREFS (const char *key, size_t keylen, const char *xkey, size_t xkeylen)
void set_X_PREFS (const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
int goto_config_room (StrBuf *Buf, folder *room)

Define Documentation

#define get_pref (   a,
 
)    get_PREFERENCE(SKEY(a), b)

Definition at line 24 of file preferences.h.

#define get_pref_long (   a,
  b,
 
)    get_PREF_LONG(a, sizeof(a) - 1, b, c)

Definition at line 30 of file preferences.h.

#define get_pref_yesno (   a,
  b,
 
)    get_PREF_YESNO(a, sizeof(a) - 1, b, c)

Definition at line 35 of file preferences.h.

#define get_preference (   a,
 
)    get_PREFERENCE(a, sizeof(a) - 1, b)

Definition at line 23 of file preferences.h.

#define get_room_pref (   a)    get_ROOM_PREFS(a, sizeof(a) - 1)

Definition at line 40 of file preferences.h.

#define get_room_pref_long (   a,
  b,
 
)    get_ROOM_PREFS_LONG(a, sizeof(a) - 1, b, c)

Definition at line 45 of file preferences.h.

#define get_x_pref (   a,
 
)    get_ROOM_PREFS(a, sizeof(a) - 1, b, sizeof(b) - 1)

Definition at line 49 of file preferences.h.

#define RegisterPreference (   a,
  b,
  c,
 
)    _RegisterPreference(a, sizeof(a) -1, b, c, d, #d)

Definition at line 19 of file preferences.h.

#define set_pref (   a,
  b,
 
)    set_PREFERENCE(SKEY(a), b, c)

Definition at line 27 of file preferences.h.

#define set_pref_long (   a,
  b,
 
)    set_PREF_LONG(a, sizeof(a) - 1, b, c)

Definition at line 32 of file preferences.h.

#define set_pref_yesno (   a,
  b,
 
)    set_PREF_YESNO(a, sizeof(a) - 1, b, c)

Definition at line 37 of file preferences.h.

#define set_preference (   a,
  b,
 
)    set_PREFERENCE(a, sizeof(a) - 1, b, c)

Definition at line 26 of file preferences.h.

#define set_room_pref (   a,
  b,
 
)    set_ROOM_PREFS(a, sizeof(a) - 1, b, c)

Definition at line 43 of file preferences.h.

#define set_x_pref (   a,
  b,
 
)    set_ROOM_PREFS(a, sizeof(a) - 1, b, sizeof(b) - 1, c, d)

Definition at line 53 of file preferences.h.


Typedef Documentation

typedef enum _ePrefType ePrefType
typedef void(* PrefEvalFunc)(StrBuf *Preference, long lvalue)

Definition at line 11 of file preferences.h.


Enumeration Type Documentation

enum _ePrefType
Enumerator:
PRF_UNSET 
PRF_STRING 
PRF_INT 
PRF_QP_STRING 
PRF_YESNO 

Definition at line 2 of file preferences.h.


Function Documentation

void _RegisterPreference ( const char *  Setting,
long  SettingLen,
const char *  PrefStr,
ePrefType  Type,
PrefEvalFunc  OnLoad,
const char *  OnLoadName 
)

Definition at line 60 of file preferences.c.

{
       PrefDef *Newpref = (PrefDef*) malloc(sizeof(PrefDef));
       Newpref->Setting = NewStrBufPlain(Setting, SettingLen);
       Newpref->PrefStr = PrefStr;
       Newpref->eType = Type;
       Newpref->OnLoad = OnLoad;
       if (Newpref->OnLoad != NULL) {
              Newpref->OnLoadName = NewStrBufPlain(OnLoadName, -1);
       }
       else
              Newpref->OnLoadName = NULL;
       Put(PreferenceHooks, Setting, SettingLen, Newpref, DestroyPrefDef);
}

Here is the call graph for this function:

int get_PREF_LONG ( const char *  key,
size_t  keylen,
long *  value,
long  Default 
)

Definition at line 658 of file preferences.c.

{
       Preference *Pref;
       int Ret;

       Ret = get_pref_backend(key, keylen, &Pref);
       if (Ret == 0) {
              *value = Default;
              return 0;
       }

       if (Pref->decoded)
              *value = Pref->lval;
       else {
              *value = Pref->lval = atol(ChrPtr(Pref->Val));
              Pref->decoded = 1;
       }
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int get_PREF_YESNO ( const char *  key,
size_t  keylen,
int *  value,
int  Default 
)

Definition at line 684 of file preferences.c.

{
       Preference *Pref;
       int Ret;

       Ret = get_pref_backend(key, keylen, &Pref);
       if (Ret == 0) {
              *value = Default;
              return 0;
       }

       if (Pref->decoded)
              *value = Pref->lval;
       else {
              *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
              Pref->decoded = 1;
       }
       return Ret;
}

Here is the call graph for this function:

int get_PREFERENCE ( const char *  key,
size_t  keylen,
StrBuf **  value 
)

Definition at line 464 of file preferences.c.

{
       Preference *Pref;
       int Ret;

       Ret = get_pref_backend(key, keylen, &Pref);
       if (Ret != 0)
              *value = Pref->Val;
       else
              *value = NULL;
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

StrBuf* get_ROOM_PREFS ( const char *  key,
size_t  keylen 
)

Definition at line 781 of file preferences.c.

{
       Preference *Pref;
       int Ret;

       Ret = get_room_prefs_backend(key, keylen, &Pref);

       if (Ret == 0) {
              return NULL;
       }
       else 
              return Pref->Val;
}

Here is the call graph for this function:

Here is the caller graph for this function:

long get_ROOM_PREFS_LONG ( const char *  key,
size_t  keylen,
long *  value,
long  Default 
)

Definition at line 759 of file preferences.c.

{
       Preference *Pref;
       int Ret;

       Ret = get_room_prefs_backend(key, keylen, &Pref);

       if (Ret == 0) {
              *value = Default;
              return 0;
       }

       if (Pref->decoded)
              *value = Pref->lval;
       else {
              *value = Pref->lval = atol(ChrPtr(Pref->Val));
              Pref->decoded = 1;
       }
       return Ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const StrBuf* get_X_PREFS ( const char *  key,
size_t  keylen,
const char *  xkey,
size_t  xkeylen 
)

Definition at line 725 of file preferences.c.

{
       int ret;
       StrBuf *pref_name;
       Preference *Prf;
       
       pref_name = NewStrBufPlain (HKEY("XPREF:"));
       StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
       StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
       StrBufAppendBufPlain(pref_name, key, keylen, 0);

       ret = get_pref_backend(SKEY(pref_name), &Prf);
       FreeStrBuf(&pref_name);

       if (ret)
              return Prf->Val;
       else return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int goto_config_room ( StrBuf *  Buf,
folder room 
)

Definition at line 288 of file preferences.c.

{
       serv_printf("GOTO %s", USERCONFIGROOM);
       StrBuf_ServGetln(Buf);
       if (GetServerStatus(Buf, NULL) != 2) {    /* try to create the config room if not there */
              serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
              StrBuf_ServGetln(Buf);
              GetServerStatus(Buf, NULL);

              serv_printf("GOTO %s", USERCONFIGROOM);
              StrBuf_ServGetln(Buf);
              if (GetServerStatus(Buf, NULL) != 2) {
                     return(1);
              }
       }
       ParseGoto(Room, Buf);
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void load_preferences ( void  )

Definition at line 226 of file preferences.c.

{
       folder Room;
       wcsession *WCC = WC;
       int Done = 0;
       StrBuf *ReadBuf;
       long msgnum = 0L;
       
       memset(&Room, 0, sizeof(folder));
       ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
       if (goto_config_room(ReadBuf, &Room) != 0) {
              FreeStrBuf(&ReadBuf);
              FlushFolder(&Room);

              return;       /* oh well. */
       }

       serv_puts("MSGS ALL|0|1");
       StrBuf_ServGetln(ReadBuf);
       if (GetServerStatus(ReadBuf, NULL) == 8) {
              serv_puts("subj|__ WebCit Preferences __");
              serv_puts("000");
       }
       while (!Done && (StrBuf_ServGetln(ReadBuf) >= 0)) {
              if ( (StrLength(ReadBuf)==3) && !strcmp(ChrPtr(ReadBuf), "000")) {
                     Done = 1;
                     break;
              }
              msgnum = StrTol(ReadBuf);
       }

       if (msgnum > 0L) {
              serv_printf("MSG0 %ld", msgnum);
              StrBuf_ServGetln(ReadBuf);
              if (GetServerStatus(ReadBuf, NULL) == 1) {
                     while (       (StrBuf_ServGetln(ReadBuf) >= 0)
                            && (strcmp(ChrPtr(ReadBuf), "text")
                            && strcmp(ChrPtr(ReadBuf), "000"))
                     ) {
                            /* flush */
                     }
                     if (!strcmp(ChrPtr(ReadBuf), "text")) {
                            ParsePref(&WCC->hash_prefs, ReadBuf);
                     }
              }
       }

       /* Go back to the room we're supposed to be in */
       if (StrLength(WCC->CurRoom.name) > 0) {
              serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
              StrBuf_ServGetln(ReadBuf);
              GetServerStatus(ReadBuf, NULL);
       }
       FreeStrBuf(&ReadBuf);
       FlushFolder(&Room);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void save_preferences ( void  )

Go back to the room we're supposed to be in

Definition at line 369 of file preferences.c.

{
       folder Room;
       wcsession *WCC = WC;
       int Done = 0;
       StrBuf *ReadBuf;
       long msgnum = 0L;
       
       ReadBuf = NewStrBuf();
       memset(&Room, 0, sizeof(folder));
       if (goto_config_room(ReadBuf, &Room) != 0) {
              FreeStrBuf(&ReadBuf);
              FlushFolder(&Room);

              return;       /* oh well. */
       }

       /* make shure the config room has the right type, else it might reject our config */
       if (Room.view != VIEW_BBS) {
              serv_printf("VIEW %d", VIEW_BBS);
              StrBuf_ServGetln(ReadBuf);
              if (GetServerStatus(ReadBuf, NULL) != 2) {
                     /* UPS? */
              }
              else if (goto_config_room(ReadBuf, &Room) != 0) {
                     FreeStrBuf(&ReadBuf);
                     FlushFolder(&Room);
                     
                     return;       /* oh well. */
              }
       }

       serv_puts("MSGS ALL|0|1");
       StrBuf_ServGetln(ReadBuf);
       if (GetServerStatus(ReadBuf, NULL) == 8) {
              serv_puts("subj|__ WebCit Preferences __");
              serv_puts("000");
       }
       while (!Done && (StrBuf_ServGetln(ReadBuf) >= 0)) {
              if ( (StrLength(ReadBuf)==3) && !strcmp(ChrPtr(ReadBuf), "000")) {
                     Done = 1;
                     break;
              }
              msgnum = StrTol(ReadBuf);
       }

       if (msgnum > 0L) {
              serv_printf("DELE %ld", msgnum);
              StrBuf_ServGetln(ReadBuf);
              GetServerStatus(ReadBuf, NULL);
       }

       serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
       StrBuf_ServGetln(ReadBuf);
       if (GetServerStatus(ReadBuf, NULL) == 4) {

              WritePrefsToServer(WCC->hash_prefs);
              serv_puts("");
              serv_puts("000");
       }

       if (StrLength(WCC->CurRoom.name) > 0) {
              serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
              StrBuf_ServGetln(ReadBuf);
              GetServerStatus(ReadBuf, NULL);
       }
       FreeStrBuf(&ReadBuf);
       FlushFolder(&Room);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_PREF_LONG ( const char *  key,
size_t  keylen,
long  value,
int  save_to_server 
)

Definition at line 679 of file preferences.c.

{
       set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
}

Here is the call graph for this function:

void set_PREF_YESNO ( const char *  key,
size_t  keylen,
long  value,
int  save_to_server 
)

Definition at line 704 of file preferences.c.

{
       set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
}

Here is the call graph for this function:

void set_PREFERENCE ( const char *  key,
size_t  keylen,
StrBuf *  value,
int  save_to_server 
)

Definition at line 653 of file preferences.c.

{
       set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
}

Here is the call graph for this function:

void set_ROOM_PREFS ( const char *  key,
size_t  keylen,
StrBuf *  value,
int  save_to_server 
)

Definition at line 795 of file preferences.c.

{
       StrBuf *pref_name;
       
       pref_name = NewStrBufPlain (HKEY("ROOM:"));
       StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
       StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
       StrBufAppendBufPlain(pref_name, key, keylen, 0);
       set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
       FreeStrBuf(&pref_name);
}

Here is the call graph for this function:

void set_X_PREFS ( const char *  key,
size_t  keylen,
const char *  xkey,
size_t  xkeylen,
StrBuf *  value,
int  save_to_server 
)

Definition at line 745 of file preferences.c.

{
       StrBuf *pref_name;
       
       pref_name = NewStrBufPlain (HKEY("XPREF:"));
       StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
       StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
       StrBufAppendBufPlain(pref_name, key, keylen, 0);

       set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
       FreeStrBuf(&pref_name);
}

Here is the call graph for this function:

Here is the caller graph for this function: