diff options
author | Brian Cully <bjc@kublai.com> | 2008-04-15 12:19:02 -0400 |
---|---|---|
committer | Brian Cully <github.20.shmit@spamgourmet.com> | 2008-04-15 12:19:02 -0400 |
commit | ca1f79f732648f9de52b0f63def37000dc9225e6 (patch) | |
tree | 599aef4c025e1012d2f5b87bce7aaa3eba951a47 /server | |
parent | 078555c194fd992a2e02e98f20645b82ce1792d3 (diff) | |
download | nastd-ca1f79f732648f9de52b0f63def37000dc9225e6.tar.gz nastd-ca1f79f732648f9de52b0f63def37000dc9225e6.zip |
Fix build on darwin
Diffstat (limited to 'server')
-rw-r--r-- | server/cdb.c | 30 | ||||
-rw-r--r-- | server/cdb_find.c | 13 | ||||
-rw-r--r-- | server/cdbpriv.h | 4 | ||||
-rw-r--r-- | server/memdb.c | 17 | ||||
-rw-r--r-- | server/memdb.h | 8 | ||||
-rw-r--r-- | server/nastd.c | 2 | ||||
-rw-r--r-- | server/nastdio.c | 14 | ||||
-rw-r--r-- | server/periodic.c | 7 |
8 files changed, 54 insertions, 41 deletions
diff --git a/server/cdb.c b/server/cdb.c index 4f55d03..8c64adb 100644 --- a/server/cdb.c +++ b/server/cdb.c @@ -41,8 +41,8 @@ static int sec_c; static float onemin_c, fivemin_c, fifteenmin_c; static int -cdb_findbykey(char *mcdb, int len, const char *key, int keylen, - char **data, int *dlen) +cdb_findbykey(char *mcdb, int len, const unsigned char *key, int keylen, + char **data, uint32_t *dlen) { if (cdb_find(mcdb, len, key, keylen, data, dlen) != 1) return -1; @@ -60,9 +60,10 @@ cdb_new() char cdbfields_s[1024], newkey[1024], newtbl[1024], newdbn[1024]; char newsep; struct stat sb; - int i, fieldslen, newfieldcount; + int fieldslen, newfieldcount; int fd; size_t len; + uint32_t i; log_info("Initialising CDB interface."); @@ -106,8 +107,8 @@ cdb_new() (void)close(fd); /* Get the key out of the CDB, so clients know how to search. */ - if (cdb_findbykey(newcdb, len, "_KEY_", strlen("_KEY_"), - &p, &i) == -1) { + if (cdb_findbykey(newcdb, len, (unsigned char *)"_KEY_", + strlen("_KEY_"), &p, &i) == -1) { log_err("Couldn't find `_KEY_' in the CDB."); munmap(newcdb, len); return -1; @@ -122,7 +123,8 @@ cdb_new() newkey[i] = '\0'; /* Get the dbname out of the CDB, so mysql knows which db to use. */ - if (cdb_findbykey(newcdb, len, "_DB_", strlen("_DB_"), &p, &i) == -1) { + if (cdb_findbykey(newcdb, len, (unsigned char *)"_DB_", + strlen("_DB_"), &p, &i) == -1) { log_err("Warning: Couldn't find `_DB_' in the CDB."); strncpy(newdbn, DBNAME, sizeof(newdbn)); } else { @@ -137,8 +139,8 @@ cdb_new() } /* Get the table out of the CDB, so mysql knows which to use. */ - if (cdb_findbykey(newcdb, len, "_TABLE_", strlen("_TABLE_"), - &p, &i) == -1) { + if (cdb_findbykey(newcdb, len, (unsigned char *)"_TABLE_", + strlen("_TABLE_"), &p, &i) == -1) { log_err("Warning: Couldn't find `_TABLE_' in the CDB."); strncpy(newtbl, DBTBL, sizeof(newtbl)); } else { @@ -153,16 +155,16 @@ cdb_new() } /* Get the delimiter out of the CDB file. */ - if (cdb_findbykey(newcdb, len, "_DELIM_", strlen("_DELIM_"), - &p, &i) == -1) { + if (cdb_findbykey(newcdb, len, (unsigned char *)"_DELIM_", + strlen("_DELIM_"), &p, &i) == -1) { log_info("Couldn't find `_DELIM_' in the CDB. Using default."); newsep = ':'; } else newsep = *p; /* Now get the column names. */ - if (cdb_findbykey(newcdb, len, "_VALUES_", strlen("_VALUES_"), - &p, &i) == -1) { + if (cdb_findbykey(newcdb, len, (unsigned char *)"_VALUES_", + strlen("_VALUES_"), &p, &i) == -1) { log_err("Couldn't find `_VALUES_' in the CDB."); munmap(newcdb, len); return -1; @@ -231,11 +233,11 @@ cdb_new() } int -cdb_get(const char *key, int keylen, array_t *aa) +cdb_get(const unsigned char *key, int keylen, array_t *aa) { char *s_p, *e_p; char *data; - int dlen; + uint32_t dlen; rw_mutex_read_lock(cdb_lk); if (cdb_findbykey(memcdb, cdb_len, key, keylen, &data, &dlen) == -1) { diff --git a/server/cdb_find.c b/server/cdb_find.c index 2fc2bcf..b7c2fc9 100644 --- a/server/cdb_find.c +++ b/server/cdb_find.c @@ -2,6 +2,7 @@ #include <errno.h> #include <stdio.h> +#include <string.h> #include <sys/types.h> #ifndef SEEK_SET @@ -11,7 +12,7 @@ RCSID("$Id: cdb_find.c,v 1.2 2000/02/29 19:31:33 shmit Exp $"); static int -cdb_bread(char **ptr, char *endptr, char *buf, unsigned int len) +cdb_bread(char **ptr, char *endptr, unsigned char *buf, unsigned int len) { if ((*ptr)+len > endptr) { errno = EIO; @@ -24,9 +25,9 @@ cdb_bread(char **ptr, char *endptr, char *buf, unsigned int len) } static int -match(char **ptr, char *endptr, const char *key, unsigned int len) +match(char **ptr, char *endptr, const unsigned char *key, unsigned int len) { - char buf[32]; + unsigned char buf[32]; int n; int i; @@ -49,11 +50,11 @@ match(char **ptr, char *endptr, const char *key, unsigned int len) } int -cdb_find(char *buff, off_t bufflen, const char *key, int len, - char **ret, uint32_t *retlen) +cdb_find(char *buff, off_t bufflen, const unsigned char *key, + unsigned int len, char **ret, uint32_t *retlen) { char *cur, *end; - char packbuf[8]; + unsigned char packbuf[8]; uint32_t pos; uint32_t h; uint32_t lenhash; diff --git a/server/cdbpriv.h b/server/cdbpriv.h index cc398a8..2372b6b 100644 --- a/server/cdbpriv.h +++ b/server/cdbpriv.h @@ -7,8 +7,8 @@ #include <sys/types.h> -int cdb_find(char *buff, off_t bufflen, const char *key, int len, - char **ret, uint32_t *retlen); +int cdb_find(char *buff, off_t bufflen, const unsigned char *key, + unsigned int len, char **ret, uint32_t *retlen); uint32_t cdb_hash(const unsigned char *buff, unsigned int len); uint32_t cdb_unpack(unsigned char *buff); diff --git a/server/memdb.c b/server/memdb.c index 501d0ef..5dfbf64 100644 --- a/server/memdb.c +++ b/server/memdb.c @@ -7,6 +7,7 @@ #include "thread.h" #include <errno.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -54,9 +55,9 @@ static counter_t delrate; static counter_t updrate; static unsigned int -hashkey(const char *key, int keylen) +hashkey(const unsigned char *key, int keylen) { - char md5hash[32]; + unsigned char md5hash[32]; unsigned int rc; memset(md5hash, 0, sizeof(md5hash)); @@ -157,7 +158,7 @@ memdb_delete() } int -memdb_add(const char *key, int keylen, array_t *vals) +memdb_add(const unsigned char *key, int keylen, array_t *vals) { cachent_t *ent; int hkey; @@ -253,8 +254,12 @@ memdb_add(const char *key, int keylen, array_t *vals) ent_delete(&p->ent); free(p); break; + + case C_UPD: + case C_TRYVAL: default: /* XXX: Do an update instead of an add. */ + log_info("XXX: Can't handle request."); } } else { p->next = ent; @@ -268,7 +273,7 @@ memdb_add(const char *key, int keylen, array_t *vals) } int -memdb_del(const char *key, int keylen) +memdb_del(const unsigned char *key, int keylen) { cachent_t *p; int hkey; @@ -319,7 +324,7 @@ memdb_del(const char *key, int keylen) } int -memdb_get(const char *key, int keylen, array_t *vals) +memdb_get(const unsigned char *key, int keylen, array_t *vals) { cachent_t *p, *q; int hkey; @@ -394,7 +399,7 @@ memdb_get(const char *key, int keylen, array_t *vals) } int -memdb_upd(const char *key, int keylen, array_t *vals) +memdb_upd(const unsigned char *key, int keylen, array_t *vals) { cachent_t *p; int hkey; diff --git a/server/memdb.h b/server/memdb.h index 0822e61..7dcc25d 100644 --- a/server/memdb.h +++ b/server/memdb.h @@ -6,10 +6,10 @@ int memdb_new(); void memdb_delete(); -int memdb_add(const char *key, int keylen, array_t *vals); -int memdb_del(const char *key, int keylen); -int memdb_get(const char *key, int keylen, array_t *vals); -int memdb_upd(const char *key, int keylen, array_t *vals); +int memdb_add(const unsigned char *key, int keylen, array_t *vals); +int memdb_del(const unsigned char *key, int keylen); +int memdb_get(const unsigned char *key, int keylen, array_t *vals); +int memdb_upd(const unsigned char *key, int keylen, array_t *vals); int memdb_stats(array_t *statarr); void memdb_collate(); diff --git a/server/nastd.c b/server/nastd.c index 3c015a6..8c6bf06 100644 --- a/server/nastd.c +++ b/server/nastd.c @@ -81,7 +81,7 @@ static int do_client_connect(int sock) { struct sockaddr_un saremote; - int addrlen; + socklen_t addrlen; int s; addrlen = sizeof(saremote); diff --git a/server/nastdio.c b/server/nastdio.c index dd7ccd3..93d85c7 100644 --- a/server/nastdio.c +++ b/server/nastdio.c @@ -43,14 +43,15 @@ arr_send_response(int sock, short reqid, char r_code, array_t *aa) { char *s; char buffer[1024]; - short l, i; + short l, i, n_reqid, n_l; ssize_t wrote; /* Save space for buffer length. */ l = sizeof(short); /* Add request ID. */ - memcpy(buffer+l, &htons(reqid), sizeof(reqid)); + n_reqid = htons(reqid); + memcpy(buffer+l, &n_reqid, sizeof(n_reqid)); l += sizeof(reqid); /* Add OK or ERR. */ @@ -79,7 +80,8 @@ arr_send_response(int sock, short reqid, char r_code, array_t *aa) } /* Fill in buffer length. */ - memcpy(buffer, &htons(l), sizeof(short)); + n_l = htons(l); + memcpy(buffer, &n_l, sizeof(short)); wrote = 0; while (wrote < l) { @@ -270,7 +272,7 @@ REQHANDLER(do_fallthrough) } /* If we're this far, the memdb doesn't have this key. Add it. */ - (void)memdb_add(req->req, strlen(req->req), aa); + (void)memdb_add((unsigned char *)req->req, strlen(req->req), aa); array_delete(aa); @@ -295,7 +297,7 @@ do_get(int s, short reqid, client_opts *cops, const char *buffer, /* Check memdb first. */ if (cops->opts->use_qcache && !cops->opts->always_fallthrough) { - if (memdb_get(buffer, bufflen, aa) == 0) { + if (memdb_get((unsigned char *)buffer, bufflen, aa) == 0) { log_info("Found `%s' in memdb.", buffer); if (arr_send_response(s, reqid, NASTOK, aa) == -1) { array_delete(aa); @@ -387,7 +389,7 @@ do_update(int s, short reqid, client_opts *cops, const char *buffer, size_t bufflen) { array_t *aa; - char *key; + unsigned char *key; int keylen; for (keylen = 0; keylen < bufflen; keylen++) { diff --git a/server/periodic.c b/server/periodic.c index 9a94edb..839b406 100644 --- a/server/periodic.c +++ b/server/periodic.c @@ -9,6 +9,7 @@ #include <errno.h> #include <stdlib.h> #include <string.h> +#include <sys/time.h> RCSID("$Id: periodic.c,v 1.9 2000/05/17 21:52:34 shmit Exp $"); @@ -29,10 +30,12 @@ periodic_looper(void *arg) count = 0; for (;;) { + struct timeval tv; struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += 1; + gettimeofday(&tv, NULL); + memset(&ts, 0, sizeof(ts)); + ts.tv_sec = tv.tv_sec + 1; (void)cond_timedwait(self->cond, &ts); count++; |