Commit 97ebe828 authored by 's avatar
Browse files

Logging to file updated. If a user wants support for logging to file, the filename is defined

in mapi.conf in the logfile field. For example, logfile=/usr/local/etc/mapi/mapi_logfile

Then, debug messages are printed to file /usr/local/etc/mapi/mapi_logfile.debug
and general information messages to file /usr/local/etc/mapi/mapi_logfile.info

In mapi.conf syslog_level changed to log_level, as it concerns both logging to
file and syslog.



git-svn-id: file:///home/svn/mapi/trunk@1299 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent fd46b474
......@@ -4,7 +4,7 @@ drvpath=@DATADIR@
libs=@MAPI_FUNC_LIBS@
dimapi_port=2233
syslog_level=1
log_level=1
logfile=
[driver]
......
......@@ -3,6 +3,8 @@
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <syslog.h>
#include "debug.h"
......@@ -12,6 +14,19 @@
char *debug_message_file = NULL; // filename information
int debug_message_line = 0; // line number information
void write_to_debug_file(int log_fd, char *msg, ...){
char buf[STD_BUF];
va_list ap;
va_start(ap, msg);
vsprintf(buf, msg, ap);
write(log_fd, buf, strlen(buf));
va_end(ap);
return;
}
void debug_message(char *fmt, ...){
char buf[STD_BUF + 1];
......@@ -22,7 +37,7 @@ void debug_message(char *fmt, ...){
va_start(ap, fmt);
if(log_level == LOG_INFO_DEBUG_ALL || log_level == SYSLOG_DISABLED){ // debug messages are printed to stdout and syslog OR logging to
if(log_level == LOG_INFO_DEBUG_ALL || log_level == LOGGING_DISABLED){ // debug messages are printed to stdout and syslog OR logging to
// syslog is disabled, thus debug messages are printed only to stdout
vprintf(fmt, ap);
......@@ -30,13 +45,14 @@ void debug_message(char *fmt, ...){
printf(" [%s:%d]\n", debug_message_file, debug_message_line);
}
if(log_level == LOG_INFO_DEBUG_SYSLOG || log_level == LOG_INFO_DEBUG_ALL){ // print debug messages to syslog
if(log_level == LOG_INFO_DEBUG_NOT_STDOUT || log_level == LOG_INFO_DEBUG_ALL){ // print debug messages to syslog
len = vsnprintf(buf, STD_BUF, fmt, ap);
sprintf(buf + len, " [%s:%d]", debug_message_file, debug_message_line); // filename and line number information
buf[STD_BUF] = '\0';
syslog(LOG_LOCAL1 | LOG_DEBUG, "%s", buf);
if(log_to_file) write_to_debug_file(log_fd_debug, "%s\n", buf);
if(log_to_syslog) syslog(LOG_LOCAL1 | LOG_DEBUG, "%s", buf);
}
va_end(ap);
......@@ -48,4 +64,7 @@ void debug_message(char *fmt, ...){
void debug_message(MAPI_UNUSED char *fmt, ...){
}
void write_to_debug_file(MAPI_UNUSED int log_fd, MAPI_UNUSED char *msg, ...){
}
#endif //DEBUG
#ifndef DEBUG_H
#define DEBUG_H
#define SYSLOG_DISABLED -1
#define LOG_INFORMATION 0
#define LOG_INFO_DEBUG_ALL 1
#define LOG_INFO_DEBUG_SYSLOG 2
#define LOGGING_DISABLED -1
#define LOG_INFORMATION 0
#define LOG_INFO_DEBUG_ALL 1
#define LOG_INFO_DEBUG_NOT_STDOUT 2
void debug_message(char *fmt, ...);
void write_to_debug_file(int log_fd, char *msg, ...);
#ifdef DEBUG
extern char *debug_message_file; // filename information
extern int debug_message_line; // line number information
extern int log_level;
extern int log_level, log_to_syslog, log_to_file, log_fd_debug;
#define Debug_Message debug_message_file = __FILE__; debug_message_line = __LINE__; debug_message
......@@ -25,6 +26,7 @@ void debug_message(char *fmt, ...);
#define DEBUG_CMD3(code) code
void debug_message(char *fmt, ...);
void write_to_debug_file(int log_fd, char *msg, ...);
#else
......
......@@ -34,34 +34,59 @@
* touch /var/tmp/debug.syslog
*
* Then issue the following command to force the syslogd daemon to reread its configuration file: kill -HUP <syslogd's process id>
*
* If a user wants support for logging to file, the filename is defined in mapi.conf in the logfile field.
* For example, logfile=/usr/local/etc/mapi/mapi_logfile
*
* Then, debug messages are printed to file /usr/local/etc/mapi/mapi_logfile.debug
* and general information messages to file /usr/local/etc/mapi/mapi_logfile.info
*/
int set_logging_to_file(char *mapi_conf, int *logging){
int set_logging_to_file(char *mapi_conf, int *log_fd_info, int *log_fd_debug){
char *logfile;
int log_fd = -1;
char *logfile, *logfile_info, *logfile_debug;
int logging = 0;
if(pc_load(mapi_conf)){
logfile = pc_get_param(pc_get_category(""), "logfile"); // get logfile name
if(logfile == NULL) // no support for logging to file
*logging = 0;
logging = 0;
else{ // support for logging to file
*logging = 1;
log_fd = open(logfile, O_WRONLY | O_CREAT | O_LARGEFILE | O_APPEND, S_IRUSR | S_IWUSR);
logfile_info = (char *)malloc(strlen(logfile) + 6);
logfile_debug = (char *)malloc(strlen(logfile) + 7);
strcpy(logfile_info, logfile);
strcat(logfile_info, ".info"); // logfilename.info
strcpy(logfile_debug, logfile);
strcat(logfile_debug, ".debug"); // logfilename.debug
logging = 1;
*log_fd_info = open(logfile_info, O_WRONLY | O_CREAT | O_LARGEFILE | O_APPEND, S_IRUSR | S_IWUSR);
if(*log_fd_info == -1){
printf("Error in opening file: %s (%s)\n", logfile_info, strerror(errno));
logging = 0;
}
*log_fd_debug = open(logfile_debug, O_WRONLY | O_CREAT | O_LARGEFILE | O_APPEND, S_IRUSR | S_IWUSR);
if(log_fd == -1){
printf("Error in opening file: %s (%s)\n", logfile, strerror(errno));
*logging = 0;
if(*log_fd_debug == -1){
printf("Error in opening file: %s (%s)\n", logfile_debug, strerror(errno));
logging = 0;
}
free(logfile_info);
free(logfile_debug);
}
if(*logging) printf("logging to file: enabled - LogFile: %s\n", logfile);
if(logging) printf("logging to file: enabled - LogFile: %s\n", logfile);
else printf("logging to file: disabled\n");
pc_close();
}
return log_fd;
return logging;
}
long acquire_write_lock(int log_fd){
......@@ -195,27 +220,75 @@ void write_libraries(int log_fd, char *path){
return;
}
void daemon_started(int log_fd, char *daemon, char daemonize, int onlydevgroup){
long file_size;
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "\t\t\t%s was started at ", daemon);
write_date(log_fd);
if(daemonize) write_to_file(log_fd, " ( is running as daemon )");
if(onlydevgroup) write_to_file(log_fd, " - ( is binding limited set of devices (aka devgroup) )");
write_newline(log_fd, "\n\n");
if(strcmp(daemon, "MAPICOMMD") == 0){
#ifdef DIMAPISSL
write_to_file(log_fd, "SSL enabled\n");
#endif
}
release_write_lock(log_fd, file_size);
return;
}
void daemon_terminated(int log_fd, char *daemon, char daemonize, int onlydevgroup){
long file_size;
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "\n\t\t\t%s was terminated at ", daemon);
write_date(log_fd);
if(daemonize) write_to_file(log_fd, " ( was running as daemon )");
if(onlydevgroup) write_to_file(log_fd, " - ( was binding limited set of devices (aka devgroup) )");
write_newline(log_fd, "\n\n");
release_write_lock(log_fd, file_size);
close(log_fd);
return;
}
/* log_level = 0 ---> Log only general information and not debugging messages
* log_level = 1 ---> Log general information plus debugging information (debug messages are printed to stdout and syslog)
* log_level = 2 ---> Log general information plus debugging information (debug messages are printed only to syslog)
* log_level = 1 ---> Log general information plus debugging information (debug messages are printed to stdout, syslog and logfile)
* log_level = 2 ---> Log general information plus debugging information (debug messages are printed to syslog and logfile)
*
* For all the above log levels, debug and/or info messages are printed to syslog and logfile,
* if logging to syslog is enabled and logging to file is enabled, respectively.
*
* The default level is 2
*/
int set_syslog(char *mapi_conf, char *ident){
int get_log_level(char *mapi_conf){
int log_level = LOGGING_DISABLED;
int log_level = SYSLOG_DISABLED;
if(pc_load(mapi_conf)){
log_level = atoi(pc_get_param(pc_get_category(""), "syslog_level")); // TODO check for error values
log_level = atoi(pc_get_param(pc_get_category(""), "log_level")); // TODO check for error values
if(log_level == 0) log_level = LOG_INFORMATION;
else if(log_level == 1) log_level = LOG_INFO_DEBUG_ALL;
else if(log_level == 2) log_level = LOG_INFO_DEBUG_SYSLOG;
else log_level = LOG_INFO_DEBUG_SYSLOG; // default level
else if(log_level == 2) log_level = LOG_INFO_DEBUG_NOT_STDOUT;
else log_level = LOG_INFO_DEBUG_NOT_STDOUT; // default level
pc_close ();
}
return log_level;
}
void open_syslog(int log_level, char *ident){
if(log_level == LOG_INFORMATION){
......@@ -223,13 +296,13 @@ int set_syslog(char *mapi_conf, char *ident){
openlog(ident, LOG_CONS | LOG_NDELAY, LOG_LOCAL1);
}
else if(log_level == LOG_INFO_DEBUG_ALL || log_level == LOG_INFO_DEBUG_SYSLOG){
else if(log_level == LOG_INFO_DEBUG_ALL || log_level == LOG_INFO_DEBUG_NOT_STDOUT){
setlogmask(LOG_MASK(LOG_DEBUG) | LOG_MASK(LOG_INFO));
openlog(ident, LOG_CONS | LOG_NDELAY, LOG_LOCAL1);
}
return log_level;
return;
}
void log_message(char *msg, ...){
......
#ifndef LOG_H
#define LOG_H
#define SYSLOG_DISABLED -1
#define LOG_INFORMATION 0
#define LOG_INFO_DEBUG_ALL 1
#define LOG_INFO_DEBUG_SYSLOG 2
#define LOGGING_DISABLED -1
#define LOG_INFORMATION 0
#define LOG_INFO_DEBUG_ALL 1
#define LOG_INFO_DEBUG_NOT_STDOUT 2
#define STD_BUF 1024
int set_logging_to_file(char *mapi_conf, int *logging);
int set_logging_to_file(char *mapi_conf, int *log_fd_info, int *log_fd_debug);
long acquire_write_lock(int log_fd);
void release_write_lock(int log_fd, long prev_file_size);
void write_newline(int log_fd, char *msg);
void write_to_file(int log_fd, char *msg, ...);
void write_date(int log_fd);
void write_libraries(int log_fd, char *path);
void daemon_started(int log_fd, char *daemon, char daemonize, int onlydevgroup);
void daemon_terminated(int log_fd, char *daemon, char daemonize, int onlydevgroup);
#ifdef DIMAPI
void mapicommd_logging(int log_to_file, int log_to_syslog, int log_fd, struct dmapiipcbuf *dbuf, ...);
#endif
int set_syslog(char *mapi_conf, char *ident);
int get_log_level(char *mapi_conf);
void open_syslog(int log_level, char *ident);
void log_message(char *msg, ...);
void syslog_libraries(char *path);
......
......@@ -64,7 +64,7 @@ static int totalflows=0; // number of flows so far (including closed flows)
static int offline_devices;
static int agent=0;
int log_level = SYSLOG_DISABLED;
int log_level, log_to_syslog, log_to_file, log_fd_debug; // support for logging to file & syslog
extern const errorstruct Errors[];
......
......@@ -29,8 +29,8 @@
int service_count;
int dimapi_port;
int log_fd, log_to_file = 0; // support for logging to file
int log_level = SYSLOG_DISABLED, log_to_syslog = 0; // support for logging to syslog
int log_fd_info = -1, log_fd_debug = -1, log_to_file = 0; // support for logging to file & syslog
int log_level = LOGGING_DISABLED, log_to_syslog = 0;
static char daemonize = 0;
......@@ -160,15 +160,18 @@ int main (int argc, char *argv[]){
#ifdef DIMAPISSL
printf("SSL enabled\n");
#endif
log_level = get_log_level(mapi_conf); // get log level from mapi.conf
if(log_to_syslog) // logging to syslog is enabled
log_level = set_syslog(mapi_conf, "MAPICOMMD");
open_syslog(log_level, "MAPICOMMD");
log_fd = set_logging_to_file(mapi_conf, &log_to_file); // support for logging to file
log_to_file = set_logging_to_file(mapi_conf, &log_fd_info, &log_fd_debug); // support for logging to file
if(log_to_syslog == 0 && log_to_file == 0)
log_level = LOGGING_DISABLED;
if(pc_load (mapi_conf)){
if(pc_load (mapi_conf))
dimapi_port = atoi(pc_get_param(pc_get_category(""), "dimapi_port"));
}
else{
printf("Error: cannot load mapi.conf file.\n");
mapicommd_shutdown(1);
......@@ -180,17 +183,8 @@ int main (int argc, char *argv[]){
else printf("logging to syslog: enabled - LogLevel: %d\n", log_level);
if(log_to_file){
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "\t\t\tMAPICOMMD was started at ");
write_date(log_fd);
if(daemonize) write_to_file(log_fd, " ( is running as daemon )");
write_newline(log_fd, "\n\n");
#ifdef DIMAPISSL
write_to_file(log_fd, "SSL enabled\n");
#endif
release_write_lock(log_fd, file_size);
daemon_started(log_fd_info, "MAPICOMMD", daemonize, 0);
daemon_started(log_fd_debug, "MAPICOMMD", daemonize, 0);
}
if(log_to_syslog){
......@@ -276,11 +270,11 @@ int main (int argc, char *argv[]){
printf("<*> got connection from %s\n", inet_ntoa(clnt_addr.sin_addr));
if(log_to_file){
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "MAPICOMMD: mapicommd got connection from * %s * at ", inet_ntoa(clnt_addr.sin_addr));
write_date(log_fd);
write_newline(log_fd, "\n");
release_write_lock(log_fd, file_size);
file_size = acquire_write_lock(log_fd_info);
write_to_file(log_fd_info, "MAPICOMMD: mapicommd got connection from * %s * at ", inet_ntoa(clnt_addr.sin_addr));
write_date(log_fd_info);
write_newline(log_fd_info, "\n");
release_write_lock(log_fd_info, file_size);
}
if(log_to_syslog)
log_message("mapicommd got connection from * %s *", inet_ntoa(clnt_addr.sin_addr));
......@@ -349,9 +343,9 @@ void *handle_request(void *arg) {
sprintf(str, "%d", sock);
#endif
if(log_to_file){
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "MAPICOMMD: new thread %lu, socket number %s\n\n", pthread_self(), str);
release_write_lock(log_fd, file_size);
file_size = acquire_write_lock(log_fd_info);
write_to_file(log_fd_info, "MAPICOMMD: new thread %lu, socket number %s\n\n", pthread_self(), str);
release_write_lock(log_fd_info, file_size);
}
while(1) {
......@@ -365,11 +359,11 @@ void *handle_request(void *arg) {
DEBUG_CMD(Debug_Message("Peer has gone"));
if(log_to_file){
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "MAPICOMMD: Peer has gone at ");
write_date(log_fd);
write_newline(log_fd, "\n");
release_write_lock(log_fd, file_size);
file_size = acquire_write_lock(log_fd_info);
write_to_file(log_fd_info, "MAPICOMMD: Peer has gone at ");
write_date(log_fd_info);
write_newline(log_fd_info, "\n");
release_write_lock(log_fd_info, file_size);
}
break;
}
......@@ -382,9 +376,9 @@ void *handle_request(void *arg) {
DEBUG_CMD(Debug_Message("WARNING: Ignoring invalid message"));
if(log_to_file){
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "MAPICOMMD: Warning - Ignoring invalid message\n");
release_write_lock(log_fd, file_size);
file_size = acquire_write_lock(log_fd_info);
write_to_file(log_fd_info, "MAPICOMMD: Warning - Ignoring invalid message\n");
release_write_lock(log_fd_info, file_size);
}
continue;
}
......@@ -399,11 +393,11 @@ void *handle_request(void *arg) {
DEBUG_CMD(Debug_Message("Peer has gone"));
if(log_to_file){
file_size = acquire_write_lock(log_fd);
write_to_file(log_fd, "MAPICOMMD: Peer has gone at ");
write_date(log_fd);
write_newline(log_fd, "\n");
release_write_lock(log_fd, file_size);
file_size = acquire_write_lock(log_fd_info);
write_to_file(log_fd_info, "MAPICOMMD: Peer has gone at ");
write_date(log_fd_info);
write_newline(log_fd_info, "\n");
release_write_lock(log_fd_info, file_size);
}
break;
}
......@@ -431,7 +425,7 @@ void *handle_request(void *arg) {
case CREATE_FLOW:
mapid_result = mapi_create_flow(dbuf->data);
fprintf(stdout,"CREATE_FLOW (%s, %d)\n",dbuf->data, mapid_result);
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, mapid_result);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, mapid_result);
if(mapid_result <0) {
dbuf->cmd = ERROR_ACK;
mapi_read_error(&errno, errorstr);
......@@ -448,7 +442,7 @@ void *handle_request(void *arg) {
case CLOSE_FLOW:
fprintf(stdout,"CLOSE_FLOW (%d)\n",dbuf->fd);
mapid_result = mapi_close_flow(dbuf->fd);
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, mapid_result);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, mapid_result);
if(!mapid_result){
for(i=0;i<ac_fl_size;++i){
if(active_flows[i] == dbuf->fd){
......@@ -462,7 +456,7 @@ void *handle_request(void *arg) {
case CONNECT:
fprintf(stdout,"CONNECT (%d)",dbuf->fd);
mapid_result = mapi_connect(dbuf->fd);
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, mapid_result);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, mapid_result);
if(mapid_result >= 0){
dbuf->cmd = CONNECT_ACK;
fprintf(stdout," OK\n");
......@@ -479,12 +473,12 @@ void *handle_request(void *arg) {
case APPLY_FUNCTION:
fprintf(stdout,"APPLY_FUNCTION\n");
if((( dbuf->fid = getfid(dbuf))!=-1)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = APPLY_FUNCTION_ACK;
dbuf->length = BASIC_SIZE;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = ERROR_ACK;
mapi_read_error(&errno, errorstr);
memcpy(dbuf->data, &errno, sizeof(int));
......@@ -501,7 +495,7 @@ void *handle_request(void *arg) {
}
else{
fprintf(stdout,"mapi_read_results failed...\n");
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = ERROR_ACK;
mapi_read_error(&errno, errorstr);
memcpy(dbuf->data, &errno, sizeof(int));
......@@ -525,12 +519,12 @@ void *handle_request(void *arg) {
case GET_FLOW_INFO:
fprintf(stdout,"GET_FLOW_INFO\n");
if(mapi_get_flow_info(dbuf->fd, &flow_info)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = MAPI_FLOW_INFO_ERR;
dbuf->length = BASIC_SIZE;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = GET_FLOW_INFO_ACK;
memcpy(dbuf->data,&flow_info,sizeof(mapi_flow_info_t));
dbuf->length = BASIC_SIZE+sizeof(mapi_flow_info_t);
......@@ -539,12 +533,12 @@ void *handle_request(void *arg) {
case GET_NEXT_FLOW_INFO:
fprintf(stdout,"GET_NEXT_FLOW_INFO\n");
if(mapi_get_next_flow_info(dbuf->fd, &flow_info)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = MAPI_FLOW_INFO_ERR;
dbuf->length = BASIC_SIZE;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = GET_FLOW_INFO_ACK;
memcpy(dbuf->data,&flow_info,sizeof(mapi_flow_info_t));
dbuf->length = BASIC_SIZE+sizeof(mapi_flow_info_t);
......@@ -553,18 +547,18 @@ void *handle_request(void *arg) {
case GET_DEVICE_INFO:
fprintf(stdout,"GET_DEVICE_INFO\n");
if(mapi_get_flow_info(dbuf->fd, &flow_info)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = GET_DEVICE_INFO_NACK;
dbuf->length = BASIC_SIZE;
}
if(mapi_get_device_info(flow_info.devid, &device_info)<0){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = GET_DEVICE_INFO_NACK;
dbuf->length = BASIC_SIZE;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = GET_DEVICE_INFO_ACK;
memcpy(dbuf->data,&device_info,sizeof(mapi_device_info_t));
dbuf->length = BASIC_SIZE+sizeof(mapi_device_info_t);
......@@ -573,18 +567,18 @@ void *handle_request(void *arg) {
case GET_NEXT_DEVICE_INFO:
fprintf(stdout,"GET_NEXT_DEVICE_INFO\n");
if(mapi_get_flow_info(dbuf->fd, &flow_info)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = GET_DEVICE_INFO_NACK;
dbuf->length = BASIC_SIZE;
}
if(mapi_get_next_device_info(flow_info.devid, &device_info)<0){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = GET_DEVICE_INFO_NACK;
dbuf->length = BASIC_SIZE;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = GET_DEVICE_INFO_ACK;
memcpy(dbuf->data,&device_info,sizeof(mapi_device_info_t));
dbuf->length = BASIC_SIZE+sizeof(mapi_device_info_t);
......@@ -593,12 +587,12 @@ void *handle_request(void *arg) {
case GET_FUNCTION_INFO:
fprintf(stdout,"GET_FUNCTION_INFO\n");
if(mapi_get_function_info(dbuf->fd, dbuf->fid, &funct_info)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = MAPI_FUNCTION_INFO_ERR;
dbuf->length = BASIC_SIZE;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = GET_FUNCTION_INFO_ACK;
memcpy(dbuf->data,&funct_info,sizeof(mapi_function_info_t));
dbuf->length = BASIC_SIZE+sizeof(mapi_function_info_t);
......@@ -607,12 +601,12 @@ void *handle_request(void *arg) {
case GET_NEXT_FUNCTION_INFO:
fprintf(stdout,"GET_NEXT_FUNCTION_INFO\n");
if(mapi_get_next_function_info(dbuf->fd, dbuf->fid, &funct_info)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = MAPI_FUNCTION_INFO_ERR;
dbuf->length = BASIC_SIZE;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = GET_FUNCTION_INFO_ACK;
memcpy(dbuf->data,&funct_info,sizeof(mapi_function_info_t));
dbuf->length = BASIC_SIZE+sizeof(mapi_function_info_t);
......@@ -635,11 +629,11 @@ void *handle_request(void *arg) {
case AUTHENTICATE:
fprintf(stdout, "AUTHENTICATE\n");
if(!agent_authenticate(dbuf)){
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, 0);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, 0);
dbuf->cmd = AUTHENTICATE_ACK;
}
else{
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, -1);
mapicommd_logging(log_to_file, log_to_syslog, log_fd_info, dbuf, -1);
dbuf->cmd = ERROR_ACK;
}
dbuf->length = BASIC_SIZE;
......@@ -648,7 +642,7 @@ void *handle_request(void *arg) {
case MAPI_STATS:
dev=strdup(dbuf->data);
mapid_result = mapi_stats(dev, &stats);
mapicommd_logging(log_to_file, log_to_syslog, log_fd, dbuf, mapid_result);