Convert buserver to libutil's logging
[openafs.git] / src / budb / struct_ops.c
index 0377f3b..fbaf14a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -9,27 +9,20 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
-
-RCSID
-    ("$Header$");
-
-#include <stdio.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#include <sys/file.h>
-#endif
-#include <sys/types.h>
 #include <afs/stds.h>
+
+#include <roken.h>
+
 #include <afs/bubasics.h>
+#include <afs/afsutil.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
-#include <string.h>
+
 #include "budb.h"
 #include "budb_errs.h"
 #include "database.h"
-
+#include "budb_internal.h"
+#include "budb_prototypes.h"
 
 /* ----------------------------------
  * structure printing utilities
@@ -68,7 +61,7 @@ printDump(FILE *fid, struct dump *dptr)
 
 }
 
-void 
+void
 printDumpEntry(struct budb_dumpEntry *deptr)
 {
     time_t created = deptr->created;
@@ -103,31 +96,11 @@ printDumpEntry(struct budb_dumpEntry *deptr)
     printPrincipal(&deptr->dumper);
 }
 
-/* printHashTable
- *     print the hash table structure, i.e. the header structure.
- */
-
-printHashTable(fid, htptr)
-     FILE *fid;
-     struct hashTable *htptr;
-{
-    fprintf(fid, "functionType = %d\n", htptr->functionType);
-    fprintf(fid, "threadOffset = %d\n", htptr->threadOffset);
-    fprintf(fid, "entries = %d\n", htptr->entries);
-    fprintf(fid, "length = %d\n", htptr->length);
-    fprintf(fid, "table = %d\n", htptr->table);
-    fprintf(fid, "progress = %d\n", htptr->progress);
-    fprintf(fid, "oldLength = %d\n", htptr->oldLength);
-    fprintf(fid, "oldTable = %d\n", htptr->oldTable);
-}
-
 /* printMemoryHashTable
  *     print the hash table structure, i.e. the header structure.
  */
 int
-printMemoryHashTable(fid, mhtptr)
-     FILE *fid;
-     struct memoryHashTable *mhtptr;
+printMemoryHashTable(FILE *fid, struct memoryHashTable *mhtptr)
 {
     fprintf(fid, "threadOffset = %d\n", mhtptr->threadOffset);
     fprintf(fid, "length = %d\n", mhtptr->length);
@@ -138,8 +111,7 @@ printMemoryHashTable(fid, mhtptr)
 }
 
 int
-printPrincipal(ptr)
-     struct ktc_principal *ptr;
+printPrincipal(struct budb_principal *ptr)
 {
     printf("name = %s\n", ptr->name);
     printf("instance = %s\n", ptr->instance);
@@ -148,8 +120,7 @@ printPrincipal(ptr)
 }
 
 int
-printStructDumpHeader(ptr)
-     struct structDumpHeader *ptr;
+printStructDumpHeader(struct structDumpHeader *ptr)
 {
     printf("type = %d\n", ptr->type);
     printf("structure version = %d\n", ptr->structversion);
@@ -214,9 +185,8 @@ printTapeEntry(struct budb_tapeEntry *teptr)
 }
 
 int
