static const HashValue *ht_lookup(HashTable *ht, const char *key) {
Tcl_HashEntry *he;
- const HashValue *htv;
- he= Tcl_FindHashEntry(ht, key);
+ he= Tcl_FindHashEntry(&ht->t, key);
if (!he) return 0;
return Tcl_GetHashValue(he);
/*---------- Lookups ----------*/
-static int wrlookup(Tcl_Interp *ip, void *rw_v, const char *key,
+static int lookup_rw(Tcl_Interp *ip, void *rw_v, const char *key,
const Byte **data_r, int *len_r /* -1 => notfound */) {
Rw *rw= rw_v;
const HashValue *val;
- int r, l;
+ int r;
val= ht_lookup(&rw->logincore, key);
if (val) {
return TCL_OK;
}
-int cht_cdb_dosomelookup(ClientData cd, Tcl_Interp *ip, void *db_v,
- int (*somelookup)(Tcl_Interp *ip, void *db_v,
- const char *key,
- const Byte **data_r, int *len_r),
- const char *key, Tcl_Obj *def,
- Tcl_Obj **result) {
- int r, len;
- const Byte *data;
-
- r= somelookup(ip, db_v, key, &data, &len);
- if (r) return r;
- if (len>0) {
- r= storeanswer();
- }
- if (def) {
- *result= def;
- return TCL_OK;
- }
- return cht_staticerr(ip, "cdbwr lookup key not found", "CDB NOTFOUND");
-
- if (len<0) *result= def;
- else *result= Tcl_NewStringObj(
+int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *rw_v,
+ const char *key, Tcl_Obj *def,
+ Tcl_Obj **result) {
+ return cht_cdb_dosomelookup(ip, rw_v, key, def, result,
+ lookup_rw, cht_cdb_storeanswer_string);
}
-
-static int storeanswer
-int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *rw_v,
- const char *key, HBytes_Value def,
- HBytes_Value *result) {
- *result= Tcl_NewStringObj(data, len);
- if (!*result) return cht_staticerr(ip, "Tcl_NewStringObj failed for"
- " lookup (utf-8 encoding problem?)", "CDB BADSTRING");
- return TCL_OK;
int cht_do_cdbwr_lookup_hb(ClientData cd, Tcl_Interp *ip, void *rw_v,
- const char *key, HBytes_Value def,
- HBytes_Value *result) {
- Rw *rw= rw_v;
- int r;
-
- r= lookup(ip, rw, key, &data, &len);
- if (r) return r;
- if (len>0) {
- cht_hb_array(result, data, len);
- return TCL_OK;
- }
- if (!HBYTES_ISSENTINEL(def)) {
- cht_hb_array(result, cht_hb_data(&def), cht_hb
+ const char *key, Tcl_Obj *def,
+ Tcl_Obj **result) {
+ return cht_cdb_dosomelookup(ip, rw_v, key, def, result,
+ lookup_rw, cht_cdb_storeanswer_hb);
+}