Skip to content

Commit

Permalink
Cleaning up formatting:
Browse files Browse the repository at this point in the history
 * tabs to 4 spaces
 * braces for single if/else statements
 * braces on the same line as the if/else & function signature
  • Loading branch information
ViToni committed May 20, 2016
1 parent 3b2df63 commit 32c8241
Show file tree
Hide file tree
Showing 21 changed files with 520 additions and 512 deletions.
33 changes: 18 additions & 15 deletions src/callout.c
Expand Up @@ -152,24 +152,22 @@ int timer_setTimer(int delay, timer_f action, void *data) {
/* if the queue is empty, insert the node and return */
if (!queue) {
queue = node;
}
else {
} else {
/* chase the pointer looking for the right place */
while (ptr) {
if (delay < ptr->time) {
// We found the correct node
node->next = ptr;
if (ptr == queue) {
queue = node;
}
else {
} else {
prev->next = node;
}
ptr->time -= node->time;
my_log(LOG_DEBUG, 0,
"Created timeout %d (#%d) - delay %d secs",
node->id, i, node->time);
debugQueue();
my_log(LOG_DEBUG, 0,
"Created timeout %d (#%d) - delay %d secs",
node->id, i, node->time);
debugQueue();
return node->id;
} else {
// Continur to check nodes.
Expand All @@ -195,8 +193,9 @@ int timer_leftTimer(int timer_id) {
struct timeOutQueue *ptr;
int left = 0;

if (!timer_id)
if (!timer_id) {
return -1;
}

for (ptr = queue; ptr; ptr = ptr->next) {
left += ptr->time;
Expand All @@ -214,8 +213,9 @@ int timer_clearTimer(int timer_id) {
struct timeOutQueue *ptr, *prev;
int i = 0;

if (!timer_id)
if (!timer_id) {
return 0;
}

prev = ptr = queue;

Expand All @@ -230,17 +230,20 @@ int timer_clearTimer(int timer_id) {
/* got the right node */

/* unlink it from the queue */
if (ptr == queue)
if (ptr == queue) {
queue = queue->next;
else
} else {
prev->next = ptr->next;
}

/* increment next node if any */
if (ptr->next != 0)
if (ptr->next != 0) {
(ptr->next)->time += ptr->time;
}

if (ptr->data)
if (ptr->data) {
free(ptr->data);
}
my_log(LOG_DEBUG, 0, "deleted timer %d (#%d)", ptr->id, i);
free(ptr);
debugQueue();
Expand All @@ -263,6 +266,6 @@ static void debugQueue(void) {
struct timeOutQueue *ptr;

for (ptr = queue; ptr; ptr = ptr->next) {
my_log(LOG_DEBUG, 0, "(Id:%d, Time:%d) ", ptr->id, ptr->time);
my_log(LOG_DEBUG, 0, "(Id:%d, Time:%d) ", ptr->id, ptr->time);
}
}
84 changes: 39 additions & 45 deletions src/config.c
Expand Up @@ -133,7 +133,6 @@ int loadConfig(char *configFile) {
my_log(LOG_WARNING, 0, "Unknown token '%s' in configfile", token);
return 0;
} else {

my_log(LOG_DEBUG, 0, "IF name : %s", tmpPtr->name);
my_log(LOG_DEBUG, 0, "Next ptr : %x", tmpPtr->next);
my_log(LOG_DEBUG, 0, "Ratelimit : %d", tmpPtr->ratelimit);
Expand All @@ -145,29 +144,26 @@ int loadConfig(char *configFile) {
*currPtr = tmpPtr;
currPtr = &tmpPtr->next;
}
}
else if(strcmp("quickleave", token)==0) {
} else if(strcmp("quickleave", token)==0) {
// Got a quickleave token....
my_log(LOG_DEBUG, 0, "Config: Quick leave mode enabled.");
commonConfig.fastUpstreamLeave = 1;

// Read next token...
token = nextConfigToken();
continue;
}
else if(strcmp("defaultdown", token)==0) {
// Got a defaultdown token...
my_log(LOG_DEBUG, 0, "Config: interface Default as down stream.");
commonConfig.defaultInterfaceState = IF_STATE_DOWNSTREAM;
} else if(strcmp("defaultdown", token)==0) {
// Got a defaultdown token...
my_log(LOG_DEBUG, 0, "Config: interface Default as down stream.");
commonConfig.defaultInterfaceState = IF_STATE_DOWNSTREAM;

// Read next token...
token = nextConfigToken();
continue;
}
else if(strcmp("rescanvif", token)==0) {
// Got a defaultdown token...
my_log(LOG_DEBUG, 0, "Config: Need detect new interace.");
commonConfig.rescanVif = 1;
} else if(strcmp("rescanvif", token)==0) {
// Got a defaultdown token...
my_log(LOG_DEBUG, 0, "Config: Need detect new interace.");
commonConfig.rescanVif = 1;

// Read next token...
token = nextConfigToken();
Expand Down Expand Up @@ -227,7 +223,7 @@ void configureVifs(void) {
// Insert the configured nets...
vifLast->next = confPtr->allowednets;

Dp->allowedgroups = confPtr->allowedgroups;
Dp->allowedgroups = confPtr->allowedgroups;

break;
}
Expand All @@ -250,8 +246,12 @@ struct vifconfig *parsePhyintToken(void) {
token = nextConfigToken();

// Sanitycheck the name...
if(token == NULL) return NULL;
if(strlen(token) >= IF_NAMESIZE) return NULL;
if(token == NULL) {
return NULL;
}
if(strlen(token) >= IF_NAMESIZE) {
return NULL;
}
my_log(LOG_DEBUG, 0, "Config: IF: Config for interface %s.", token);

// Allocate memory for configuration...
Expand Down Expand Up @@ -294,37 +294,32 @@ struct vifconfig *parsePhyintToken(void) {
} else {
anetPtr = &(*anetPtr)->next;
}
}
else if(strcmp("whitelist", token)==0) {
// Whitelist
token = nextConfigToken();
my_log(LOG_DEBUG, 0, "Config: IF: Got whitelist token %s.", token);

*agrpPtr = parseSubnetAddress(token);
if(*agrpPtr == NULL) {
parseError = 1;
my_log(LOG_WARNING, 0, "Unable to parse subnet address.");
break;
} else {
agrpPtr = &(*agrpPtr)->next;
}
}
else if(strcmp("upstream", token)==0) {
} else if(strcmp("whitelist", token)==0) {
// Whitelist
token = nextConfigToken();
my_log(LOG_DEBUG, 0, "Config: IF: Got whitelist token %s.", token);

*agrpPtr = parseSubnetAddress(token);
if(*agrpPtr == NULL) {
parseError = 1;
my_log(LOG_WARNING, 0, "Unable to parse subnet address.");
break;
} else {
agrpPtr = &(*agrpPtr)->next;
}
} else if(strcmp("upstream", token)==0) {
// Upstream
my_log(LOG_DEBUG, 0, "Config: IF: Got upstream token.");
tmpPtr->state = IF_STATE_UPSTREAM;
}
else if(strcmp("downstream", token)==0) {
} else if(strcmp("downstream", token)==0) {
// Downstream
my_log(LOG_DEBUG, 0, "Config: IF: Got downstream token.");
tmpPtr->state = IF_STATE_DOWNSTREAM;
}
else if(strcmp("disabled", token)==0) {
} else if(strcmp("disabled", token)==0) {
// Disabled
my_log(LOG_DEBUG, 0, "Config: IF: Got disabled token.");
tmpPtr->state = IF_STATE_DISABLED;
}
else if(strcmp("ratelimit", token)==0) {
} else if(strcmp("ratelimit", token)==0) {
// Ratelimit
token = nextConfigToken();
my_log(LOG_DEBUG, 0, "Config: IF: Got ratelimit token '%s'.", token);
Expand All @@ -334,8 +329,7 @@ struct vifconfig *parsePhyintToken(void) {
parseError = 1;
break;
}
}
else if(strcmp("threshold", token)==0) {
} else if(strcmp("threshold", token)==0) {
// Threshold
token = nextConfigToken();
my_log(LOG_DEBUG, 0, "Config: IF: Got threshold token '%s'.", token);
Expand All @@ -345,8 +339,7 @@ struct vifconfig *parsePhyintToken(void) {
parseError = 1;
break;
}
}
else {
} else {
// Unknown token. Break...
break;
}
Expand Down Expand Up @@ -385,10 +378,11 @@ struct SubnetList *parseSubnetAddress(char *addrstr) {
return NULL;
}

if (bitcnt == 0)
if (bitcnt == 0) {
mask = 0;
else
} else {
mask <<= (32 - bitcnt);
}
}

if(addr == -1) {
Expand All @@ -402,7 +396,7 @@ struct SubnetList *parseSubnetAddress(char *addrstr) {
tmpSubnet->next = NULL;

my_log(LOG_DEBUG, 0, "Config: IF: Altnet: Parsed altnet to %s.",
inetFmts(tmpSubnet->subnet_addr, tmpSubnet->subnet_mask,s1));
inetFmts(tmpSubnet->subnet_addr, tmpSubnet->subnet_mask,s1));

return tmpSubnet;
}
15 changes: 7 additions & 8 deletions src/confread.c
Expand Up @@ -67,20 +67,20 @@ int openConfigFile(char *filename) {

// Open the file for reading...
confFilePtr = fopen(filename, "r");

// On error, return false
if(confFilePtr == NULL) {
return 0;
}

// Allocate memory for inputbuffer...
iBuffer = (char*) malloc( sizeof(char) * READ_BUFFER_SIZE );

if(iBuffer == NULL) {
closeConfigFile();
return 0;
}

// Reset bufferpointer and readsize
bufPtr = 0;
readSize = 0;
Expand Down Expand Up @@ -149,7 +149,6 @@ char *nextConfigToken(void) {
commentFound = 0;
}
} else {

// Check current char...
switch(iBuffer[bufPtr]) {
case '#':
Expand Down Expand Up @@ -188,10 +187,11 @@ char *nextConfigToken(void) {
}
// If the readsize is less than buffersize, we assume EOF.
if(readSize < READ_BUFFER_SIZE && bufPtr == readSize) {
if (tokenPtr > 0)
if (tokenPtr > 0) {
finished = 1;
else
} else {
return NULL;
}
}
}
if(tokenPtr>0) {
Expand All @@ -210,4 +210,3 @@ char *nextConfigToken(void) {
char *getCurrentConfigToken(void) {
return validToken ? cToken : NULL;
}

0 comments on commit 32c8241

Please sign in to comment.