| 1 | #ifdef ARBDB_H |
|---|
| 2 | #error Please do not include "arbdb.h" yourself when also including "adlocal.h" |
|---|
| 3 | #endif |
|---|
| 4 | |
|---|
| 5 | #ifndef ADLOCAL_H |
|---|
| 6 | #define ADLOCAL_H |
|---|
| 7 | |
|---|
| 8 | #ifndef _STDIO_H |
|---|
| 9 | #include <stdio.h> |
|---|
| 10 | #endif |
|---|
| 11 | #ifndef _STDINT_H |
|---|
| 12 | #include <stdint.h> |
|---|
| 13 | #endif |
|---|
| 14 | #ifndef ATTRIBUTES_H |
|---|
| 15 | #include <attributes.h> |
|---|
| 16 | #endif |
|---|
| 17 | #ifndef ARBDB_BASE_H |
|---|
| 18 | #include <arbdb_base.h> |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | /* ================ Test memory @@@===================== */ |
|---|
| 22 | #if defined(DEBUG) |
|---|
| 23 | #define MEMORY_TEST 1 |
|---|
| 24 | #else |
|---|
| 25 | #define MEMORY_TEST 0 |
|---|
| 26 | #endif |
|---|
| 27 | |
|---|
| 28 | #ifdef __cplusplus |
|---|
| 29 | inline void ad_use(int, ...) {} |
|---|
| 30 | #else |
|---|
| 31 | void ad_use(int dummy, ...); |
|---|
| 32 | #endif |
|---|
| 33 | |
|---|
| 34 | #define ADUSE(variable) ad_use(1, variable) |
|---|
| 35 | |
|---|
| 36 | #if (MEMORY_TEST==1) |
|---|
| 37 | |
|---|
| 38 | #define gbm_put_memblk(block,size) |
|---|
| 39 | #define gbm_get_memblk(size) (char*)(GB_calloc(1,size)) |
|---|
| 40 | #define gbm_get_mem(size,index) (char*)(GB_calloc(1,size)) |
|---|
| 41 | #define gbm_free_mem(block,size,index) do { free(block); ADUSE(index); } while(0) |
|---|
| 42 | #define fread(block,size,nelem,stream) (memset(block,0,size*nelem), (fread)(block,size,nelem,stream)) |
|---|
| 43 | |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | /* ================ Assert's ======================== */ |
|---|
| 47 | |
|---|
| 48 | #ifndef ARB_ASSERT_H |
|---|
| 49 | #include <arb_assert.h> |
|---|
| 50 | #endif |
|---|
| 51 | #define ad_assert(bed) arb_assert(bed) |
|---|
| 52 | |
|---|
| 53 | /* ================================================== */ |
|---|
| 54 | |
|---|
| 55 | #define GBTUM_MAGIC_NUMBER 0x17488400 |
|---|
| 56 | #define GBTUM_MAGIC_NUMBER_FILTER 0xffffff00 |
|---|
| 57 | |
|---|
| 58 | #define GBTUM_MAGIC_REVERSED 0x00844817 |
|---|
| 59 | |
|---|
| 60 | #define GB_MAX_PROJECTS 256 |
|---|
| 61 | #define GBTUM_COMPRESS_TREE_SIZE 32 |
|---|
| 62 | #define GB_MAX_USERS 4 |
|---|
| 63 | #define GB_MAX_KEYS 0x1000000 /* 24 bit see flags also */ |
|---|
| 64 | |
|---|
| 65 | #define CROSS_BUFFER_DIFF 20 |
|---|
| 66 | #define SIZOFINTERN 10 |
|---|
| 67 | |
|---|
| 68 | #define GB_SYSTEM_FOLDER "__SYSTEM__" |
|---|
| 69 | #define GB_SYSTEM_KEY_DATA "@key_data" |
|---|
| 70 | |
|---|
| 71 | #define GB_MAX_MAPPED_FILES 10 |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | /********** RELATIVE ADRESSING *************/ |
|---|
| 75 | |
|---|
| 76 | #if (MEMORY_TEST==1) |
|---|
| 77 | typedef void *GB_REL_ADD; |
|---|
| 78 | typedef char *GB_REL_STRING; |
|---|
| 79 | typedef struct gb_data_base_type *GB_REL_GBDATA; |
|---|
| 80 | typedef struct gb_data_base_type2 *GB_REL_CONTAINER; |
|---|
| 81 | typedef struct gb_header_list_struct *GB_REL_HLS; |
|---|
| 82 | typedef struct gb_if_entries *GB_REL_IFES; |
|---|
| 83 | typedef struct gb_index_files_struct *GB_REL_IFS; |
|---|
| 84 | typedef struct gb_if_entries **GB_REL_PIFES; |
|---|
| 85 | #else |
|---|
| 86 | typedef long GB_REL_ADD; /* relative adress */ |
|---|
| 87 | typedef long GB_REL_STRING; /* relative adress */ |
|---|
| 88 | typedef long GB_REL_GBDATA; /* relative adress */ |
|---|
| 89 | typedef long GB_REL_CONTAINER; /* relative adress */ |
|---|
| 90 | typedef long GB_REL_HLS; /* relative adress */ |
|---|
| 91 | typedef long GB_REL_IFES; /* relative adress */ |
|---|
| 92 | typedef long GB_REL_IFS; /* relative adress */ |
|---|
| 93 | typedef long GB_REL_PIFES; /* relative adress */ |
|---|
| 94 | #endif |
|---|
| 95 | |
|---|
| 96 | typedef short GB_MAIN_IDX; /* random-index */ |
|---|
| 97 | |
|---|
| 98 | typedef struct gbs_hash_struct GB_HASH; |
|---|
| 99 | typedef struct gbs_hashi_struct GB_HASHI; |
|---|
| 100 | |
|---|
| 101 | struct GBS_regex; |
|---|
| 102 | struct GBS_string_matcher; |
|---|
| 103 | |
|---|
| 104 | typedef struct GBS_regex GBS_REGEX; |
|---|
| 105 | typedef struct GBS_string_matcher GBS_MATCHER; |
|---|
| 106 | |
|---|
| 107 | #define GB_MAIN_ARRAY_SIZE 4096 |
|---|
| 108 | |
|---|
| 109 | struct GBS_strstruct; |
|---|
| 110 | |
|---|
| 111 | /********************************************/ |
|---|
| 112 | |
|---|
| 113 | enum { |
|---|
| 114 | GBM_CB_INDEX = -1, |
|---|
| 115 | GBM_HASH_INDEX = -2, |
|---|
| 116 | GBM_HEADER_INDEX = -3, |
|---|
| 117 | GBM_UNDO = -4, |
|---|
| 118 | GBM_DICT_INDEX = -5, |
|---|
| 119 | GBM_USER_INDEX = -6 |
|---|
| 120 | }; |
|---|
| 121 | |
|---|
| 122 | typedef long gb_bool; |
|---|
| 123 | struct gb_map_header; |
|---|
| 124 | |
|---|
| 125 | #define _GB_UNDO_TYPE_DEFINED |
|---|
| 126 | typedef enum { /* Warning: Same typedef in arbdb.h */ |
|---|
| 127 | GB_UNDO_NONE, |
|---|
| 128 | GB_UNDO_KILL, /* no undo and delete all old undos */ |
|---|
| 129 | GB_UNDO_UNDO, |
|---|
| 130 | GB_UNDO_REDO, |
|---|
| 131 | GB_UNDO_UNDO_REDO |
|---|
| 132 | } GB_UNDO_TYPE; |
|---|
| 133 | |
|---|
| 134 | typedef enum gb_changed_types { |
|---|
| 135 | gb_not_changed = 0, |
|---|
| 136 | gb_son_changed = 2, |
|---|
| 137 | gb_changed = 4, |
|---|
| 138 | gb_created = 5, |
|---|
| 139 | gb_deleted = 6, |
|---|
| 140 | gb_deleted_in_master = 7 |
|---|
| 141 | } GB_CHANGED; |
|---|
| 142 | |
|---|
| 143 | enum gb_open_types { |
|---|
| 144 | gb_open_all = 0, |
|---|
| 145 | gb_open_read_only_all = 16, |
|---|
| 146 | gb_open_read_only_small = 17 |
|---|
| 147 | }; |
|---|
| 148 | |
|---|
| 149 | #ifdef __cplusplus |
|---|
| 150 | extern "C" { |
|---|
| 151 | #endif |
|---|
| 152 | |
|---|
| 153 | typedef void (*GB_CB)(GBDATA *,int *clientdata, GB_CB_TYPE gbtype); |
|---|
| 154 | |
|---|
| 155 | #ifdef __cplusplus |
|---|
| 156 | } |
|---|
| 157 | #endif |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | typedef int GBQUARK; |
|---|
| 161 | |
|---|
| 162 | /********************* compress ******************/ |
|---|
| 163 | enum GB_COMPRESSION_TYPES { |
|---|
| 164 | GB_COMPRESSION_NONE = 0, |
|---|
| 165 | GB_COMPRESSION_RUNLENGTH = 1, |
|---|
| 166 | GB_COMPRESSION_HUFFMANN = 2, |
|---|
| 167 | GB_COMPRESSION_DICTIONARY = 4, |
|---|
| 168 | GB_COMPRESSION_SEQUENCE = 8, |
|---|
| 169 | GB_COMPRESSION_SORTBYTES = 16, |
|---|
| 170 | GB_COMPRESSION_BITS = 32, |
|---|
| 171 | GB_COMPRESSION_LAST = 128 |
|---|
| 172 | }; |
|---|
| 173 | typedef int GB_NINT; /* Network byte order int */ |
|---|
| 174 | |
|---|
| 175 | typedef struct { |
|---|
| 176 | int words; |
|---|
| 177 | int textlen; |
|---|
| 178 | unsigned char *text; |
|---|
| 179 | GB_NINT *offsets; /* in network byte order */ |
|---|
| 180 | GB_NINT *resort; /* in network byte order */ |
|---|
| 181 | |
|---|
| 182 | } GB_DICTIONARY; |
|---|
| 183 | |
|---|
| 184 | extern int gb_convert_type_2_compression_flags[]; |
|---|
| 185 | extern int gb_convert_type_2_sizeof[]; |
|---|
| 186 | extern int gb_convert_type_2_appendix_size[]; |
|---|
| 187 | extern int gb_verbose_mode; |
|---|
| 188 | |
|---|
| 189 | #define GB_UNCOMPRESSED_SIZE(gbd, type) (GB_GETSIZE(gbd) * gb_convert_type_2_sizeof[type] + gb_convert_type_2_appendix_size[type]) |
|---|
| 190 | |
|---|
| 191 | struct gb_compress_tree { |
|---|
| 192 | char leave; |
|---|
| 193 | struct gb_compress_tree *son[2]; |
|---|
| 194 | }; |
|---|
| 195 | |
|---|
| 196 | enum gb_compress_list_commands { |
|---|
| 197 | gb_cs_ok = 0, |
|---|
| 198 | gb_cs_sub = 1, |
|---|
| 199 | gb_cs_id = 2, |
|---|
| 200 | gb_cs_end = 3, |
|---|
| 201 | gb_cd_node = 4 |
|---|
| 202 | }; |
|---|
| 203 | |
|---|
| 204 | struct gb_compress_list { |
|---|
| 205 | enum gb_compress_list_commands command; |
|---|
| 206 | |
|---|
| 207 | int value; |
|---|
| 208 | int bitcnt; |
|---|
| 209 | int bits; |
|---|
| 210 | int mask; |
|---|
| 211 | long count; |
|---|
| 212 | |
|---|
| 213 | struct gb_compress_list *son[2]; |
|---|
| 214 | }; |
|---|
| 215 | |
|---|
| 216 | /********************* main ******************/ |
|---|
| 217 | |
|---|
| 218 | struct gb_user_struct { |
|---|
| 219 | char *username; |
|---|
| 220 | int userid; |
|---|
| 221 | int userbit; |
|---|
| 222 | int nusers; /* number of clients of this user */ |
|---|
| 223 | }; |
|---|
| 224 | |
|---|
| 225 | struct gb_project_struct { |
|---|
| 226 | char *projectname; |
|---|
| 227 | int projectid; |
|---|
| 228 | |
|---|
| 229 | struct gb_export_project { |
|---|
| 230 | struct gb_export_project *next; |
|---|
| 231 | char *username; |
|---|
| 232 | } *export_; |
|---|
| 233 | |
|---|
| 234 | long export_2_users; /* bits , one bit for each logged in user */ |
|---|
| 235 | }; |
|---|
| 236 | |
|---|
| 237 | struct gb_data_base_type; |
|---|
| 238 | struct gb_key_struct { |
|---|
| 239 | char *key; |
|---|
| 240 | |
|---|
| 241 | long nref; |
|---|
| 242 | long next_free_key; |
|---|
| 243 | long nref_last_saved; |
|---|
| 244 | |
|---|
| 245 | struct gb_data_base_type *gb_key; /* for fast access and dynamic loading */ |
|---|
| 246 | struct gb_data_base_type *gb_master_ali; /* Pointer to the master container */ |
|---|
| 247 | int gb_key_disabled; /* There will never be a gb_key */ |
|---|
| 248 | int compression_mask; /* maximum compression for this type */ |
|---|
| 249 | GB_DICTIONARY *dictionary; /* optional dictionary */ |
|---|
| 250 | |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | struct gb_quick_save_struct { |
|---|
| 254 | char *quick_save_disabled; /* GB_BOOL if set, than text decsribes reason*/ |
|---|
| 255 | int last_index; |
|---|
| 256 | }; |
|---|
| 257 | |
|---|
| 258 | struct gb_cache_entry_struct { |
|---|
| 259 | struct gb_data_base_type *gbd; |
|---|
| 260 | |
|---|
| 261 | long prev; |
|---|
| 262 | long next; |
|---|
| 263 | char *data; |
|---|
| 264 | long clock; |
|---|
| 265 | int sizeof_data; |
|---|
| 266 | }; |
|---|
| 267 | |
|---|
| 268 | struct gb_cache_struct { |
|---|
| 269 | struct gb_cache_entry_struct *entries; |
|---|
| 270 | |
|---|
| 271 | long firstfree_entry; |
|---|
| 272 | long newest_entry; |
|---|
| 273 | long oldest_entry; |
|---|
| 274 | long sum_data_size; |
|---|
| 275 | long max_data_size; |
|---|
| 276 | long max_entries; |
|---|
| 277 | }; |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | // ----------------------------------------------- |
|---|
| 282 | // root structure (one for each database) |
|---|
| 283 | |
|---|
| 284 | struct gbcmc_comm; |
|---|
| 285 | struct g_b_undo_mgr_struct; |
|---|
| 286 | struct gb_callback_list; |
|---|
| 287 | struct gb_data_base_type2; |
|---|
| 288 | struct gb_close_callback_struct; |
|---|
| 289 | |
|---|
| 290 | typedef struct gb_main_type { |
|---|
| 291 | int transaction; |
|---|
| 292 | int aborted_transaction; |
|---|
| 293 | int local_mode; // GB_TRUE = server, GB_FALSE = client |
|---|
| 294 | int client_transaction_socket; |
|---|
| 295 | |
|---|
| 296 | struct gbcmc_comm *c_link; |
|---|
| 297 | void *server_data; |
|---|
| 298 | struct gb_data_base_type2 *dummy_father; |
|---|
| 299 | struct gb_data_base_type2 *data; |
|---|
| 300 | struct gb_data_base_type *gb_key_data; |
|---|
| 301 | char *path; |
|---|
| 302 | enum gb_open_types opentype; |
|---|
| 303 | char *disabled_path; |
|---|
| 304 | int allow_corrupt_file_recovery; |
|---|
| 305 | |
|---|
| 306 | struct gb_quick_save_struct qs; |
|---|
| 307 | struct gb_cache_struct cache; |
|---|
| 308 | int compression_mask; |
|---|
| 309 | |
|---|
| 310 | int keycnt; /* first non used key */ |
|---|
| 311 | long sizeofkeys; /* malloc size */ |
|---|
| 312 | long first_free_key; /* index of first gap */ |
|---|
| 313 | struct gb_key_struct *keys; |
|---|
| 314 | GB_HASH *key_2_index_hash; |
|---|
| 315 | long key_clock; /* trans. nr. of last change */ |
|---|
| 316 | |
|---|
| 317 | char *keys_new[256]; |
|---|
| 318 | unsigned int last_updated; |
|---|
| 319 | long last_saved_time; |
|---|
| 320 | long last_saved_transaction; |
|---|
| 321 | long last_main_saved_transaction; |
|---|
| 322 | |
|---|
| 323 | GB_UNDO_TYPE requested_undo_type; |
|---|
| 324 | GB_UNDO_TYPE undo_type; |
|---|
| 325 | struct g_b_undo_mgr_struct *undo; |
|---|
| 326 | |
|---|
| 327 | char *dates[256]; |
|---|
| 328 | unsigned int security_level; |
|---|
| 329 | int old_security_level; |
|---|
| 330 | int pushed_security_level; |
|---|
| 331 | long clock; |
|---|
| 332 | GB_HASHI *remote_hash; |
|---|
| 333 | |
|---|
| 334 | GB_HASH *command_hash; |
|---|
| 335 | GB_HASH *resolve_link_hash; |
|---|
| 336 | GB_HASH *table_hash; |
|---|
| 337 | |
|---|
| 338 | struct gb_close_callback_struct *close_callbacks; |
|---|
| 339 | |
|---|
| 340 | struct gb_callback_list *cbl; /* contains change-callbacks (after change, until callbacks are done) */ |
|---|
| 341 | struct gb_callback_list *cbl_last; |
|---|
| 342 | |
|---|
| 343 | struct gb_callback_list *cbld; /* contains delete-callbacks (after delete, until callbacks are done) */ |
|---|
| 344 | struct gb_callback_list *cbld_last; |
|---|
| 345 | |
|---|
| 346 | struct gb_user_struct *users[GB_MAX_USERS]; /* user 0 is server */ |
|---|
| 347 | struct gb_project_struct *projects[GB_MAX_PROJECTS]; /* projects */ |
|---|
| 348 | struct gb_user_struct *this_user; |
|---|
| 349 | struct gb_project_struct *this_project; |
|---|
| 350 | |
|---|
| 351 | } GB_MAIN_TYPE; |
|---|
| 352 | |
|---|
| 353 | extern GB_MAIN_TYPE *gb_main_array[]; |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | typedef enum { ARB_COMMIT, ARB_ABORT, ARB_TRANS } ARB_TRANS_TYPE; |
|---|
| 357 | typedef enum { GB_IGNORE_CASE = 0 , GB_MIND_CASE = 1, GB_CASE_UNDEFINED = 2 } GB_CASE; |
|---|
| 358 | |
|---|
| 359 | // ------------------------------------------------------------------ |
|---|
| 360 | // global data structure that is used for all open databases |
|---|
| 361 | |
|---|
| 362 | struct gb_buffer { |
|---|
| 363 | char *mem; |
|---|
| 364 | size_t size; |
|---|
| 365 | }; |
|---|
| 366 | |
|---|
| 367 | struct gb_local_data { |
|---|
| 368 | struct gb_buffer buf1, buf2; |
|---|
| 369 | char *write_buffer; |
|---|
| 370 | char *write_ptr; |
|---|
| 371 | long write_bufsize; |
|---|
| 372 | long write_free; |
|---|
| 373 | int iamclient; |
|---|
| 374 | int search_system_folder; |
|---|
| 375 | |
|---|
| 376 | struct gb_compress_tree *bituncompress; |
|---|
| 377 | struct gb_compress_list *bitcompress; |
|---|
| 378 | |
|---|
| 379 | long bc_size; |
|---|
| 380 | long gb_compress_keys_count; |
|---|
| 381 | long gb_compress_keys_level; |
|---|
| 382 | |
|---|
| 383 | struct gb_main_type *gb_compress_keys_main; |
|---|
| 384 | ARB_TRANS_TYPE running_client_transaction; |
|---|
| 385 | struct { |
|---|
| 386 | struct gb_data_base_type *gb_main; |
|---|
| 387 | } gbl; |
|---|
| 388 | }; |
|---|
| 389 | |
|---|
| 390 | extern struct gb_local_data *gb_local; |
|---|
| 391 | extern const uint32_t crctab[]; |
|---|
| 392 | |
|---|
| 393 | struct gb_header_flags { |
|---|
| 394 | unsigned int flags:GB_MAX_USERS; /* public */ |
|---|
| 395 | unsigned int key_quark:24; /* == 0 -> invalid */ |
|---|
| 396 | unsigned int changed:3; |
|---|
| 397 | unsigned int ever_changed:1; /* is this element ever changed */ |
|---|
| 398 | } ; |
|---|
| 399 | |
|---|
| 400 | struct gb_header_list_struct { /* public fast flags */ |
|---|
| 401 | struct gb_header_flags flags; |
|---|
| 402 | |
|---|
| 403 | GB_REL_GBDATA rel_hl_gbd; /* Typ: (struct gb_data_base_type *) */ |
|---|
| 404 | /* pointer to data |
|---|
| 405 | if 0 & !key_index -> free data |
|---|
| 406 | if 0 & key_index -> data only in server */ |
|---|
| 407 | }; |
|---|
| 408 | |
|---|
| 409 | struct gb_data_list { |
|---|
| 410 | |
|---|
| 411 | GB_REL_HLS rel_header; /* Typ: (struct gb_header_list_struct *) */ |
|---|
| 412 | |
|---|
| 413 | int headermemsize; |
|---|
| 414 | int size; /* number of valid items */ |
|---|
| 415 | int nheader; /* size + deleted items */ |
|---|
| 416 | }; |
|---|
| 417 | struct gb_flag_types { /* public flags, abort possible */ |
|---|
| 418 | unsigned int type:4; |
|---|
| 419 | unsigned int security_delete:3; |
|---|
| 420 | unsigned int security_write:3; |
|---|
| 421 | unsigned int security_read:3; |
|---|
| 422 | unsigned int compressed_data:1; |
|---|
| 423 | unsigned int unused:1; /* last bit saved */ |
|---|
| 424 | unsigned int user_flags:8; |
|---|
| 425 | unsigned int temporary:1; /* ==1 -> dont save entry */ |
|---|
| 426 | unsigned int saved_flags:8; |
|---|
| 427 | }; |
|---|
| 428 | struct gb_flag_types2 { /* private flags, abortable */ |
|---|
| 429 | /* uncritic section undoable */ |
|---|
| 430 | unsigned int last_updated:8; |
|---|
| 431 | unsigned int usr_ref:7; /* for user access */ |
|---|
| 432 | /* critic section, do not update any below */ |
|---|
| 433 | unsigned int folded_container:1; |
|---|
| 434 | unsigned int update_in_server:1; /* already informed */ |
|---|
| 435 | unsigned int extern_data:1; /* data ref. by pntr*/ |
|---|
| 436 | unsigned int header_changed:1; /* used by container*/ |
|---|
| 437 | unsigned int gbm_index:8; /* memory section*/ |
|---|
| 438 | unsigned int tisa_index:1; /* this should be indexed */ |
|---|
| 439 | unsigned int is_indexed:1; /* this db. field is indexed*/ |
|---|
| 440 | }; |
|---|
| 441 | |
|---|
| 442 | struct gb_flag_types3 { /* user and project flags (public) |
|---|
| 443 | not abortable !!! */ |
|---|
| 444 | unsigned int project:8; |
|---|
| 445 | unsigned int unused:24; |
|---|
| 446 | }; |
|---|
| 447 | |
|---|
| 448 | struct gb_if_entries |
|---|
| 449 | { |
|---|
| 450 | GB_REL_IFES rel_ie_next; /* Typ: (struct gb_if_entries *) */ |
|---|
| 451 | GB_REL_GBDATA rel_ie_gbd; /* Typ: (struct gb_data_base_type *) */ |
|---|
| 452 | }; |
|---|
| 453 | |
|---|
| 454 | /** hash index to speed up GB_find(x,x,down_2_level) ***/ |
|---|
| 455 | |
|---|
| 456 | struct gb_index_files_struct { |
|---|
| 457 | GB_REL_IFS rel_if_next; /* Typ: (struct gb_index_files_struct *) */ |
|---|
| 458 | |
|---|
| 459 | GBQUARK key; |
|---|
| 460 | long hash_table_size; |
|---|
| 461 | long nr_of_elements; |
|---|
| 462 | GB_CASE case_sens; |
|---|
| 463 | |
|---|
| 464 | GB_REL_PIFES rel_entries; /* Typ: (struct gb_if_entries **) */ |
|---|
| 465 | }; |
|---|
| 466 | |
|---|
| 467 | struct gb_db_extended; |
|---|
| 468 | |
|---|
| 469 | typedef struct gb_data_base_type2 { /* public area */ |
|---|
| 470 | long server_id; |
|---|
| 471 | GB_REL_CONTAINER rel_father; /* Typ: (struct gb_data_base_type2 *) */ |
|---|
| 472 | struct gb_db_extended *ext; |
|---|
| 473 | long index; |
|---|
| 474 | struct gb_flag_types flags; |
|---|
| 475 | struct gb_flag_types2 flags2; /* privat area */ |
|---|
| 476 | struct gb_flag_types3 flags3; |
|---|
| 477 | struct gb_data_list d; |
|---|
| 478 | |
|---|
| 479 | long index_of_touched_one_son; /* index of modified son |
|---|
| 480 | in case of a single mod. son |
|---|
| 481 | -1 more than one (or one with ind = 0) |
|---|
| 482 | 0 no son |
|---|
| 483 | >0 index */ |
|---|
| 484 | long header_update_date; |
|---|
| 485 | |
|---|
| 486 | GB_MAIN_IDX main_idx; /* Typ: (GB_MAIN_TYPE *) */ |
|---|
| 487 | GB_REL_IFS rel_ifs; /* Typ: (struct gb_index_files_struct *) */ |
|---|
| 488 | |
|---|
| 489 | } GBCONTAINER; |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | struct gb_extern_data2 { |
|---|
| 493 | char *data; /* Typ: (char *) */ |
|---|
| 494 | long memsize; |
|---|
| 495 | long size; |
|---|
| 496 | }; |
|---|
| 497 | |
|---|
| 498 | struct GB_INTern_strings2 { |
|---|
| 499 | char data[SIZOFINTERN]; |
|---|
| 500 | unsigned char memsize; |
|---|
| 501 | unsigned char size; |
|---|
| 502 | }; |
|---|
| 503 | |
|---|
| 504 | struct GB_INTern2 { |
|---|
| 505 | char data[SIZOFINTERN]; |
|---|
| 506 | }; |
|---|
| 507 | |
|---|
| 508 | union gb_data_base_type_union2 { |
|---|
| 509 | struct GB_INTern_strings2 istr; |
|---|
| 510 | struct GB_INTern2 in; |
|---|
| 511 | struct gb_extern_data2 ex; |
|---|
| 512 | }; |
|---|
| 513 | |
|---|
| 514 | struct gb_transaction_save { |
|---|
| 515 | struct gb_flag_types flags; |
|---|
| 516 | struct gb_flag_types2 flags2; |
|---|
| 517 | union gb_data_base_type_union2 info; |
|---|
| 518 | short refcount; /* number of references to this object */ |
|---|
| 519 | }; |
|---|
| 520 | |
|---|
| 521 | struct gb_callback |
|---|
| 522 | { |
|---|
| 523 | struct gb_callback *next; |
|---|
| 524 | GB_CB func; |
|---|
| 525 | enum gb_call_back_type type; |
|---|
| 526 | int *clientdata; |
|---|
| 527 | short priority; |
|---|
| 528 | short running; |
|---|
| 529 | }; |
|---|
| 530 | |
|---|
| 531 | struct gb_callback_list { |
|---|
| 532 | struct gb_callback_list *next; |
|---|
| 533 | GB_CB func; |
|---|
| 534 | struct gb_transaction_save *old; |
|---|
| 535 | GB_CB_TYPE type; |
|---|
| 536 | struct gb_data_base_type *gbd; |
|---|
| 537 | int *clientdata; |
|---|
| 538 | }; |
|---|
| 539 | |
|---|
| 540 | /*#undef GBDATA*/ |
|---|
| 541 | |
|---|
| 542 | enum gb_undo_commands { |
|---|
| 543 | _GBCMC_UNDOCOM_REQUEST_NOUNDO_KILL, |
|---|
| 544 | _GBCMC_UNDOCOM_REQUEST_NOUNDO, |
|---|
| 545 | _GBCMC_UNDOCOM_REQUEST_UNDO, |
|---|
| 546 | _GBCMC_UNDOCOM_INFO_UNDO, |
|---|
| 547 | _GBCMC_UNDOCOM_INFO_REDO, |
|---|
| 548 | _GBCMC_UNDOCOM_UNDO, |
|---|
| 549 | _GBCMC_UNDOCOM_REDO, |
|---|
| 550 | |
|---|
| 551 | _GBCMC_UNDOCOM_SET_MEM = 10000 /* Minimum */ |
|---|
| 552 | }; |
|---|
| 553 | |
|---|
| 554 | enum gb_scan_quicks_types { |
|---|
| 555 | GB_SCAN_NO_QUICK, |
|---|
| 556 | GB_SCAN_NEW_QUICK, |
|---|
| 557 | GB_SCAN_OLD_QUICK |
|---|
| 558 | }; |
|---|
| 559 | |
|---|
| 560 | struct gb_scandir { |
|---|
| 561 | int highest_quick_index; |
|---|
| 562 | int newest_quick_index; |
|---|
| 563 | unsigned long date_of_quick_file; |
|---|
| 564 | enum gb_scan_quicks_types type; /* xxx.arb.quick? or xxx.a?? */ |
|---|
| 565 | }; |
|---|
| 566 | |
|---|
| 567 | #define GBCM_SERVER_OK_WAIT 3 |
|---|
| 568 | #define GBCM_SERVER_ABORTED 2 |
|---|
| 569 | #define GBCM_SERVER_FAULT 1 |
|---|
| 570 | #define GBCM_SERVER_OK 0 |
|---|
| 571 | |
|---|
| 572 | #ifndef ARBDB_H |
|---|
| 573 | # include "arbdb.h" |
|---|
| 574 | #endif |
|---|
| 575 | |
|---|
| 576 | #include "adtune.h" |
|---|
| 577 | #include "adlmacros.h" |
|---|
| 578 | |
|---|
| 579 | /* command interpreter */ |
|---|
| 580 | |
|---|
| 581 | #define GBL_MAX_ARGUMENTS 500 |
|---|
| 582 | |
|---|
| 583 | typedef struct gbl_struct { |
|---|
| 584 | char *str; |
|---|
| 585 | } GBL; |
|---|
| 586 | |
|---|
| 587 | typedef struct gbl_command_arguments_struct { |
|---|
| 588 | GBDATA *gb_ref; /* a database entry on which the command is applied (may be species, gene, experiment, group and maybe more) */ |
|---|
| 589 | const char *default_tree_name; /* if we have a default tree, its name is specified here (0 otherwise) */ |
|---|
| 590 | const char *command; /* the name of the current command */ |
|---|
| 591 | |
|---|
| 592 | int cinput; const GBL *vinput; /* input streams */ |
|---|
| 593 | int cparam; const GBL *vparam; /* parameter "streams" */ |
|---|
| 594 | int *coutput; GBL **voutput; /* the output streams */ |
|---|
| 595 | |
|---|
| 596 | } GBL_command_arguments; |
|---|
| 597 | |
|---|
| 598 | #ifdef __cplusplus |
|---|
| 599 | extern "C" { |
|---|
| 600 | #endif |
|---|
| 601 | |
|---|
| 602 | typedef GB_ERROR (*GBL_COMMAND)(GBL_command_arguments *args); |
|---|
| 603 | /* typedef GB_ERROR (*GBL_COMMAND)(GBDATA *gb_ref, char *com, GBL_client_data *cd, |
|---|
| 604 | int argcinput, GBL *argvinput, int argcparam,GBL *argvparam, int *argcout, GBL **argvout); */ |
|---|
| 605 | |
|---|
| 606 | #ifdef __cplusplus |
|---|
| 607 | } |
|---|
| 608 | #endif |
|---|
| 609 | |
|---|
| 610 | struct GBL_command_table { |
|---|
| 611 | const char *command_identifier; |
|---|
| 612 | GBL_COMMAND function; |
|---|
| 613 | }; |
|---|
| 614 | |
|---|
| 615 | // ------------------------------- |
|---|
| 616 | // hash index calculation |
|---|
| 617 | // ------------------------------- |
|---|
| 618 | |
|---|
| 619 | #define GB_CALC_HASH_INDEX_CASE_SENSITIVE(string,index,size) do { \ |
|---|
| 620 | const char *local_ptr = (string); \ |
|---|
| 621 | int local_i; \ |
|---|
| 622 | (index) = 0xffffffffL; \ |
|---|
| 623 | while ((local_i=(*(local_ptr++)))) { \ |
|---|
| 624 | (index) = crctab[((int)(index)^local_i) & 0xff] ^ ((index) >> 8); \ |
|---|
| 625 | } \ |
|---|
| 626 | (index) = (index) % (size); \ |
|---|
| 627 | } while(0) |
|---|
| 628 | |
|---|
| 629 | #define GB_CALC_HASH_INDEX_CASE_IGNORED(string,index,size) do { \ |
|---|
| 630 | const char *local_ptr = (string); \ |
|---|
| 631 | int local_i; \ |
|---|
| 632 | (index) = 0xffffffffL; \ |
|---|
| 633 | while ( (local_i = *(local_ptr++))){ \ |
|---|
| 634 | (index) = crctab[((int) (index) ^ toupper(local_i)) & 0xff] ^ ((index) >> 8); \ |
|---|
| 635 | } \ |
|---|
| 636 | (index) = (index) % (size); \ |
|---|
| 637 | } while(0) |
|---|
| 638 | |
|---|
| 639 | #define GB_CALC_HASH_INDEX(string, index, size, caseSens) do { \ |
|---|
| 640 | if ((caseSens) == GB_IGNORE_CASE) \ |
|---|
| 641 | GB_CALC_HASH_INDEX_CASE_IGNORED(string, index, size); \ |
|---|
| 642 | else \ |
|---|
| 643 | GB_CALC_HASH_INDEX_CASE_SENSITIVE(string, index, size); \ |
|---|
| 644 | } while(0) |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | #endif |
|---|