-printTapeSet(tsptr, nss)
-     struct budb_tapeSet *tsptr;
-     afs_int32 nss;            /* is the tapeserver name an accurate name */
+printTapeSet(struct budb_tapeSet *tsptr,
+            afs_int32 nss)     /* is the tapeserver name an accurate name */
 {
     printf("Group id  = %d\n", tsptr->id);
     printf("tapeServer = %s%s\n", tsptr->tapeServer,
@@ -284,9 +254,7 @@ printVolFragment(FILE *fid, struct volFragment *vfptr)
 }
 
 int
-printVolInfo(fid, viptr)
-     FILE *fid;
-     struct volInfo *viptr;
+printVolInfo(FILE *fid, struct volInfo *viptr)
 {
     fprintf(fid, "name = %s\n", viptr->name);
     fprintf(fid, "nameHashChain = %d\n", viptr->nameHashChain);
@@ -304,15 +272,16 @@ printVolInfo(fid, viptr)
 
 /* -----------------------------------------
  * structure xdr routines
- * ----------------------------------------- 
+ * -----------------------------------------
  */
 
 /* utilities - network to host conversion
  *     currently used for debug only
  */
 
-volFragment_ntoh(netVfPtr, hostVfPtr)
-     struct volFragment *netVfPtr, *hostVfPtr;
+void
+volFragment_ntoh(struct volFragment *netVfPtr,
+                struct volFragment *hostVfPtr)
 {
     hostVfPtr->vol = ntohl(netVfPtr->vol);
     hostVfPtr->sameNameChain = ntohl(netVfPtr->sameNameChain);
@@ -327,8 +296,9 @@ volFragment_ntoh(netVfPtr, hostVfPtr)
     hostVfPtr->sequence = ntohs(netVfPtr->sequence);
 }
 
-volInfo_ntoh(netViPtr, hostViPtr)
-     struct volInfo *netViPtr, *hostViPtr;
+void
+volInfo_ntoh(struct volInfo *netViPtr,
+            struct volInfo *hostViPtr)
 {
     strcpy(hostViPtr->name, netViPtr->name);
     hostViPtr->nameHashChain = ntohl(netViPtr->nameHashChain);
@@ -342,8 +312,9 @@ volInfo_ntoh(netViPtr, hostViPtr)
     hostViPtr->nFrags = ntohl(netViPtr->nFrags);
 }
 
-tape_ntoh(netTapePtr, hostTapePtr)
-     struct tape *netTapePtr, *hostTapePtr;
+void
+tape_ntoh(struct tape *netTapePtr,
+         struct tape *hostTapePtr)
 {
     strcpy(hostTapePtr->name, netTapePtr->name);
     hostTapePtr->nameHashChain = ntohl(netTapePtr->nameHashChain);
@@ -363,14 +334,18 @@ tape_ntoh(netTapePtr, hostTapePtr)
     hostTapePtr->useCount = ntohl(netTapePtr->useCount);
 }
 
-dump_ntoh(netDumpPtr, hostDumpPtr)
-     struct dump *netDumpPtr, *hostDumpPtr;
+void
+dump_ntoh(struct dump *netDumpPtr,
+         struct dump *hostDumpPtr)
 {
     hostDumpPtr->id = ntohl(netDumpPtr->id);
     hostDumpPtr->idHashChain = ntohl(netDumpPtr->idHashChain);
-    strcpy(hostDumpPtr->dumpName, netDumpPtr->dumpName);
-    strcpy(hostDumpPtr->dumpPath, netDumpPtr->dumpPath);
-    strcpy(hostDumpPtr->volumeSet, netDumpPtr->volumeSet);
+    strlcpy(hostDumpPtr->dumpName, netDumpPtr->dumpName,
+           sizeof(hostDumpPtr->dumpName));
+    strlcpy(hostDumpPtr->dumpPath, netDumpPtr->dumpPath,
+           sizeof(hostDumpPtr->dumpPath));
+    strlcpy(hostDumpPtr->volumeSet, netDumpPtr->volumeSet,
+           sizeof(hostDumpPtr->volumeSet));
     hostDumpPtr->nameHashChain = ntohl(netDumpPtr->nameHashChain);
     hostDumpPtr->flags = ntohl(netDumpPtr->flags);
     hostDumpPtr->parent = ntohl(netDumpPtr->parent);
@@ -382,11 +357,12 @@ dump_ntoh(netDumpPtr, hostDumpPtr)
 
     hostDumpPtr->firstTape = ntohl(netDumpPtr->firstTape);
 
-    principal_ntoh(&netDumpPtr->dumper, &hostDumpPtr->dumper);
+    hostDumpPtr->dumper = netDumpPtr->dumper;
 }
 
-DbHeader_ntoh(netptr, hostptr)
-     struct DbHeader *netptr, *hostptr;
+void
+DbHeader_ntoh(struct DbHeader *netptr,
+             struct DbHeader *hostptr)
 {
     hostptr->dbversion = ntohl(netptr->dbversion);
     hostptr->created = ntohl(netptr->created);
@@ -396,8 +372,9 @@ DbHeader_ntoh(netptr, hostptr)
     hostptr->lastTapeId = ntohl(netptr->lastTapeId);
 }
 
-dumpEntry_ntoh(netptr, hostptr)
-     struct budb_dumpEntry *netptr, *hostptr;
+void
+dumpEntry_ntoh(struct budb_dumpEntry *netptr,
+              struct budb_dumpEntry *hostptr)
 {
     hostptr->id = ntohl(netptr->id);
     hostptr->initialDumpID = ntohl(netptr->initialDumpID);
@@ -416,42 +393,45 @@ dumpEntry_ntoh(netptr, hostptr)
     principal_ntoh(&netptr->dumper, &hostptr->dumper);
 }
 
-principal_hton(hostptr, netptr)
-     struct ktc_principal *hostptr, *netptr;
+void
+principal_hton(struct budb_principal *hostptr,
+              struct budb_principal *netptr)
 {
     strcpy(netptr->name, hostptr->name);
     strcpy(netptr->instance, hostptr->instance);
     strcpy(netptr->cell, hostptr->cell);
-    return 0;
 }
 
-principal_ntoh(netptr, hostptr)
-     struct ktc_principal *netptr, *hostptr;
+void
+principal_ntoh(struct budb_principal *netptr,
+              struct budb_principal *hostptr)
 {
     strcpy(hostptr->name, netptr->name);
     strcpy(hostptr->instance, netptr->instance);
     strcpy(hostptr->cell, netptr->cell);
-    return 0;
 }
 
-structDumpHeader_hton(hostPtr, netPtr)
-     struct structDumpHeader *hostPtr, *netPtr;
+void
+structDumpHeader_hton(struct structDumpHeader *hostPtr,
+                     struct structDumpHeader *netPtr)
 {
     netPtr->type = htonl(hostPtr->type);
     netPtr->structversion = htonl(hostPtr->structversion);
     netPtr->size = htonl(hostPtr->size);
 }
 
-structDumpHeader_ntoh(netPtr, hostPtr)
-     struct structDumpHeader *hostPtr, *netPtr;
+void
+structDumpHeader_ntoh(struct structDumpHeader *netPtr,
+                     struct structDumpHeader *hostPtr)
 {
     hostPtr->type = ntohl(netPtr->type);
     hostPtr->structversion = ntohl(netPtr->structversion);
     hostPtr->size = ntohl(netPtr->size);
 }
 
-tapeEntry_ntoh(netptr, hostptr)
-     struct budb_tapeEntry *netptr, *hostptr;
+void
+tapeEntry_ntoh(struct budb_tapeEntry *netptr,
+              struct budb_tapeEntry *hostptr)
 {
     strcpy(hostptr->name, netptr->name);
     hostptr->flags = ntohl(netptr->flags);
@@ -469,8 +449,8 @@ tapeEntry_ntoh(netptr, hostptr)
 }
 
 int
-tapeSet_hton(hostptr, netptr)
-     struct budb_tapeSet *hostptr, *netptr;
+tapeSet_hton(struct budb_tapeSet *hostptr,
+            struct budb_tapeSet *netptr)
 {
     netptr->id = htonl(hostptr->id);
     strcpy(netptr->tapeServer, hostptr->tapeServer);
@@ -482,8 +462,8 @@ tapeSet_hton(hostptr, netptr)
 }
 
 int
-tapeSet_ntoh(netptr, hostptr)
-     struct budb_tapeSet *netptr, *hostptr;
+tapeSet_ntoh(struct budb_tapeSet *netptr,
+            struct budb_tapeSet *hostptr)
 {
     hostptr->id = ntohl(netptr->id);
     strcpy(hostptr->tapeServer, netptr->tapeServer);
@@ -494,8 +474,9 @@ tapeSet_ntoh(netptr, hostptr)
     return 0;
 }
 
-textBlock_hton(hostptr, netptr)
-     struct textBlock *hostptr, *netptr;
+void
+textBlock_hton(struct textBlock *hostptr,
+              struct textBlock *netptr)
 {
     netptr->version = htonl(hostptr->version);
     netptr->size = htonl(hostptr->size);
@@ -504,8 +485,9 @@ textBlock_hton(hostptr, netptr)
     netptr->newTextAddr = htonl(hostptr->newTextAddr);
 }
 
-textBlock_ntoh(netptr, hostptr)
-     struct textBlock *netptr, *hostptr;
+void
+textBlock_ntoh(struct textBlock *netptr,
+              struct textBlock *hostptr)
 {
     hostptr->version = ntohl(netptr->version);
     hostptr->size = ntohl(netptr->size);
@@ -514,8 +496,8 @@ textBlock_ntoh(netptr, hostptr)
     hostptr->newTextAddr = ntohl(netptr->newTextAddr);
 }
 
-textLock_hton(hostptr, netptr)
-     db_lockP hostptr, netptr;
+void
+textLock_hton(db_lockP hostptr, db_lockP netptr)
 {
     netptr->type = htonl(hostptr->type);
     netptr->lockState = htonl(hostptr->lockState);
@@ -525,8 +507,8 @@ textLock_hton(hostptr, netptr)
     netptr->lockHost = htonl(hostptr->lockHost);
 }
 
-textLock_ntoh(netptr, hostptr)
-     db_lockP netptr, hostptr;
+void
+textLock_ntoh(db_lockP netptr, db_lockP hostptr)
 {
     hostptr->type = ntohl(netptr->type);
     hostptr->lockState = ntohl(netptr->lockState);
@@ -536,8 +518,9 @@ textLock_ntoh(netptr, hostptr)
     hostptr->lockHost = ntohl(netptr->lockHost);
 }
 
-volumeEntry_ntoh(netptr, hostptr)
-     struct budb_volumeEntry *netptr, *hostptr;
+void
+volumeEntry_ntoh(struct budb_volumeEntry *netptr,
+                struct budb_volumeEntry *hostptr)
 {
     strcpy(hostptr->name, netptr->name);
     hostptr->flags = ntohl(netptr->flags);
@@ -558,14 +541,13 @@ volumeEntry_ntoh(netptr, hostptr)
 }
 
 /* -------------------------------------
- * structure conversion & copy routines 
+ * structure conversion & copy routines
  * -------------------------------------
  */
 
-
-copy_ktcPrincipal_to_budbPrincipal(ktcPtr, budbPtr)
-     struct ktc_principal *ktcPtr;
-     struct budb_principal *budbPtr;
+void
+copy_ktcPrincipal_to_budbPrincipal(struct ktc_principal *ktcPtr,
+                                  struct budb_principal *budbPtr)
 {
     strncpy(budbPtr->name, ktcPtr->name, sizeof(budbPtr->name));
     strncpy(budbPtr->instance, ktcPtr->instance, sizeof(budbPtr->instance));
@@ -577,9 +559,8 @@ copy_ktcPrincipal_to_budbPrincipal(ktcPtr, budbPtr)
  *     dumpPtr - host format
  */
 
-dumpToBudbDump(dumpPtr, budbDumpPtr)
-     dbDumpP dumpPtr;
-     struct budb_dumpEntry *budbDumpPtr;
+int
+dumpToBudbDump(dbDumpP dumpPtr, struct budb_dumpEntry *budbDumpPtr)
 {
     budbDumpPtr->id = dumpPtr->id;
     budbDumpPtr->initialDumpID = dumpPtr->initialDumpID;
@@ -600,9 +581,8 @@ dumpToBudbDump(dumpPtr, budbDumpPtr)
     return (0);
 }
 
-tapeToBudbTape(tapePtr, budbTapePtr)
-     struct tape *tapePtr;
-     struct budb_tapeEntry *budbTapePtr;
+int
+tapeToBudbTape(struct tape *tapePtr, struct budb_tapeEntry *budbTapePtr)
 {
     strcpy(budbTapePtr->name, tapePtr->name);
     budbTapePtr->flags = tapePtr->flags;
@@ -619,10 +599,9 @@ tapeToBudbTape(tapePtr, budbTapePtr)
     return (0);
 }
 
-volsToBudbVol(volFragPtr, volInfoPtr, budbVolPtr)
-     struct volFragment *volFragPtr;
-     struct volInfo *volInfoPtr;
-     struct budb_volumeEntry *budbVolPtr;
+int
+volsToBudbVol(struct volFragment *volFragPtr, struct volInfo *volInfoPtr,
+             struct budb_volumeEntry *budbVolPtr)
 {
     strcpy(budbVolPtr->name, volInfoPtr->name);
     budbVolPtr->flags = volInfoPtr->flags;
@@ -641,7 +620,7 @@ volsToBudbVol(volFragPtr, volInfoPtr, budbVolPtr)
 }
 
 /* ----------------------------------
- * structure initialization routines 
+ * structure initialization routines
  *  ---------------------------------
  */
 
@@ -655,9 +634,8 @@ volsToBudbVol(volFragPtr, volInfoPtr, budbVolPtr)
  *     n - error
  */
 
-default_tapeset(tapesetPtr, dumpname)
-     struct budb_tapeSet *tapesetPtr;
-     char *dumpname;
+int
+default_tapeset(struct budb_tapeSet *tapesetPtr, char *dumpname)
 {
     memset(tapesetPtr, 0, sizeof(*tapesetPtr));
 
@@ -666,4 +644,5 @@ default_tapeset(tapesetPtr, dumpname)
     tapesetPtr->a = 1;
     tapesetPtr->b = 1;
     tapesetPtr->maxTapes = 0;
+    return 0;
 }