Diff for /src/usr.sbin/ypserv/yp_dblookup.c between versions 1.2 and 1.3

version 1.2, 2003/06/17 04:30:04 version 1.3, 2004/03/31 23:20:22
Line 30 Line 30
  * SUCH DAMAGE.   * SUCH DAMAGE.
  *   *
  * $FreeBSD: src/usr.sbin/ypserv/yp_dblookup.c,v 1.17.2.1 2002/02/15 00:47:00 des Exp $   * $FreeBSD: src/usr.sbin/ypserv/yp_dblookup.c,v 1.17.2.1 2002/02/15 00:47:00 des Exp $
 * $DragonFly: src/usr.sbin/ypserv/yp_dblookup.c,v 1.1 2003/06/16 07:40:03 dillon Exp $ * $DragonFly$
  */   */
   
 #include <db.h>  #include <db.h>
Line 87  struct circleq_entry { Line 87  struct circleq_entry {
 /*  /*
  * Initialize the circular queue.   * Initialize the circular queue.
  */   */
void yp_init_dbs()void
 yp_init_dbs(void)
 {  {
         CIRCLEQ_INIT(&qhead);          CIRCLEQ_INIT(&qhead);
         return;  
 }  }
   
 /*  /*
  * Dynamically allocate an entry for the circular queue.   * Dynamically allocate an entry for the circular queue.
  * Return a NULL pointer on failure.   * Return a NULL pointer on failure.
  */   */
static struct circleq_entry *yp_malloc_qent()static struct circleq_entry *
 yp_malloc_qent(void)
 {  {
        register struct circleq_entry *q;        struct circleq_entry *q;
   
         q = (struct circleq_entry *)malloc(sizeof(struct circleq_entry));          q = (struct circleq_entry *)malloc(sizeof(struct circleq_entry));
         if (q == NULL) {          if (q == NULL) {
Line 122  static struct circleq_entry *yp_malloc_q Line 123  static struct circleq_entry *yp_malloc_q
  * Free a previously allocated circular queue   * Free a previously allocated circular queue
  * entry.   * entry.
  */   */
static void yp_free_qent(q)static void
        struct circleq_entry *q;yp_free_qent(struct circleq_entry *q)
 {  {
         /*          /*
          * First, close the database. In theory, this is also           * First, close the database. In theory, this is also
Line 151  static void yp_free_qent(q) Line 152  static void yp_free_qent(q)
          */           */
         free(q);          free(q);
         q = NULL;          q = NULL;
   
         return;  
 }  }
   
 /*  /*
Line 160  static void yp_free_qent(q) Line 159  static void yp_free_qent(q)
  * all its resources. (This always removes the last entry   * all its resources. (This always removes the last entry
  * in the queue.)   * in the queue.)
  */   */
static void yp_flush()static void
 yp_flush(void)
 {  {
        register struct circleq_entry *qptr;        struct circleq_entry *qptr;
   
         qptr = qhead.cqh_last;          qptr = qhead.cqh_last;
         CIRCLEQ_REMOVE(&qhead, qptr, links);          CIRCLEQ_REMOVE(&qhead, qptr, links);
         yp_free_qent(qptr);          yp_free_qent(qptr);
         numdbs--;          numdbs--;
   
         return;  
 }  }
   
 /*  /*
  * Close all databases, erase all database names and empty the queue.   * Close all databases, erase all database names and empty the queue.
  */   */
void yp_flush_all()void
 yp_flush_all(void)
 {  {
        register struct circleq_entry *qptr;        struct circleq_entry *qptr;
   
         while (qhead.cqh_first != (void *)&qhead) {          while (qhead.cqh_first != (void *)&qhead) {
                 qptr = qhead.cqh_first; /* save this */                  qptr = qhead.cqh_first; /* save this */
Line 185  void yp_flush_all() Line 184  void yp_flush_all()
                 yp_free_qent(qptr);                  yp_free_qent(qptr);
         }          }
         numdbs = 0;          numdbs = 0;
   
         return;  
 }  }
   
 static char *inter_string = "YP_INTERDOMAIN";  static char *inter_string = "YP_INTERDOMAIN";
Line 194  static char *secure_string = "YP_SECURE" Line 191  static char *secure_string = "YP_SECURE"
 static int inter_sz = sizeof("YP_INTERDOMAIN") - 1;  static int inter_sz = sizeof("YP_INTERDOMAIN") - 1;
 static int secure_sz = sizeof("YP_SECURE") - 1;  static int secure_sz = sizeof("YP_SECURE") - 1;
   
static int yp_setflags(dbp)static int
        DB *dbp;yp_setflags(DB *dbp)
 {  {
         DBT key = { NULL, 0 }, data = { NULL, 0 };          DBT key = { NULL, 0 }, data = { NULL, 0 };
         int flags = 0;          int flags = 0;
Line 215  static int yp_setflags(dbp) Line 212  static int yp_setflags(dbp)
         return(flags);          return(flags);
 }  }
   
int yp_testflag(map, domain, flag)int
        char *map;yp_testflag(char *map, char *domain, int flag)
        char *domain; 
        int flag; 
 {  {
         char buf[MAXPATHLEN + 2];          char buf[MAXPATHLEN + 2];
        register struct circleq_entry *qptr;        struct circleq_entry *qptr;
   
         if (map == NULL || domain == NULL)          if (map == NULL || domain == NULL)
                 return(0);                  return(0);
Line 255  int yp_testflag(map, domain, flag) Line 250  int yp_testflag(map, domain, flag)
  * a new entry when all our slots are already filled, we have to kick   * a new entry when all our slots are already filled, we have to kick
  * out the entry in the last slot to make room.   * out the entry in the last slot to make room.
  */   */
static int yp_cache_db(dbp, name, size)static int
        DB *dbp;yp_cache_db(DB *dbp, char *name, int size)
        char *name; 
        int size; 
 {  {
        register struct circleq_entry *qptr;        struct circleq_entry *qptr;
   
         if (numdbs == MAXDBS) {          if (numdbs == MAXDBS) {
                 if (ypdb_debug)                  if (ypdb_debug)
Line 316  static int yp_cache_db(dbp, name, size) Line 309  static int yp_cache_db(dbp, name, size)
  *   so that it will be easier to find if another request for   *   so that it will be easier to find if another request for
  *   the same database comes in later.   *   the same database comes in later.
  */   */
static DB *yp_find_db(name, key, size)static DB *
        char *name;yp_find_db(const char *name, const char *key, const int size)
        char *key; 
        int size; 
 {  {
        register struct circleq_entry *qptr;        struct circleq_entry *qptr;
   
         for (qptr = qhead.cqh_first; qptr != (void *)&qhead;          for (qptr = qhead.cqh_first; qptr != (void *)&qhead;
                                                 qptr = qptr->links.cqe_next) {                                                  qptr = qptr->links.cqe_next) {
Line 351  static DB *yp_find_db(name, key, size) Line 342  static DB *yp_find_db(name, key, size)
  * If so, we fetch the handle from the cache. If not, we try to open   * If so, we fetch the handle from the cache. If not, we try to open
  * the database and save the handle in the cache for later use.   * the database and save the handle in the cache for later use.
  */   */
DB *yp_open_db_cache(domain, map, key, size)DB *
        const char *domain;yp_open_db_cache(const char *domain, const char *map, const char *key,
        const char *map;                 const int size)
        const char *key; 
        const int size; 
 {  {
         DB *dbp = NULL;          DB *dbp = NULL;
         char buf[MAXPATHLEN + 2];          char buf[MAXPATHLEN + 2];
Line 387  DB *yp_open_db_cache(domain, map, key, s Line 376  DB *yp_open_db_cache(domain, map, key, s
 /*  /*
  * Open a DB database.   * Open a DB database.
  */   */
DB *yp_open_db(domain, map)DB *
        const char *domain;yp_open_db(const char *domain, const char *map)
        const char *map; 
 {  {
         DB *dbp = NULL;          DB *dbp = NULL;
         char buf[MAXPATHLEN + 2];          char buf[MAXPATHLEN + 2];
Line 455  again: Line 443  again:
  */   */
   
 #ifdef DB_CACHE  #ifdef DB_CACHE
int yp_get_record(dbp,key,data,allow)int
        DB *dbp;yp_get_record(DB *dbp, const DBT *key, DBT *data, int allow)
 #else  #else
int yp_get_record(domain,map,key,data,allow)int
        const char *domain;yp_get_record(const char *domain, const char *map, const DBT *key,
        const char *map;              DBT *data, int allow)
#endif#endif
        const DBT *key; 
        DBT *data; 
        int allow; 
 {  {
 #ifndef DB_CACHE  #ifndef DB_CACHE
         DB *dbp;          DB *dbp;
Line 522  int yp_get_record(domain,map,key,data,al Line 507  int yp_get_record(domain,map,key,data,al
         return(YP_TRUE);          return(YP_TRUE);
 }  }
   
int yp_first_record(dbp,key,data,allow)int
        const DB *dbp;yp_first_record(const DB *dbp, DBT *key, DBT *data, int allow)
        DBT *key; 
        DBT *data; 
        int allow; 
 {  {
         int rval;          int rval;
 #ifndef DB_CACHE  #ifndef DB_CACHE
Line 576  int yp_first_record(dbp,key,data,allow) Line 558  int yp_first_record(dbp,key,data,allow)
         return(YP_TRUE);          return(YP_TRUE);
 }  }
   
int yp_next_record(dbp,key,data,all,allow)int
        const DB *dbp;yp_next_record(const DB *dbp, DBT *key, DBT *data, int all, int allow)
        DBT *key; 
        DBT *data; 
        int all; 
        int allow; 
 {  {
         static DBT lkey = { NULL, 0 };          static DBT lkey = { NULL, 0 };
         static DBT ldata = { NULL, 0 };          static DBT ldata = { NULL, 0 };
Line 672  int yp_next_record(dbp,key,data,all,allo Line 650  int yp_next_record(dbp,key,data,all,allo
 static DB *yp_currmap_db = NULL;  static DB *yp_currmap_db = NULL;
 static int yp_allow_db = 0;  static int yp_allow_db = 0;
   
ypstat yp_select_map(map, domain, key, allow)ypstat
        char *map;yp_select_map(char *map, char *domain, keydat *key, int allow)
        char *domain; 
        keydat *key; 
        int allow; 
 {  {
         if (key == NULL)          if (key == NULL)
                 yp_currmap_db = yp_open_db_cache(domain, map, NULL, 0);                  yp_currmap_db = yp_open_db_cache(domain, map, NULL, 0);
Line 689  ypstat yp_select_map(map, domain, key, a Line 664  ypstat yp_select_map(map, domain, key, a
         return(yp_errno);          return(yp_errno);
 }  }
   
ypstat yp_getbykey(key, val)ypstat
        keydat *key;yp_getbykey(keydat *key, valdat *val)
        valdat *val; 
 {  {
         DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };          DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };
         ypstat rval;          ypstat rval;
Line 710  ypstat yp_getbykey(key, val) Line 684  ypstat yp_getbykey(key, val)
         return(rval);          return(rval);
 }  }
   
ypstat yp_firstbykey(key, val)ypstat
        keydat *key;yp_firstbykey(keydat *key, valdat *val)
        valdat *val; 
 {  {
         DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };          DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };
         ypstat rval;          ypstat rval;
Line 729  ypstat yp_firstbykey(key, val) Line 702  ypstat yp_firstbykey(key, val)
         return(rval);          return(rval);
 }  }
   
ypstat yp_nextbykey(key, val)ypstat
        keydat *key;yp_nextbykey(keydat *key, valdat *val)
        valdat *val; 
 {  {
         DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };          DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };
         ypstat rval;          ypstat rval;

Removed from v.1.2  
changed lines
  Added in v.1.3