[examples] Added log functions to filelistc.c and filelistd.c;

master
leonid-ed 8 years ago
parent f63f2398f9
commit 6c9d847cb7

@ -104,6 +104,42 @@ static int __rpcscheck_onclient(sxlink_t *l, int ch_tid, char *description)
return SXE_SUCCESS; return SXE_SUCCESS;
} }
/*
* This function might be used to output log in any format you like.
* In this case it is a prefix with a message type before a message body.
*/
static int __log(const sxlogtype_t type, const char *fmt, ...)
{
int r = 0;
switch(type) {
case SXCRITICAL_LOG:
r += fprintf(stderr, "[CRITICAL] ");
break;
case SXERROR_LOG:
r += fprintf(stderr, "[ERROR] ");
break;
case SXWARNING_LOG:
r += fprintf(stderr, "[WARNING] ");
break;
case SXINFO_LOG:
r += fprintf(stderr, "[INFO] ");
break;
case SXDEBUG_LOG:
r += fprintf(stderr, "[DEBUG] ");
break;
default:
r += fprintf(stderr, "[UNKNOWN] ");
break;
}
va_list arglist;
va_start(arglist, fmt);
r += vfprintf(stderr, fmt, arglist);
va_end(arglist);
return r;
}
/* supplemetary functions to make code more readable */ /* supplemetary functions to make code more readable */
static int __close_dir_stream(sxchnl_t *c, int sid) static int __close_dir_stream(sxchnl_t *c, int sid)
{ {
@ -400,6 +436,9 @@ int main(int argc, char **argv)
lhub = sxhub_create(); /* create sxhub for link creation */ lhub = sxhub_create(); /* create sxhub for link creation */
if(!lhub) return ENOMEM; if(!lhub) return ENOMEM;
/* set sxhub log function */
sxhub_set_logops(lhub, __log);
i = sxhub_setsslserts(lhub, rootca, cert, cert); i = sxhub_setsslserts(lhub, rootca, cert, cert);
if(i) return i; if(i) return i;

@ -151,6 +151,31 @@ static int __secure_check(sxlink_t *l)
return SXE_SUCCESS; return SXE_SUCCESS;
} }
/*
* This function might be used to output log in any format you like.
* In this case it is a prefix with date and time marks before a message body.
*/
static int __log(const sxlogtype_t type, const char *fmt, ...)
{
int r = 0;
time_t timer;
char buffer[26];
struct tm* tm_info;
time(&timer);
tm_info = localtime(&timer);
strftime(buffer, 26, "%Y/%m/%d %H:%M:%S", tm_info);
r += fprintf(stderr, "[%s] ", buffer);
va_list arglist;
va_start(arglist, fmt);
r += vfprintf(stderr, fmt, arglist);
va_end(arglist);
return r;
}
/* Our RPC functions it used to get a message and reply */ /* Our RPC functions it used to get a message and reply */
static int __dir_open(void *m, sexp_t *sx) static int __dir_open(void *m, sexp_t *sx)
{ {
@ -336,6 +361,10 @@ int main(int argc, char **argv)
fprintf(stderr, "Subsystem init failed: %d\n", opt); fprintf(stderr, "Subsystem init failed: %d\n", opt);
return 2; return 2;
} }
/* set sxhub log function */
sxhub_set_logops(sxmphub, __log);
/* set working certificates */ /* set working certificates */
opt = sxhub_setsslserts(sxmphub, rootca, cert, cert); opt = sxhub_setsslserts(sxmphub, rootca, cert, cert);
if(opt) { if(opt) {

Loading…
Cancel
Save