Blank line cleanup.

This commit is contained in:
Chris Osborn 2016-05-24 18:39:33 -07:00
parent 5f0e28bb83
commit 18f40e77c4
14 changed files with 47 additions and 29 deletions

View File

@ -47,7 +47,6 @@ int accept_connection(modem_config *cfg)
return 0;
}
int parse_ip_data(modem_config *cfg, char *data, int len)
{
// I'm going to cheat and assume it comes in chunks.
@ -56,6 +55,7 @@ int parse_ip_data(modem_config *cfg, char *data, int len)
char text[1025];
int text_len = 0;
if (cfg->line_data.first_char == TRUE) {
cfg->line_data.first_char = FALSE;
if ((data[0] == 0xff) || (data[0] == 0x1a)) {
@ -182,6 +182,7 @@ void *ctrl_thread(void *arg)
int status;
int new_status;
LOG_ENTER();
status = dce_get_control_lines(cfg);
@ -207,7 +208,6 @@ void *ctrl_thread(void *arg)
exit(-1);
}
int spawn_ctrl_thread(modem_config *cfg)
{
int rc;
@ -228,6 +228,7 @@ int spawn_ip_thread(modem_config *cfg)
int rc;
pthread_t thread_id;
rc = pthread_create(&thread_id, NULL, ip_thread, (void *) cfg);
LOG(LOG_ALL, "IP thread ID=%d", (int) thread_id);

View File

@ -17,6 +17,7 @@ int dce_init_conn(modem_config *cfg)
{
int rc;
LOG_ENTER();
if (cfg->dce_data.is_ip232) {
rc = ip232_init_conn(cfg);
@ -35,6 +36,7 @@ int dce_set_flow_control(modem_config *cfg, int opts)
int status = 0;
int rc = 0;
LOG_ENTER();
if (opts == 0) {
LOG(LOG_ALL, "Setting NONE flow control");
@ -66,6 +68,7 @@ int dce_set_control_lines(modem_config *cfg, int state)
int status = 0;
int rc;
LOG_ENTER();
if ((state & MDM_CL_CTS_HIGH) != 0) {
LOG(LOG_ALL, "Setting CTS pin high");
@ -100,6 +103,7 @@ int dce_get_control_lines(modem_config *cfg)
int status;
int rc_status;
if (cfg->dce_data.is_ip232) {
status = ip232_get_control_lines(cfg);
}
@ -122,6 +126,7 @@ int dce_check_control_lines(modem_config *cfg)
int status = 0;
int new_status = 0;
LOG_ENTER();
status = dce_get_control_lines(cfg);
new_status = status;

View File

@ -12,7 +12,6 @@ char *trace_type[9]; // cheesy, but I can't think of another o(1) way
char *log_desc[LOG_TRACE + 1];
pthread_mutex_t log_mutex;
int log_init()
{
log_file = stdout;
@ -37,31 +36,26 @@ int log_init()
return 0;
}
void log_set_file(FILE * a)
{
log_file = a;
}
void log_set_level(int a)
{
log_level = a;
}
void log_set_trace_flags(int a)
{
trace_flags = a;
}
int log_get_trace_flags()
{
return trace_flags;
}
void log_trace(int type, char *line, int len)
{
int i = 0;
@ -70,6 +64,7 @@ void log_trace(int type, char *line, int len)
char *dptr = NULL;
char text[17];
if (len == 0)
return;
@ -119,6 +114,7 @@ void log_start(int level)
char t[23];
time_t now;
if (-1 == pthread_mutex_lock(&log_mutex)) {
perror("Could not lock the log mutex");
}

View File

@ -28,7 +28,6 @@
#endif
#endif
#define LOG(a,args...) do { \
if(a <= log_level) { \
log_start(a); \

View File

@ -4,12 +4,13 @@
#include "getcmd.h"
int getData(char line[], int *index, int len, int *data_start, int *data_end, int complex_parse)
int getData(char line[], int *index, int len, int *data_start, int *data_end,
int complex_parse)
{
int alpha = FALSE;
int done = FALSE;
*data_start = *index;
while (*index < len && done != TRUE) {
@ -68,6 +69,7 @@ int getNumber(char line[], int *index, int len)
int num = 0;
int found = FALSE;
while (*index < len && 0 != isdigit(line[*index])) {
num = num * 10 + line[(*index)++] - '0';
found = 1;
@ -77,7 +79,6 @@ int getNumber(char line[], int *index, int len)
return num;
}
int skip(char line[], int *index, int len, char ch)
{
while (*index < len && ch == line[*index])
@ -90,30 +91,30 @@ int getCommand(char line[], int flags, int *index, int *num, int len)
{
int cmd = line[(*index)++];
*num = getNumber(line, index, len);
return cmd;
}
int parseCommand(char line[], int flags, int *index, int *num, int len)
{
int cmd = getCommand(line, flags, index, num, len);
if (0 < cmd && 0 > *num)
*num = 0;
return toupper(cmd) | flags;
}
int parseRegister(char line[],
int flags,
int *index,
int *num, int len, int *data_start, int *data_end, int complex_parse)
{
// need to handle S<num>?, which queries that S register.
int cmd = 0;
cmd = getCommand(line, flags, index, num, len);
if (0 > num)
return AT_CMD_ERR;
@ -136,6 +137,7 @@ int parseRegister(char line[],
default:
return AT_CMD_ERR;
}
return toupper(cmd) | flags;
}
@ -144,6 +146,7 @@ int getcmd(char line[], int *index, int *num, int *data_start, int *data_end)
int len = 0;
int cmd = AT_CMD_END;
*num = 0;
*data_start = 0;
*data_end = 0;
@ -267,9 +270,11 @@ int main_getcmd(int argc, char **argv)
int index = 0, num = 0, start = 0, end = 0;
int cmd = 0;
while (cmd != AT_CMD_END) {
cmd = getcmd(data, &index, &num, &start, &end);
printf("Cmd: %c Index: %d Num: %d Start: %d End: %d\n", cmd, index, num, start, end);
}
return 0;
}

View File

@ -52,6 +52,7 @@ int init(int argc,
int dce_set = FALSE;
int tty_set = FALSE;
LOG_ENTER();
*port = 6400;
mdm_init_config(&cfg[0]);

View File

@ -9,7 +9,6 @@
#include "debug.h"
#include "ip.h"
const int BACK_LOG = 5;
int ip_init_server_conn(int port)
@ -17,6 +16,7 @@ int ip_init_server_conn(int port)
int sSocket = 0, on = 0, rc = 0;
struct sockaddr_in serverName = { 0 };
LOG_ENTER();
LOG(LOG_DEBUG, "Creating server socket");
@ -70,8 +70,6 @@ int ip_init_server_conn(int port)
return sSocket;
}
int ip_connect(char addy[])
{
struct sockaddr_in pin;
@ -82,6 +80,7 @@ int ip_connect(char addy[])
char *address;
char *tmp;
LOG_ENTER();
address = (char *) strtok(addy, ":");
@ -131,6 +130,7 @@ int ip_accept(int sSocket)
socklen_t clientLength = sizeof(clientName);
int cSocket = -1;
LOG_ENTER();
(void) memset(&clientName, 0, sizeof(clientName));
@ -169,6 +169,7 @@ int ip_read(int fd, char *data, int len)
{
int res;
res = recv(fd, data, len, 0);
log_trace(TRACE_IP_IN, data, res);
return res;

View File

@ -26,6 +26,7 @@ void *ip232_thread(void *arg)
int max_fd = 0;
int cSocket;
LOG_ENTER();
for (;;) {
FD_ZERO(&readfs);
@ -71,9 +72,9 @@ void *ip232_thread(void *arg)
int spawn_ip232_thread(modem_config *cfg)
{
int rc;
pthread_t thread_id;
rc = pthread_create(&thread_id, NULL, ip232_thread, (void *) cfg);
LOG(LOG_ALL, "ip232 thread ID=%d", (int) thread_id);
if (rc < 0) {
@ -88,6 +89,7 @@ int ip232_init_conn(modem_config *cfg)
int rc = -1;
int port;
LOG_ENTER();
LOG(LOG_INFO, "Opening ip232 device");
port = atoi(cfg->dce_data.tty);
@ -122,6 +124,7 @@ int ip232_get_control_lines(modem_config *cfg)
{
int status = 0;
if (cfg->dce_data.ip232_is_connected && cfg->dce_data.ip232_dtr) {
status |= TIOCM_DSR;
}
@ -133,6 +136,7 @@ int ip232_set_control_lines(modem_config *cfg, int state)
int dcd;
char cmd[2];
if (cfg->dce_data.ip232_is_connected) {
dcd = (state & TIOCM_DTR) ? TRUE : FALSE;
if (dcd != cfg->dce_data.ip232_dcd) {
@ -153,6 +157,7 @@ int ip232_write(modem_config *cfg, char *data, int len)
char text[1024];
int text_len = 0;
log_trace(TRACE_MODEM_OUT, data, len);
retval = len;
if (cfg->dce_data.ip232_is_connected) {
@ -192,6 +197,7 @@ int ip232_read(modem_config *cfg, char *data, int len)
char ch;
int text_len = 0;
LOG_ENTER();
if (len > sizeof(buf)) {
LOG(LOG_FATAL, "ip232_read: len > sizeof(buf)");
@ -237,7 +243,6 @@ int ip232_read(modem_config *cfg, char *data, int len)
}
}
else {
// not connected
res = read(cfg->dce_data.dp[0][0], buf, sizeof(buf));
switch (buf[0]) {
@ -254,6 +259,7 @@ int ip232_read(modem_config *cfg, char *data, int len)
break;
}
}
LOG_EXIT();
return text_len;
}

View File

@ -15,5 +15,4 @@ int ip232_set_control_lines(modem_config *, int state);
int ip232_write(modem_config *, char *data, int len);
int ip232_read(modem_config *, char *data, int len);
#endif /* */

View File

@ -33,7 +33,6 @@ int mdm_init()
return 0;
}
int get_connect_response(int speed, int level)
{
if (level == 0) {
@ -66,6 +65,7 @@ void mdm_init_config(modem_config *cfg)
{
int i = 0;
cfg->send_responses = TRUE;
cfg->connect_response = 0;
cfg->response_code_level = 4;
@ -155,6 +155,7 @@ int mdm_set_control_lines(modem_config *cfg)
int state = 0;
int up = (cfg->conn_type == MDM_CONN_NONE ? FALSE : TRUE);
state |= get_new_cts_state(cfg, up);
state |= get_new_dsr_state(cfg, up);
state |= get_new_dcd_state(cfg, up);
@ -172,6 +173,7 @@ void mdm_write_char(modem_config *cfg, char data)
{
char str[2];
str[0] = data;
mdm_write(cfg, str, 1);
}
@ -209,6 +211,7 @@ void mdm_send_response(int msg, modem_config *cfg)
{
char msgID[17];
LOG(LOG_DEBUG, "Sending %s response to modem", mdm_responses[msg]);
if (cfg->send_responses == TRUE) {
mdm_write_parity(cfg, cfg->crlf, 2);
@ -227,7 +230,6 @@ void mdm_send_response(int msg, modem_config *cfg)
int mdm_off_hook(modem_config *cfg)
{
LOG(LOG_INFO, "taking modem off hook");
cfg->off_hook = TRUE;
cfg->cmd_mode = FALSE;
@ -258,6 +260,7 @@ int mdm_print_speed(modem_config *cfg)
{
int speed;
switch (cfg->connect_response) {
case 2:
speed = cfg->dte_speed;
@ -288,17 +291,16 @@ int mdm_connect(modem_config *cfg)
return 0;
}
int mdm_listen(modem_config *cfg)
{
return line_listen(cfg);
}
int mdm_disconnect(modem_config *cfg)
{
int type;
LOG_ENTER();
LOG(LOG_INFO, "Disconnecting modem");
cfg->cmd_mode = TRUE;
@ -335,6 +337,7 @@ int mdm_parse_cmd(modem_config *cfg)
char *command = cfg->cur_line;
char tmp[256];
LOG_ENTER();
LOG(LOG_DEBUG, "Evaluating AT%s", command);
@ -629,6 +632,7 @@ int mdm_parse_data(modem_config *cfg, char *data, int len)
{
int i;
if (cfg->cmd_mode == TRUE) {
for (i = 0; i < len; i++) {
mdm_handle_char(cfg, data[i]);

View File

@ -49,7 +49,6 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
typedef struct line_config {
int valid_conn;
int fd;

View File

@ -8,6 +8,7 @@ int nvt_init_config(nvt_vars *vars)
{
int i;
vars->binary_xmit = FALSE;
vars->binary_recv = FALSE;
for (i = 0; i < 256; i++)
@ -20,6 +21,7 @@ char get_nvt_cmd_response(char action, char type)
{
char rc = 0;
if (type == TRUE) {
switch (action) {
case NVT_DO:
@ -63,6 +65,7 @@ int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len)
int rc;
int slen = 0;
for (rc = 2; rc < len - 1; rc++) {
if (NVT_IAC == data[rc])
if (NVT_SE == data[rc + 1]) {
@ -106,6 +109,7 @@ int send_nvt_command(int fd, nvt_vars *vars, char action, int opt)
{
char cmd[3];
cmd[0] = NVT_IAC;
cmd[1] = action;
cmd[2] = opt;
@ -116,11 +120,11 @@ int send_nvt_command(int fd, nvt_vars *vars, char action, int opt)
return 0;
}
int parse_nvt_command(int fd, nvt_vars *vars, char action, int opt)
{
char resp[3];
resp[0] = NVT_IAC;
resp[2] = opt;

View File

@ -44,7 +44,6 @@ typedef struct nvt_vars {
char term[256];
} nvt_vars;
char get_nvt_cmd_response(char action, char type);
int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len);
int parse_nvt_command(int fd, nvt_vars *vars, char action, int opt);

View File

@ -17,7 +17,6 @@
const char MDM_BUSY[] = "BUSY\n";
int main(int argc, char *argv[])
{
modem_config cfg[64];