/** * Knowing the user's home directory, TGDB can initialize the logger interface * * \param tgdb * The tgdb context. * * \param logs_dir * The path to the user's logging directory * * \return * -1 on error, or 0 on success */ static int tgdb_initialize_logger_interface(struct tgdb *tgdb, char *logs_dir) { /* Open our cgdb and tgdb io logfiles */ clog_open(CLOG_CGDB_ID, "%s/cgdb_log%d.txt", logs_dir); clog_open(CLOG_GDBIO_ID, "%s/cgdb_gdb_io_log%d.txt", logs_dir); /* Puts cgdb in a mode where it writes a debug log of everything * that is read from gdb. That is basically the entire session. * This info is useful in determining what is going on under tgdb * since the gui is good at hiding that info from the user. * * Change level to CLOG_ERROR to write only error messages. * clog_set_level(CLOG_GDBIO, CLOG_ERROR); */ clog_set_level(CLOG_GDBIO_ID, CLOG_DEBUG); clog_set_fmt(CLOG_GDBIO_ID, CGDB_CLOG_FORMAT); /* General cgdb logging. Only logging warnings and debug messages by default. */ clog_set_level(CLOG_CGDB_ID, CLOG_WARN); clog_set_fmt(CLOG_CGDB_ID, CGDB_CLOG_FORMAT); return 0; }
int main(int argc, char *argv[]) { XMLROOT *root = NULL; XMLNODE *node = NULL; struct cstring *xml_string=NULL; CLOG_INFO *log = NULL; printf("cXML test program\n"); log = clog_open("test.log", clog_getlevel("TRACE"),NULL,0); root = xml_root_new(log); if(0==xml_fread(log, root, argv[1])) { fprintf(stderr, "Something was wrong with the XML File, please check the log!\n"); xml_root_free(log, root); exit(1); } xml_string = xml_node_tostring(log, root->data); if(NULL!=xml_string) { fprintf(stderr, "%s\n", xml_string->string); cstring_free(&xml_string); } xml_root_free(log, root); { // test xml creation functionality.. XMLNODE* tmpx = NULL; XMLNODE* tmpy = NULL; node = xml_node_create(log, NULL, "tickets_container", 17); xml_node_addattribute(log, node, "bob", "3"); tmpx = xml_node_create(log, node, "ticket", 6); tmpy = xml_node_create(log, tmpx, "id", 2); xml_node_adddata(log, tmpy, "3", 1); xml_string = xml_node_tostring(log, node); if(0!=xml_string->length) { fprintf(stderr, "%s\n", xml_string->string); cstring_free(&xml_string); } xml_node_free(log, node); } clog_close(log); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int exit_code=0; CERBFIG* cer_config=NULL; // linked list to store the messages in struct linkedlist* messages=NULL; CXMLROOT* xml_root=NULL; CFILE* file=NULL; CFSYS* cfsys=NULL; // log struct CLOG_INFO* log=NULL; #ifdef MEMWATCH EF_ALIGNMENT=1; EF_PROTECT_BELOW=1; EF_PROTECT_FREE=1; #endif // memory checking // mtrace(); // ########################################################################## // ############=- CHECK CMD LINE PARAMETERS -=############################### // ########################################################################## // start the logging so we can log! if( !(argc==4) ) { fprintf(stderr, "\nUsage:\n%.80s xml_config_file log_level log.txt \n\n", argv[0]); } // ########################################################################## // ############=- Run Test Suite -=########################################## // ########################################################################## #ifndef NOTEST if(1==argc) { CuString *output = CuStringNew(); CuSuite* suite = CuSuiteNew(); printf("Running Test Suite\n"); CuSuiteAddSuite(suite, CuGetSuite()); CuSuiteAddSuite(suite, CuStringGetSuite()); CuSuiteAddSuite(suite, TestSuite__cstring()); CuSuiteAddSuite(suite, TestSuite__cfile()); CuSuiteAddSuite(suite, TestSuite__cxml()); // CuSuiteAddSuite(suite, TestSuite__cmime()); CuSuiteRun(suite); CuSuiteSummary(suite, output); CuSuiteDetails(suite, output); printf("%s\n", output->buffer); CuStringFree(output); CuSuiteFree(suite); return EX_USAGE; } #endif log = clog_open(argv[3], clog_getlevel(argv[2]), NULL, 0); // if we couldn't log to the file, let's log to stderr! if(NULL!=log && NULL==log->s_logfile) { clog_setcallback(log, clog_stderr); clog_setcallbacklevel(log, clog_getlevel(argv[2])); clog(log, CERROR, "Could not log to file, logging to stderr!"); } clog(log, CMARK, "Cerberus v. 2.x build %s Starting", BUILDNUMBER); clog(log, CDEBUG, "CMDLINE: Command line: %.80s %.80s %.80s", argv[0], argv[1], argv[2]); clog(log, CDEBUG, "CMDLINE: Command line arguments check passed"); clog(log, CMARK, "Cerberus Starting..."); // ########################################################################## // ############=- LOAD XML CONFIG FILE -=#################################### // ########################################################################## // parse the XML now clog(log, CDEBUG, "XML: Starting XML config file parsing"); clog(log, CDEBUG, "XML: Creating XML DOM Variable"); xml_root = cxml_root_new(log); clog(log, CDEBUG, "XML: XML DOM Variable Created"); // make a new cer filesystem obj cfsys = cfile_init(0); cer_config = malloc(sizeof(CERBFIG)); memset(cer_config, 0, sizeof(CERBFIG)); cer_config->cfsys = cfsys; exit_code = cer_load_config(log, &xml_root, argv[1], &cer_config); // ########################################################################## // ################=- READ IN FILES -=####################################### // ########################################################################## if(0==exit_code) { CPOP3* pop3 = NULL; char *filename = NULL; messages = linkedlist_new(0); // if there is something in the list, process via pop3 if(NULL!=cer_config->poplist) { exit_code = cer_curl_init(log, &cer_config, cer_config->curl_location); clog(log, CMARK, "Parser is in POP3 mode."); while(NULL!=(pop3=linkedlist_remove_last(cer_config->poplist))) { if(0==exit_code) { if(NULL!=pop3->user && NULL!=pop3->pass) { if(0==cpop3_connect(log, pop3)){ if(0==cpop3_user(log, pop3, pop3->user)) { if(0==cpop3_pass(log, pop3, pop3->pass)) { int x=0; int y=0; x = cpop3_stat(log, pop3); while(y<x && y<cer_config->pop3_max) { if(NULL!=(filename = cpop3_retr(log, pop3, cer_config->tmp_cerbmail->string))) { int pid = 0; linkedlist_add(messages, filename); pid = cer_fork(); if(-1==pid) { clog(log, CDEBUG, "FORK: Could not fork, running straight through"); // if we couldn't fork run the parser and risk killing entire process exit_code = cer_parse_files(log, &cer_config, xml_root, &messages); if(pop3->dele) { if(1==cer_config->pop3_max_delete) { cpop3_dele(log, pop3); } else if(0==exit_code) { cpop3_dele(log, pop3); } } } else if(0==pid) { clog(log, CDEBUG, "FORK: Forked, running file parser"); exit_code = cer_parse_files(log, &cer_config, xml_root, &messages); if(pop3->dele) { if(1==cer_config->pop3_max_delete) { cpop3_dele(log, pop3); } else if(0==exit_code) { cpop3_dele(log, pop3); } } // didn't send quit, just close the fork'd connection cpop3_disconnect(log, pop3); cpop3_free(log, &pop3); // remove the emails from the list that we've processed linkedlist_iterate(messages); while(NULL!=(filename=linkedlist_remove_last(messages))) { free(filename); filename = NULL; } linkedlist_del(cer_config->poplist, free); linkedlist_del(messages, free); goto CLEANUP; } else { // must be the parent process // clean up any forked children that are sitting around clog(log, CDEBUG, "FORK: Forked, am parent waiting for child process"); while(0<(pid=cer_wait4(0, NULL, 0, NULL))) { clog(log, CDEBUG, "WAIT: cleaned up after child %d!", pid); }; } // remove the emails from the list that we've processed linkedlist_iterate(messages); while(NULL!=(filename=linkedlist_remove_last(messages))) { free(filename); filename = NULL; } } ++y; } } } cpop3_quit(log, pop3); cpop3_disconnect(log, pop3); } } else { clog(log, CERROR, "POP3: User or Password was NULL, skipping"); } } cpop3_free(log, &pop3); } linkedlist_del(cer_config->poplist, free); } // otherwise it's stdin else { clog(log, CMARK, "Parser is in PIPE mode, waiting for input"); file = cer_save_input(log, cfsys, cer_config->tmp_cerbmail->string); if(NULL!=file) { filename = strdup(file->filename); linkedlist_add(messages, filename); cfile_close(&file); cfile_free(&file); exit_code = cer_curl_init(log, &cer_config, cer_config->curl_location); if(0==exit_code) { exit_code = cer_parse_files(log, &cer_config, xml_root, &messages); } } } // free the linked list linkedlist_del(messages, free); } // this is above cleanup to keep the forks from clobbering each other cfile_cleanup(&cfsys); CLEANUP: if(NULL!=dl_curl_easy_cleanup) { // clean up the info in cURL dl_curl_easy_cleanup(cer_config->curl); } if(NULL!=dl_curl_global_cleanup) { // close down curl dl_curl_global_cleanup(); } #ifndef WIN32 if(NULL!=dl_curl) { dlclose(dl_curl); dl_curl=NULL; } #endif dl_curl = NULL; dl_curl_formadd=NULL; dl_curl_formfree=NULL; dl_curl_global_init=NULL; dl_curl_easy_init=NULL; dl_curl_easy_setopt=NULL; dl_curl_easy_perform=NULL; dl_curl_easy_cleanup=NULL; dl_curl_global_cleanup=NULL; // free the xml data cxml_root_free(log, &xml_root); if(NULL!=cer_config->xsp) cstring_free(&cer_config->xsp); cstring_free(&cer_config->curl_location); cstring_free(&cer_config->tmp_cerbmail); cstring_free(&cer_config->tmp_cerbmime); // free the optional SSL data cstring_free(&cer_config->curl_cainfo); cstring_free(&cer_config->curl_capath); cer_config->curl_verifyhostpeer = 0; clog(log, CMARK, "Shutting Down"); // close the log file clog_close(log); free(cer_config); cer_config=NULL; return exit_code; }
int main(int argc, char ** argv) { int bytes = 0; CSOCKET* sock=NULL; CLOG_INFO* log=NULL; CSTRING* buf = NULL; // open the logfile log = clog_open("./test_csocket.log", CTRACE, NULL, 0); if(3>argc) { clog(log, CFATAL, "USAGE: %s host user password", argv[0]); clog_close(log); return 1; } // create the new socket sock = csocket_new(log); // initialize the socket csocket_init(log, sock, argv[1], 110); // connect csocket_connect(log, sock); // read/write buf = cstring_new(1024); bytes=csocket_read(log, sock, buf->string, 1024); fprintf(stdout, "%s", buf->string); buf->length=0; memset(buf->string, 0, buf->memsize); cstring_strcat_imp(buf, "USER ", 5); cstring_strcat_imp(buf, argv[2], strlen(argv[2])); cstring_strcat_imp(buf, "\r\n", 2); csocket_write(log, sock, buf->string, buf->length); buf->length=0; memset(buf->string, 0, buf->memsize); bytes=csocket_read(log, sock, buf->string, 1024); fprintf(stdout, "%s", buf->string); buf->length=0; memset(buf->string, 0, buf->memsize); cstring_strcat_imp(buf, "PASS ", 5); cstring_strcat_imp(buf, argv[3], strlen(argv[3])); cstring_strcat_imp(buf, "\r\n", 2); csocket_write(log, sock, buf->string, buf->length); buf->length=0; memset(buf->string, 0, buf->memsize); bytes=csocket_read(log, sock, buf->string, 1024); fprintf(stdout, "%s", buf->string); buf->length=0; memset(buf->string, 0, buf->memsize); cstring_strcat_imp(buf, "STAT\r\n", 6); csocket_write(log, sock, buf->string, buf->length); buf->length=0; memset(buf->string, 0, buf->memsize); bytes=csocket_read(log, sock, buf->string, 1024); fprintf(stdout, "%s", buf->string); buf->length=0; memset(buf->string, 0, buf->memsize); cstring_strcat_imp(buf, "QUIT\r\n", 6); csocket_write(log, sock, buf->string, buf->length); buf->length=0; memset(buf->string, 0, buf->memsize); bytes=csocket_read(log, sock, buf->string, 1024); fprintf(stdout, "%s", buf->string); cstring_free(&buf); // close the connection csocket_close(log, sock); // free the socket csocket_free(log, sock); // close the log clog_close(log); return 0; }