"Fossies" - the Fresh Open Source Software Archive

Member "rgdbm-2.1.42/rgdbm.h" (21 Jun 2007, 6132 Bytes) of package /linux/privat/old/rgdbm-2.1.42.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "rgdbm.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef RGDBM3_H
    2 #define RGDBM3_H 1
    3 
    4 /* protocol number .. ^2.1^.30 */
    5 #define __RGDBM_VERSION "2.1"
    6 #define __RGDBM_VERSION_MAJOR 2001000
    7 #define __RGDBM_VERSION_MINOR 34
    8 
    9 #if defined(HAVE_GDBM_H) ||defined(_GDBM_H)
   10 # define RGDBM_FILE GDBM_FILE
   11 # define rgdbm_error gdbm_error
   12 #else
   13 
   14 /*
   15  * our own prototypes use GDBM_FILE, so we need to define it on the
   16  * rare occasions when gdbm.h is not present. We might as well make a
   17  * best effort to compile even then!
   18  *
   19  * rgdbm_strerr magnificently uses gdbm_error in its prototype in order
   20  * to be a dropin replacement for gdbm_error, so we have to do the
   21  * typedef of that too, if we are really trung to compile without
   22  * gdb.h.
   23  */
   24 typedef struct { char dummy[10]; } *RGDBM_FILE;
   25 typedef int rgdbm_error;
   26 
   27 #endif
   28 
   29 #ifdef HAVE_GDBM_H
   30 
   31 /*
   32  * Define our own open flags so that we're not wholly depenedent on gdbm.h.
   33  * Of course, they're the same value! So this is vanity.
   34  */
   35 # define  RGDBM_READER  GDBM_READER   /* A reader. */
   36 # define  RGDBM_WRITER  GDBM_WRITER   /* A writer. */
   37 # define  RGDBM_WRCREAT GDBM_WRCREAT  /* A writer.  Create the db if needed. */
   38 # define  RGDBM_NEWDB   GDBM_NEWDB    /* A writer.  Always create a new db. */
   39 # define  RGDBM_FAST    GDBM_FAST     /* Write fast! => No fsyncs.  OBSOLETE. */
   40 /* RGDBM_SYNC is presently defined in an enum */
   41 # define  RGDBM_NOLOCK  GDBM_NOLOCK   /* Don't do file locking operations. */
   42 
   43 /* Parameters to gdbm_setopt, specifing the type of operation to
   44  * perform. */
   45 #define  RGDBM_CACHESIZE GDBM_CACHESIZE       /* Set the cache size. */
   46 #define  RGDBM_FASTMODE  GDBM_FASTMODE        /* Toggle fast mode.  OBSOLETE. */
   47 #define  RGDBM_SYNCMODE  GDBM_SYNCMODE        /* Turn on or off sync operations. */
   48 #define  RGDBM_CENTFREE  GDBM_CENTFREE        /* Keep all free blocks in the header. */
   49 #define  RGDBM_COALESCEBLKS GDBM_COALESCEBLKS /* Attempt to coalesce free blocks. */
   50 #define  RGDBM_RDONLY    15
   51 
   52 #else
   53 
   54 /* flags for rgdbm_open - FIXME, need to use own values */
   55 # define  RGDBM_READER  0         /* A reader. */
   56 # define  RGDBM_WRITER  1         /* A writer. */
   57 # define  RGDBM_WRCREAT 2         /* A writer.  Create the db if needed. */
   58 # define  RGDBM_NEWDB   3         /* A writer.  Always create a new db. */
   59 # define  RGDBM_FAST    0x10      /* Write fast! => No fsyncs.  OBSOLETE. */
   60 /* RGDBM_SYNC is presently defined in an enum */
   61 # define  RGDBM_NOLOCK  0x40      /* Don't do file locking operations. */
   62 
   63 /* Parameters to gdbm_setopt, specifing the type of operation to
   64  * perform. */
   65 #define  RGDBM_CACHESIZE 1       /* Set the cache size. */
   66 #define  RGDBM_FASTMODE  2       /* Toggle fast mode.  OBSOLETE. */
   67 #define  RGDBM_SYNCMODE  3       /* Turn on or off sync operations. */
   68 #define  RGDBM_CENTFREE  4       /* Keep all free blocks in the header. */
   69 #define  RGDBM_COALESCEBLKS 5    /* Attempt to coalesce free blocks. */
   70 #define  RGDBM_RDONLY    15
   71 
   72 #endif /* HAVE_GDBM_H */
   73 
   74 
   75 /*
   76  * command types
   77  */
   78 enum {
   79 /* gdbm (also ndbm and dbm) */
   80     RGDBM_INSERT 
   81 #ifdef HAVE_GDBM_H
   82       = GDBM_INSERT,
   83 #else
   84       = 0, /* = GDBM_INSERT */
   85 #endif
   86     RGDBM_REPLACE
   87 #ifdef HAVE_GDBM_H
   88        = GDBM_REPLACE,
   89 #else
   90        = 1, /* = GDBM_REPLACE */
   91 #endif
   92     RGDBM_OPEN,
   93     RGDBM_CLOSE,
   94     RGDBM_FETCH,
   95     RGDBM_EXISTS,
   96     RGDBM_DELETE,
   97     RGDBM_FIRSTKEY,
   98     RGDBM_NEXTKEY,
   99     RGDBM_REORGANIZE,
  100     RGDBM_SETOPT,
  101     RGDBM_FDESC,
  102     RGDBM_BEGIN,
  103     RGDBM_COMMIT,
  104     RGDBM_ROLLBACK,
  105 
  106     RGDBM_CONNECT,
  107 
  108     RGDBM_SYNC
  109 #ifdef HAVE_GDBM_H
  110        = GDBM_SYNC,
  111 #else
  112        = 0x20, /* = GDBM_SYNC */
  113 #endif
  114     RGDBM_VERSION,
  115     RGDBM_ERRNO,
  116     RGDBM_STRERROR,
  117 
  118     RGDBM_DISCONNECT,
  119     RGDBM_HANDSHAKE,
  120 
  121 };
  122 
  123 /*
  124  * up to 4 transport protocols, currently TCP and SSL only
  125  */
  126 enum {
  127     RGDBM_CRYPTO_NONE        = 0x1,
  128     RGDBM_CRYPTO_TCP         = RGDBM_CRYPTO_NONE,
  129     RGDBM_CRYPTO_SSL         = 0x2,
  130     RGDBM_CRYPTO_SSL_OR_NONE = RGDBM_CRYPTO_NONE|RGDBM_CRYPTO_SSL,
  131     RGDBM_CRYPTO_ANY         = RGDBM_CRYPTO_SSL_OR_NONE,
  132 };
  133 
  134 
  135 
  136 struct rgdbm_datum {
  137    int size;
  138    char data[0];
  139 } __attribute__((packed));
  140 
  141 struct rgdbm_request {
  142    int64_t magic;
  143    int32_t  type;
  144    int32_t tableno;
  145    int32_t flags;
  146    int32_t  seqno;
  147    int32_t  count; // following data count. Number of datum elements
  148    struct rgdbm_datum data[0];
  149 } __attribute__((packed));
  150 
  151 struct rgdbm_reply {
  152    int64_t magic;
  153    int32_t  type;
  154    int32_t  result;
  155    int32_t  seqno;
  156    int32_t  count; // following data count. Number of datum elements
  157    struct rgdbm_datum data[0];
  158 } __attribute__((packed));
  159 
  160 struct rgdbm_file_s {
  161     int fd; 
  162 };
  163 
  164 RGDBM_FILE rgdbm_open (char *name, int block_size, int rw, int mode,
  165                                                         void (*fatal_func)());
  166 void rgdbm_close   (RGDBM_FILE dbf3);
  167 
  168 int rgdbm_store    (RGDBM_FILE dbf, datum key, datum content, int flag);
  169 datum rgdbm_fetch  (RGDBM_FILE dbf, datum key);
  170 int rgdbm_delete   (RGDBM_FILE dbf, datum key);
  171 int rgdbm_exists   (RGDBM_FILE dbf, datum key);
  172 
  173 int rgdbm_begin    (RGDBM_FILE dbf);
  174 int rgdbm_commit   (RGDBM_FILE dbf);
  175 int rgdbm_rollback (RGDBM_FILE dbf);
  176 
  177 datum rgdbm_firstkey (RGDBM_FILE dbf);
  178 datum rgdbm_nextkey  (RGDBM_FILE dbf, datum key);
  179 
  180 int rgdbm_reorganize (RGDBM_FILE dbf);
  181 void rgdbm_sync      (RGDBM_FILE dbf);
  182 int rgdbm_setopt     (RGDBM_FILE dbf, int option, int *value, int size);
  183 int rgdbm_fdesc      (RGDBM_FILE dbf);
  184 
  185 
  186 int rgdbm_connect    (char *hostname, char *dbname, char *user, unsigned long flags);
  187 void rgdbm_disconnect(void);
  188 
  189 
  190 char *rgdbm_strerror  (rgdbm_error);
  191 rgdbm_error rgdbm_errno(void);
  192 char * rgdbm_version  (void);
  193 
  194 #if defined(_ARPA_INET_H) || defined(_NETINET_IN_H)
  195 # ifndef htonll
  196 #  ifdef WORDS_BIGENDIAN
  197 static inline uint64_t
  198 ntohll (uint64_t a)
  199 {
  200     return a;
  201 }
  202 #  else /* if !defined (WORDS_BIGENDIAN) */
  203 static inline uint64_t
  204 ntohll (uint64_t a)
  205 {
  206     /* probably faster in assembler, with some rot instruction  */
  207     uint32_t lo = a & 0xffffffff;
  208     uint32_t hi = a >> 32U;
  209 
  210     lo = ntohl (lo);
  211     hi = ntohl (hi);
  212     return ((uint64_t) lo) << 32U | hi;
  213 }
  214 #  endif /* WORDS_BIGENDIAN */
  215 #  define htonll ntohll
  216 # endif
  217 #endif
  218 
  219 #endif /* RGDBM3_H */
  220