diff options
| author | Franklin Wei <git@fwei.tk> | 2016-03-28 14:11:22 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2016-03-28 14:11:22 -0400 |
| commit | 2687778cf7c099e47de410d62d26d874f4dcebba (patch) | |
| tree | 359759f153ffd0dc6b8c0bfc60460d10c9cd806a | |
| parent | 13052597a19fd2212efb7f51f19ed73b9f4b6ba4 (diff) | |
| download | netcosm-2687778cf7c099e47de410d62d26d874f4dcebba.zip netcosm-2687778cf7c099e47de410d62d26d874f4dcebba.tar.gz netcosm-2687778cf7c099e47de410d62d26d874f4dcebba.tar.bz2 netcosm-2687778cf7c099e47de410d62d26d874f4dcebba.tar.xz | |
kludge things to compile on old linux
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | export/include/world_api.h | 1 | ||||
| -rw-r--r-- | src/client.c | 2 | ||||
| -rw-r--r-- | src/client.h | 4 | ||||
| -rw-r--r-- | src/client_reqs.c | 1 | ||||
| -rw-r--r-- | src/client_reqs.h | 2 | ||||
| -rw-r--r-- | src/globals.h | 4 | ||||
| -rw-r--r-- | src/hash.c | 1 | ||||
| -rw-r--r-- | src/obj.h | 3 | ||||
| -rw-r--r-- | src/room.h | 19 | ||||
| -rw-r--r-- | src/server.c | 5 | ||||
| -rw-r--r-- | src/server.h | 7 | ||||
| -rw-r--r-- | src/server_reqs.c | 3 | ||||
| -rw-r--r-- | src/server_reqs.h | 2 | ||||
| -rw-r--r-- | src/userdb.c | 3 | ||||
| -rw-r--r-- | src/util.c | 55 | ||||
| -rw-r--r-- | src/verb.h | 4 |
17 files changed, 88 insertions, 30 deletions
@@ -34,7 +34,7 @@ INCLUDES = -I src/ -I export/include/ WARNFLAGS = -Wall -Wextra -Wshadow -fno-strict-aliasing -OPTFLAGS = -Og +OPTFLAGS = -O2 DEBUGFLAGS = -g CFLAGS = $(OPTFLAGS) $(DEBUGFLAGS) $(WARNFLAGS) -std=c99 $(INCLUDES) diff --git a/export/include/world_api.h b/export/include/world_api.h index d97d9cb..9537c68 100644 --- a/export/include/world_api.h +++ b/export/include/world_api.h @@ -21,6 +21,7 @@ #include "globals.h" #include "server.h" +#include "server_reqs.h" #include "hash.h" #include "multimap.h" #include "userdb.h" diff --git a/src/client.c b/src/client.c index a93ae0e..90a166b 100644 --- a/src/client.c +++ b/src/client.c @@ -20,10 +20,12 @@ #include "auth.h" #include "client.h" +#include "client_reqs.h" #include "hash.h" #include "server.h" #include "room.h" #include "telnet.h" +#include "userdb.h" #include "util.h" bool are_admin = false; diff --git a/src/client.h b/src/client.h index 5b5c5ff..223bf86 100644 --- a/src/client.h +++ b/src/client.h @@ -21,10 +21,6 @@ #include "globals.h" -#include "client_reqs.h" -#include "room.h" -#include "userdb.h" - extern int client_fd, to_parent, from_parent; extern bool are_admin; diff --git a/src/client_reqs.c b/src/client_reqs.c index 39a67f9..40d1c61 100644 --- a/src/client_reqs.c +++ b/src/client_reqs.c @@ -19,6 +19,7 @@ #include "globals.h" #include "client.h" +#include "client_reqs.h" #include "hash.h" enum reqdata_typespec reqdata_type = TYPE_NONE; diff --git a/src/client_reqs.h b/src/client_reqs.h index 979da9a..0d2a63c 100644 --- a/src/client_reqs.h +++ b/src/client_reqs.h @@ -24,6 +24,8 @@ #include "server_reqs.h" #include "userdb.h" +enum room_id; + enum reqdata_typespec { TYPE_NONE = 0, TYPE_USERDATA, TYPE_BOOLEAN } reqdata_type; union reqdata_t { diff --git a/src/globals.h b/src/globals.h index 987d382..0177b8a 100644 --- a/src/globals.h +++ b/src/globals.h @@ -21,14 +21,14 @@ #define _GNU_SOURCE -#include <ev.h> +#include <libev/ev.h> #include <openssl/sha.h> #include <openssl/opensslv.h> #include <arpa/inet.h> #include <arpa/telnet.h> #include <assert.h> -#include <bsd/string.h> // for strlcat +//#include <bsd/string.h> // for strlcat #include <ctype.h> #include <errno.h> #include <fcntl.h> @@ -357,6 +357,7 @@ struct hash_export_node hash_get_internal_node(void *ptr, const void *key) } struct hash_export_node ret; + memset(&ret, 0, sizeof(ret)); ret.node = NULL; return ret; } @@ -21,14 +21,13 @@ #include "globals.h" #include "room.h" +#include "server.h" /* Objects belong to an object class. Objects define their object * class through the class name, which is converted to a class ID * internally. */ -typedef struct child_data user_t; - struct object_t; struct obj_class_t { @@ -20,15 +20,14 @@ #include "globals.h" -#include "obj.h" -#include "verb.h" - /* Our world is an array of rooms, each having a list of objects in - them, as well as actions that can be performed in the room. Objects - are added by hooks in rooms, which are provided by the world - module. */ + * them, as well as actions that can be performed in them + * (verbs). Objects are added by hooks in rooms, which are provided as + * function pointers by the world module. */ -typedef struct child_data user_t; // definition of child_data in server.h +struct child_data; +struct object_t; +struct verb_t; typedef enum room_id { ROOM_NONE = -1 } room_id; @@ -50,8 +49,10 @@ struct roomdata_t { /* return values indicate permission to enter/leave, * setting to NULL defaults to true. */ - bool (* const hook_enter)(room_id room, user_t *user); - bool (* const hook_leave)(room_id room, user_t *user); + + /* NOTE: struct child_data is aliased as "user_t"!!! */ + bool (* const hook_enter)(room_id room, struct child_data *user); + bool (* const hook_leave)(room_id room, struct child_data *user); void (* const hook_serialize)(room_id room, int fd); void (* const hook_deserialize)(room_id room, int fd); void (* const hook_destroy)(room_id room); diff --git a/src/server.c b/src/server.c index e42483c..f0b56ec 100644 --- a/src/server.c +++ b/src/server.c @@ -21,6 +21,7 @@ #include "client.h" #include "hash.h" #include "server.h" +#include "server_reqs.h" #include "userdb.h" #include "util.h" #include "world.h" @@ -254,9 +255,9 @@ static void new_connection_cb(EV_P_ ev_io *w, int revents) int readpipe[2]; /* child->parent */ int outpipe [2]; /* parent->child */ - if(pipe2(readpipe, O_DIRECT) < 0) + if(pipe(readpipe) < 0) error("error creating pipe, need linux kernel >= 3.4"); - if(pipe2(outpipe, O_DIRECT) < 0) + if(pipe(outpipe) < 0) error("error creating pipe, need linux kernel >= 3.4"); pid_t pid = fork(); diff --git a/src/server.h b/src/server.h index 95e537a..6d3d029 100644 --- a/src/server.h +++ b/src/server.h @@ -19,12 +19,9 @@ /* You should use #pragma once everywhere. */ #pragma once -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> +#include "globals.h" -#include "server_reqs.h" -#include "room.h" +enum room_id; /* everything the server needs to manage its children */ struct child_data { diff --git a/src/server_reqs.c b/src/server_reqs.c index 4d89ca4..4a147ae 100644 --- a/src/server_reqs.c +++ b/src/server_reqs.c @@ -21,10 +21,11 @@ #include "hash.h" #include "multimap.h" #include "server.h" +#include "server_reqs.h" #include "userdb.h" #include "world.h" -/* sends a single packet to a child, virtually guarantees receipt */ +/* sends a single packet to a child, mostly reliable */ static void send_packet(struct child_data *child, unsigned char cmd, const void *data, size_t datalen) { diff --git a/src/server_reqs.h b/src/server_reqs.h index c77c53a..68ba74a 100644 --- a/src/server_reqs.h +++ b/src/server_reqs.h @@ -20,7 +20,7 @@ #include "globals.h" -typedef struct child_data user_t; +#include "server.h" /* child<->master commands */ /* children might not implement all of these */ diff --git a/src/userdb.c b/src/userdb.c index 101b6d0..54dd19e 100644 --- a/src/userdb.c +++ b/src/userdb.c @@ -19,9 +19,12 @@ #include "globals.h" #include "client.h" +#include "client_reqs.h" #include "hash.h" #include "multimap.h" +#include "obj.h" #include "server.h" +#include "server_reqs.h" #include "userdb.h" static void *map = NULL; @@ -187,3 +187,58 @@ bool is_vowel(char c) return false; } } + +/* $NetBSD: strlcat.c,v 1.4 2005/05/16 06:55:48 lukem Exp $ */ +/* from NetBSD: strlcat.c,v 1.16 2003/10/27 00:12:42 lukem Exp */ +/* from OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE + * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} @@ -21,6 +21,7 @@ #include "globals.h" #include "room.h" +#include "server.h" /* the verb API is modeled after that of obj_*, this allows for * dynamic creation/deletion of verbs, but is also easily @@ -30,9 +31,6 @@ * callbacks. */ -struct child_data; -typedef struct child_data user_t; - struct verb_t; struct verb_class_t { const char *class_name; |