bbslib::userec

作者: 遊手好閒的石頭成 <shirock@mail.educities.edu.tw>
日期: 2001年4月17日

Header files

#include <bbslib/bbsdefs.h>
#include <bbslib/pool.h>
#include <bbslib/userec.h>

也可以直接引入 <bbslib.h> , bbslib.h 會將引入所有 bbslib 的 header files 。

Struct

typedef struct userec {
  phash_t	fields;
  unsigned int level;
  unsigned int group;
  char* (*get)(struct userec*, const char*field_name);
  char* (*put)(struct userec*, const char*field_name, const char*content);
  char* (*userid)(struct userec*);
  char* (*username)(struct userec*);
  unsigned int (*setlevel)(struct userec*);
  unsigned int (*setgroup)(struct userec*);
  int (*checkpasswd)(struct userec*, const char*passwd);
  int (*chpasswd)(struct userec*, const char*newpass);
} userec_t ;

Functions

invalid_userid()

int invalid_userid( const char*userid );

valid userid: [A-Za-z][A-Za-z0-9]*IDLEN-2
etc/.badname 中另外列出保留或不雅的英文名稱。

RC: invalid(YEA,1), valid(NA,0).

userid_exist()

int userid_exist(const char*userid);

#define existent_userid userid_exist

Check userid exists

RC: exists(YEA, 1), not exists(NA, 0)

userec_construct()/userec_destroy()

userec_t* userec_construct(userec_t*urec);

void userec_destroy(userec_t*urec);

建構及解構 userec_t 物件的內容。

user_getfield()/user_putfield

char*user_getfield(userec_t*urec, const char*field_name);

char*user_putfield(userec_t*urec, const char*field_name, char*content);

取得及指派欄位內容。

user_userid()/user_username()

char*user_userid(userec_t*urec);

char*user_username(userec_t*urec);

取得 userid / username 的內容。 與 user_getfield("userid") / user_getfield("username") 相同。

user_setlevel()/user_setgroup()

unsigned int user_setlevel(userec_t*urec, unsigned int newlevel);

unsigned int user_setgroup(userec_t*urec, unsigned int newgroup);

設定新的 level / group 的值。

若要取得 level / group 的值,可以直接讀取 userec.level / userec.group 的內容; 但若試圖直接設定 userec.level / userec.group 的內容,是不會被儲存起來的。

user_chpasswd()/user_checkpasswd()

int user_chpasswd(userec_t*urec, const char*newpasswd);

int user_checkpasswd(userec_t*urec, const char*test);

user_chpasswd() 改變使用者密碼。 有兩個特殊密碼: (1)newpasswd = "" (空字串) ,不需要密碼... (2)newpasswd = "*" 不能 login 。

RC: 0(success), -1(error)

user_checkpasswd() 檢查使用者密碼。 必須使用 user_checkpasswd() 才能檢查使用者密碼。

RC: YEA(valid), NA(invalid)

user_append()

int user_append(userec_t*urec);

新增使用者。 使用者的資料應已在 urec 中設定好,且不可省略 userid 欄位的內容。

user_delete()

int user_delete(userec_t*urec);

刪除使用者。 根據 urec 的 userid 欄位的內容刪除使用者記錄。

user_fetch()/getuser()

userec_t *user_fetch(char*userid);

int getuser(char*userid, userec_t*urec);

讀取使用者的記錄至 urec 中。 user_fetch() 會自動建構一個 userec_t 物件回傳。

user_update()

int user_update(userec_t*urec);

#define user_modify user_update

更新使用者記錄的內容。

user_store()

int user_store(userec_t*urec);

儲存使用者記錄的內容。 會自動解構 urec 。


The TIP Project

Short URL: http://fbtip.tsx.org/
Group: http://groups.yahoo.com/list/firebird-tip
Mailing list: firebird-tip@yahoogroups.com