Improve code readability by using enum typedefs.

This commit is contained in:
Sam Hocevar 2019-07-05 10:35:39 +02:00
parent da497404ab
commit ebd31cc72e
3 changed files with 11 additions and 9 deletions

View File

@ -248,8 +248,8 @@ static void readConfiguration(char const *file) {
} }
} }
void addServer(char *bindAddress, uint16_t bindPort, int bindProto, void addServer(char *bindAddress, uint16_t bindPort, protocolType bindProto,
char *connectAddress, uint16_t connectPort, int connectProto, char *connectAddress, uint16_t connectPort, protocolType connectProto,
int serverTimeout, char *sourceAddress) int serverTimeout, char *sourceAddress)
{ {
/* Turn all of this stuff into reasonable addresses */ /* Turn all of this stuff into reasonable addresses */

View File

@ -46,7 +46,7 @@ extern FILE *logFile;
/* Functions */ /* Functions */
void addServer(char *bindAddress, uint16_t bindPort, int bindProto, void addServer(char *bindAddress, uint16_t bindPort, protocolType bindProto,
char *connectAddress, uint16_t connectPort, int connectProto, char *connectAddress, uint16_t connectPort, protocolType connectProto,
int serverTimeout, char *sourceAddress); int serverTimeout, char *sourceAddress);

View File

@ -11,12 +11,14 @@
#include <time.h> #include <time.h>
#include <stdint.h> #include <stdint.h>
enum ruleType { typedef enum _rule_type ruleType;
enum _rule_type {
allowRule, allowRule,
denyRule, denyRule,
}; };
enum protocolType { typedef enum _protocol_type protocolType;
enum _protocol_type {
protoTcp = 1, protoTcp = 1,
protoUdp = 2, protoUdp = 2,
}; };
@ -25,7 +27,7 @@ typedef struct _rule Rule;
struct _rule struct _rule
{ {
char *pattern; char *pattern;
int type; ruleType type;
}; };
typedef struct _server_info ServerInfo; typedef struct _server_info ServerInfo;
@ -40,7 +42,7 @@ struct _server_info {
/* In ASCII and local byte order, for logging purposes */ /* In ASCII and local byte order, for logging purposes */
char *fromHost, *toHost; char *fromHost, *toHost;
int16_t fromPort, toPort; int16_t fromPort, toPort;
int fromProto, toProto; protocolType fromProto, toProto;
/* Offset and count into list of allow and deny rules. Any rules /* Offset and count into list of allow and deny rules. Any rules
prior to globalAllowRules and globalDenyRules are global rules. */ prior to globalAllowRules and globalDenyRules are global rules. */
@ -54,7 +56,7 @@ typedef struct _socket Socket;
struct _socket struct _socket
{ {
SOCKET fd; SOCKET fd;
int proto; protocolType proto;
/* recv: received on this socket /* recv: received on this socket
sent: sent through this socket from the other buffer */ sent: sent through this socket from the other buffer */
int recvPos, sentPos; int recvPos, sentPos;