CAMLprim value caml_sqlite3_exec_not_null_no_headers( value v_db, value v_cb, value v_sql) { CAMLparam2(v_db, v_cb); CAMLlocal1(v_exn); callback_with_exn cbx; db_wrap *dbw = Sqlite3_val(v_db); int len = caml_string_length(v_sql) + 1; char *sql; int rc; check_db(dbw, "exec_not_null_no_headers"); sql = caml_stat_alloc(len); memcpy(sql, String_val(v_sql), len); cbx.cbp = &v_cb; cbx.exn = &v_exn; caml_enter_blocking_section(); rc = sqlite3_exec( dbw->db, sql, exec_not_null_no_headers_callback, (void *) &cbx, NULL); free(sql); caml_leave_blocking_section(); if (rc == SQLITE_ABORT) { if (*cbx.exn != 0) caml_raise(*cbx.exn); else raise_sqlite3_Error("Null element in row"); } CAMLreturn(Val_rc(rc)); }
int main(int argc, char **argv) { int errs=0; GWEN_GUI *gui; gui=GWEN_Gui_CGui_new(); GWEN_Gui_SetCheckCertFn(gui, checkCert); GWEN_Gui_SetGui(gui); if (check_db()) errs++; #ifdef GWENHYWFAR_SKIP_NETWORK_CHECKS fprintf(stderr, "Skipping all checks that assume available network connectivity\n" "Run ./configure without --disable-network-checks to enable the skipped checks\n"); #else if (check_syncio_tls()) errs++; if (check_syncio_http()) errs++; if (check_syncio_https()) errs++; #endif if (errs) return 2; return 0; }
CAMLprim value caml_sqlite3_exec(value v_db, value v_maybe_cb, value v_sql) { CAMLparam1(v_db); CAMLlocal2(v_cb, v_exn); callback_with_exn cbx; db_wrap *dbw = Sqlite3_val(v_db); int len = caml_string_length(v_sql) + 1; char *sql; int rc; sqlite3_callback cb = NULL; check_db(dbw, "exec"); sql = caml_stat_alloc(len); memcpy(sql, String_val(v_sql), len); cbx.cbp = &v_cb; cbx.exn = &v_exn; if (v_maybe_cb != Val_None) { v_cb = Field(v_maybe_cb, 0); cb = exec_callback; } caml_enter_blocking_section(); rc = sqlite3_exec(dbw->db, sql, cb, (void *) &cbx, NULL); free(sql); caml_leave_blocking_section(); if (rc == SQLITE_ABORT) caml_raise(*cbx.exn); CAMLreturn(Val_rc(rc)); }
CAMLprim value caml_sqlite3_close(value v_db) { int ret, not_busy; db_wrap *dbw = Sqlite3_val(v_db); check_db(dbw, "close"); ret = sqlite3_close(dbw->db); not_busy = ret != SQLITE_BUSY; if (not_busy) dbw->db = NULL; return Val_bool(not_busy); }
CAMLprim value caml_sqlite3_prepare(value v_db, value v_sql) { CAMLparam2(v_db, v_sql); char *loc = "prepare"; db_wrap *dbw = Sqlite3_val(v_db); value v_stmt; check_db(dbw, loc); v_stmt = alloc_stmt(dbw); prepare_it(dbw, v_stmt, String_val(v_sql), caml_string_length(v_sql), loc); CAMLreturn(v_stmt); }
Dictionary dictionary_create_lang(const char * lang) { Dictionary dictionary = NULL; object_open(NULL, NULL, NULL); /* Invalidate the directory path cache */ /* If an sql database exists, try to read that. */ if (check_db(lang)) { dictionary = dictionary_create_from_db(lang); } /* Fallback to a plain-text dictionary */ if (NULL == dictionary) { dictionary = dictionary_create_from_file(lang); } return dictionary; }
static int do_command(void) { COMMAND_TABLE *ctp = cmd_table; enum commands mycmd = CMD_HELP; int cmd_len; if (cmdname && strlen(cmdname) == 0) { mycmd = CMD_NEXT; } else { while (ctp->name) { cmd_len = strlen(ctp->name); if (strncmp(ctp->name,cmdname,cmd_len) == 0) { mycmd = ctp->cmd; break; } ctp++; } } switch (mycmd) { case CMD_CREATE_TDB: bIterate = 0; create_tdb(arg1); return 0; case CMD_OPEN_TDB: bIterate = 0; open_tdb(arg1); return 0; case CMD_SYSTEM: /* Shell command */ if (system(arg1) == -1) { terror("system() call failed\n"); } return 0; case CMD_QUIT: return 1; default: /* all the rest require a open database */ if (!tdb) { bIterate = 0; terror("database not open"); help(); return 0; } switch (mycmd) { case CMD_TRANSACTION_START: bIterate = 0; tdb_transaction_start(tdb); return 0; case CMD_TRANSACTION_COMMIT: bIterate = 0; tdb_transaction_commit(tdb); return 0; case CMD_REPACK: bIterate = 0; tdb_repack(tdb); return 0; case CMD_TRANSACTION_CANCEL: bIterate = 0; tdb_transaction_cancel(tdb); return 0; case CMD_ERASE: bIterate = 0; tdb_traverse(tdb, do_delete_fn, NULL); return 0; case CMD_DUMP: bIterate = 0; tdb_traverse(tdb, print_rec, NULL); return 0; case CMD_INSERT: bIterate = 0; insert_tdb(arg1, arg1len,arg2,arg2len); return 0; case CMD_MOVE: bIterate = 0; move_rec(arg1,arg1len,arg2); return 0; case CMD_STORE: bIterate = 0; store_tdb(arg1,arg1len,arg2,arg2len); return 0; case CMD_SHOW: bIterate = 0; show_tdb(arg1, arg1len); return 0; case CMD_KEYS: tdb_traverse(tdb, print_key, NULL); return 0; case CMD_HEXKEYS: tdb_traverse(tdb, print_hexkey, NULL); return 0; case CMD_DELETE: bIterate = 0; delete_tdb(arg1,arg1len); return 0; case CMD_LIST_HASH_FREE: tdb_dump_all(tdb); return 0; case CMD_LIST_FREE: tdb_printfreelist(tdb); return 0; case CMD_FREELIST_SIZE: { int size; size = tdb_freelist_size(tdb); if (size < 0) { printf("Error getting freelist size.\n"); } else { printf("freelist size: %d\n", size); } return 0; } case CMD_INFO: info_tdb(); return 0; case CMD_SPEED: speed_tdb(arg1); return 0; case CMD_MMAP: toggle_mmap(); return 0; case CMD_FIRST: bIterate = 1; first_record(tdb, &iterate_kbuf); return 0; case CMD_NEXT: if (bIterate) next_record(tdb, &iterate_kbuf); return 0; case CMD_CHECK: check_db(tdb); return 0; case CMD_HELP: help(); return 0; case CMD_CREATE_TDB: case CMD_OPEN_TDB: case CMD_SYSTEM: case CMD_QUIT: /* * unhandled commands. cases included here to avoid compiler * warnings. */ return 0; } } return 0; }
/* process HTTP or SSDP requests */ int main(int argc, char **argv) { int ret, i; int sudp = -1, shttpl = -1; int snotify[MAX_LAN_ADDR]; LIST_HEAD(httplisthead, upnphttp) upnphttphead; struct upnphttp * e = 0; struct upnphttp * next; fd_set readset; /* for select() */ fd_set writeset; struct timeval timeout, timeofday, lastnotifytime = {0, 0}; time_t lastupdatetime = 0; int max_fd = -1; int last_changecnt = 0; pid_t scanner_pid = 0; pthread_t inotify_thread = 0; #ifdef TIVO_SUPPORT uint8_t beacon_interval = 5; int sbeacon = -1; struct sockaddr_in tivo_bcast; struct timeval lastbeacontime = {0, 0}; #endif for (i = 0; i < L_MAX; i++) log_level[i] = E_WARN; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); setlocale(LC_CTYPE, "en_US.utf8"); DPRINTF(E_DEBUG, L_GENERAL, "Using locale dir %s\n", bindtextdomain("minidlna", getenv("TEXTDOMAINDIR"))); textdomain("minidlna"); #endif ret = init(argc, argv); if (ret != 0) return 1; DPRINTF(E_WARN, L_GENERAL, "Starting " SERVER_NAME " version " MINIDLNA_VERSION ".\n"); if (sqlite3_libversion_number() < 3005001) { DPRINTF(E_WARN, L_GENERAL, "SQLite library is old. Please use version 3.5.1 or newer.\n"); } LIST_INIT(&upnphttphead); ret = open_db(NULL); if (ret == 0) { updateID = sql_get_int_field(db, "SELECT VALUE from SETTINGS where KEY = 'UPDATE_ID'"); if (updateID == -1) ret = -1; } check_db(db, ret, &scanner_pid); signal(SIGCHLD, &sigchld); #ifdef HAVE_INOTIFY if( GETFLAG(INOTIFY_MASK) ) { if (!sqlite3_threadsafe() || sqlite3_libversion_number() < 3005001) DPRINTF(E_ERROR, L_GENERAL, "SQLite library is not threadsafe! " "Inotify will be disabled.\n"); else if (pthread_create(&inotify_thread, NULL, start_inotify, NULL) != 0) DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() failed for start_inotify. EXITING\n"); } #endif for (i = 0; i < n_lan_addr; i++) { DPRINTF(E_INFO, L_GENERAL, "Enabled interface %s/%s\n", lan_addr[i].str, inet_ntoa(lan_addr[i].mask)); } sudp = OpenAndConfSSDPReceiveSocket(); if (sudp < 0) { DPRINTF(E_INFO, L_GENERAL, "Failed to open socket for receiving SSDP. Trying to use MiniSSDPd\n"); if (SubmitServicesToMiniSSDPD(lan_addr[0].str, runtime_vars.port) < 0) DPRINTF(E_FATAL, L_GENERAL, "Failed to connect to MiniSSDPd. EXITING"); } /* open socket for HTTP connections. Listen on the 1st LAN address */ shttpl = OpenAndConfHTTPSocket(runtime_vars.port); if (shttpl < 0) DPRINTF(E_FATAL, L_GENERAL, "Failed to open socket for HTTP. EXITING\n"); DPRINTF(E_WARN, L_GENERAL, "HTTP listening on port %d\n", runtime_vars.port); /* open socket for sending notifications */ if (OpenAndConfSSDPNotifySockets(snotify) < 0) DPRINTF(E_FATAL, L_GENERAL, "Failed to open sockets for sending SSDP notify " "messages. EXITING\n"); #ifdef TIVO_SUPPORT if (GETFLAG(TIVO_MASK)) { DPRINTF(E_WARN, L_GENERAL, "TiVo support is enabled.\n"); /* Add TiVo-specific randomize function to sqlite */ ret = sqlite3_create_function(db, "tivorandom", 1, SQLITE_UTF8, NULL, &TiVoRandomSeedFunc, NULL, NULL); if (ret != SQLITE_OK) DPRINTF(E_ERROR, L_TIVO, "ERROR: Failed to add sqlite randomize function for TiVo!\n"); /* open socket for sending Tivo notifications */ sbeacon = OpenAndConfTivoBeaconSocket(); if(sbeacon < 0) DPRINTF(E_FATAL, L_GENERAL, "Failed to open sockets for sending Tivo beacon notify " "messages. EXITING\n"); tivo_bcast.sin_family = AF_INET; tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress()); tivo_bcast.sin_port = htons(2190); } else sbeacon = -1; #endif SendSSDPGoodbye(snotify, n_lan_addr); /* main loop */ while (!quitting) { /* Check if we need to send SSDP NOTIFY messages and do it if * needed */ if (gettimeofday(&timeofday, 0) < 0) { DPRINTF(E_ERROR, L_GENERAL, "gettimeofday(): %s\n", strerror(errno)); timeout.tv_sec = runtime_vars.notify_interval; timeout.tv_usec = 0; } else { /* the comparison is not very precise but who cares ? */ if (timeofday.tv_sec >= (lastnotifytime.tv_sec + runtime_vars.notify_interval)) { SendSSDPNotifies2(snotify, (unsigned short)runtime_vars.port, (runtime_vars.notify_interval << 1)+10); memcpy(&lastnotifytime, &timeofday, sizeof(struct timeval)); timeout.tv_sec = runtime_vars.notify_interval; timeout.tv_usec = 0; } else { timeout.tv_sec = lastnotifytime.tv_sec + runtime_vars.notify_interval - timeofday.tv_sec; if (timeofday.tv_usec > lastnotifytime.tv_usec) { timeout.tv_usec = 1000000 + lastnotifytime.tv_usec - timeofday.tv_usec; timeout.tv_sec--; } else timeout.tv_usec = lastnotifytime.tv_usec - timeofday.tv_usec; } #ifdef TIVO_SUPPORT if (GETFLAG(TIVO_MASK)) { if (timeofday.tv_sec >= (lastbeacontime.tv_sec + beacon_interval)) { sendBeaconMessage(sbeacon, &tivo_bcast, sizeof(struct sockaddr_in), 1); memcpy(&lastbeacontime, &timeofday, sizeof(struct timeval)); if (timeout.tv_sec > beacon_interval) { timeout.tv_sec = beacon_interval; timeout.tv_usec = 0; } /* Beacons should be sent every 5 seconds or so for the first minute, * then every minute or so thereafter. */ if (beacon_interval == 5 && (timeofday.tv_sec - startup_time) > 60) beacon_interval = 60; } else if (timeout.tv_sec > (lastbeacontime.tv_sec + beacon_interval + 1 - timeofday.tv_sec)) timeout.tv_sec = lastbeacontime.tv_sec + beacon_interval - timeofday.tv_sec; } #endif } if (scanning) { if (!scanner_pid || kill(scanner_pid, 0) != 0) { scanning = 0; updateID++; } } /* select open sockets (SSDP, HTTP listen, and all HTTP soap sockets) */ FD_ZERO(&readset); if (sudp >= 0) { FD_SET(sudp, &readset); max_fd = MAX(max_fd, sudp); } if (shttpl >= 0) { FD_SET(shttpl, &readset); max_fd = MAX(max_fd, shttpl); } #ifdef TIVO_SUPPORT if (sbeacon >= 0) { FD_SET(sbeacon, &readset); max_fd = MAX(max_fd, sbeacon); } #endif i = 0; /* active HTTP connections count */ for (e = upnphttphead.lh_first; e != NULL; e = e->entries.le_next) { if ((e->socket >= 0) && (e->state <= 2)) { FD_SET(e->socket, &readset); max_fd = MAX(max_fd, e->socket); i++; } } #ifdef DEBUG /* for debug */ if (i > 1) DPRINTF(E_DEBUG, L_GENERAL, "%d active incoming HTTP connections\n", i); #endif FD_ZERO(&writeset); upnpevents_selectfds(&readset, &writeset, &max_fd); ret = select(max_fd+1, &readset, &writeset, 0, &timeout); if (ret < 0) { if(quitting) goto shutdown; if(errno == EINTR) continue; DPRINTF(E_ERROR, L_GENERAL, "select(all): %s\n", strerror(errno)); DPRINTF(E_FATAL, L_GENERAL, "Failed to select open sockets. EXITING\n"); } upnpevents_processfds(&readset, &writeset); /* process SSDP packets */ if (sudp >= 0 && FD_ISSET(sudp, &readset)) { /*DPRINTF(E_DEBUG, L_GENERAL, "Received UDP Packet\n");*/ ProcessSSDPRequest(sudp, (unsigned short)runtime_vars.port); } #ifdef TIVO_SUPPORT if (sbeacon >= 0 && FD_ISSET(sbeacon, &readset)) { /*DPRINTF(E_DEBUG, L_GENERAL, "Received UDP Packet\n");*/ ProcessTiVoBeacon(sbeacon); } #endif /* increment SystemUpdateID if the content database has changed, * and if there is an active HTTP connection, at most once every 2 seconds */ if (i && (timeofday.tv_sec >= (lastupdatetime + 2))) { if (scanning || sqlite3_total_changes(db) != last_changecnt) { updateID++; last_changecnt = sqlite3_total_changes(db); upnp_event_var_change_notify(EContentDirectory); lastupdatetime = timeofday.tv_sec; } } /* process active HTTP connections */ for (e = upnphttphead.lh_first; e != NULL; e = e->entries.le_next) { if ((e->socket >= 0) && (e->state <= 2) && (FD_ISSET(e->socket, &readset))) Process_upnphttp(e); } /* process incoming HTTP connections */ if (shttpl >= 0 && FD_ISSET(shttpl, &readset)) { int shttp; socklen_t clientnamelen; struct sockaddr_in clientname; clientnamelen = sizeof(struct sockaddr_in); shttp = accept(shttpl, (struct sockaddr *)&clientname, &clientnamelen); if (shttp<0) { DPRINTF(E_ERROR, L_GENERAL, "accept(http): %s\n", strerror(errno)); } else { struct upnphttp * tmp = 0; DPRINTF(E_DEBUG, L_GENERAL, "HTTP connection from %s:%d\n", inet_ntoa(clientname.sin_addr), ntohs(clientname.sin_port) ); /*if (fcntl(shttp, F_SETFL, O_NONBLOCK) < 0) { DPRINTF(E_ERROR, L_GENERAL, "fcntl F_SETFL, O_NONBLOCK\n"); }*/ /* Create a new upnphttp object and add it to * the active upnphttp object list */ tmp = New_upnphttp(shttp); if (tmp) { tmp->clientaddr = clientname.sin_addr; LIST_INSERT_HEAD(&upnphttphead, tmp, entries); } else { DPRINTF(E_ERROR, L_GENERAL, "New_upnphttp() failed\n"); close(shttp); } } } /* delete finished HTTP connections */ for (e = upnphttphead.lh_first; e != NULL; e = next) { next = e->entries.le_next; if(e->state >= 100) { LIST_REMOVE(e, entries); Delete_upnphttp(e); } } } shutdown: /* kill the scanner */ if (scanning && scanner_pid) kill(scanner_pid, 9); /* close out open sockets */ while (upnphttphead.lh_first != NULL) { e = upnphttphead.lh_first; LIST_REMOVE(e, entries); Delete_upnphttp(e); } if (sudp >= 0) close(sudp); if (shttpl >= 0) close(shttpl); #ifdef TIVO_SUPPORT if (sbeacon >= 0) close(sbeacon); #endif if (SendSSDPGoodbye(snotify, n_lan_addr) < 0) DPRINTF(E_ERROR, L_GENERAL, "Failed to broadcast good-bye notifications\n"); for (i=0; i < n_lan_addr; i++) close(snotify[i]); if (inotify_thread) pthread_join(inotify_thread, NULL); sql_exec(db, "UPDATE SETTINGS set VALUE = '%u' where KEY = 'UPDATE_ID'", updateID); sqlite3_close(db); upnpevents_removeSubscribers(); if (pidfilename && unlink(pidfilename) < 0) DPRINTF(E_ERROR, L_GENERAL, "Failed to remove pidfile %s: %s\n", pidfilename, strerror(errno)); log_close(); freeoptions(); exit(EXIT_SUCCESS); }
int sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) { int rc; char *text, *from; mu_sieve_value_t *val; mu_message_t msg; mu_header_t hdr; char *my_address = mu_sieve_get_daemon_email (mach); if (diag (mach)) return 0; val = mu_sieve_value_get (args, 0); if (!val) { mu_sieve_error (mach, _("cannot get text!")); mu_sieve_abort (mach); } else text = val->v.string; msg = mu_sieve_get_message (mach); mu_message_get_header (msg, &hdr); if (mu_sieve_tag_lookup (tags, "sender", &val)) { /* Debugging hook: :sender sets fake reply address */ from = strdup (val->v.string); if (!from) { mu_sieve_error (mach, "%lu: %s", (unsigned long) mu_sieve_get_message_num (mach), mu_strerror (ENOMEM)); mu_sieve_abort (mach); } } else if (mu_sieve_get_message_sender (msg, &from)) { mu_sieve_error (mach, _("%lu: cannot get sender address"), (unsigned long) mu_sieve_get_message_num (mach)); mu_sieve_abort (mach); } if (mu_sieve_tag_lookup (tags, "aliases", &val) && match_addresses (hdr, val, &my_address) == 0) return 0; if (noreply_address_p (mach, tags, from) || bulk_precedence_p (hdr) || check_db (mach, tags, from)) { free (from); return 0; } rc = vacation_reply (mach, tags, msg, text, from, my_address); free (from); if (rc == -1) mu_sieve_abort (mach); return rc; }
int main(void) { char command[150]; int retval; unsigned int databaseCheck; // compare the consistency of the database (magic page) databaseCheck = check_db(); printf("Database checksum: @d\n", databaseCheck); // load data from the magic page if (loadDB(&airports) == -1) _terminate(-1); while(1) { getline(command, sizeof(command)); retval = execute_cmd(&airports, command); switch (retval) { case COMMAND_OK: printf("OK\n"); break; case BAD_COMMAND: printf("BAD COMMAND FORMAT\n"); break; case DUPLICATE_CODE: printf("AIRPORT CODE EXISTS\n"); break; case UNKN_CODE: printf("UNKNOWN AIRPORT\n"); break; case DATABASE_EMPTY: printf("EMPTY DB\n"); break; case COMMAND_TERMINATED: printf("COMMAND TERMINATED\n"); break; case NO_RESULTS: printf("NO RESULTS\n"); break; case UNRECOVERABLE_ERROR: printf("TERMINATING\n"); _terminate(-1); break; // quit command case -99: printf("OK\n"); break; default: printf("UNSPECIFIED ERROR\n"); } // switch if (retval == -99) break; } // while _terminate(0); } // main
int main(int argc, char **argv) { int argn; FILE *tmpfp; struct rfc2045 *rfcp; struct mimeautoreply_s replyinfo; const char *subj=0; const char *txtfile=0, *mimefile=0; const char *mimedsn=0; int nosend=0; const char *replymode="reply"; int replytoenvelope=0; int donotquote=0; const char *forwardsep="--- Forwarded message ---"; const char *replysalut="%F writes:"; struct rfc2045src *src; setlocale(LC_ALL, ""); charset=unicode_default_chset(); sender=NULL; for (argn=1; argn < argc; argn++) { char optc; char *optarg; if (argv[argn][0] != '-') break; if (strcmp(argv[argn], "--") == 0) { ++argn; break; } optc=argv[argn][1]; optarg=argv[argn]+2; if (!*optarg) optarg=NULL; switch (optc) { case 'c': if (!optarg && argn+1 < argc) optarg=argv[++argn]; if (optarg && *optarg) { char *p=libmail_u_convert_tobuf("", optarg, libmail_u_ucs4_native, NULL); if (!p) { fprintf(stderr, "Unknown charset: %s\n", charset); exit(1); } free(p); charset=optarg; } continue; case 't': if (!optarg && argn+1 < argc) optarg=argv[++argn]; txtfile=optarg; continue; case 'm': if (!optarg && argn+1 < argc) optarg=argv[++argn]; mimefile=optarg; continue; case 'r': if (!optarg && argn+1 < argc) optarg=argv[++argn]; recips=optarg; continue; case 'M': if (!optarg && argn+1 < argc) optarg=argv[++argn]; mimedsn=optarg; continue; case 'd': if (!optarg && argn+1 < argc) optarg=argv[++argn]; dbfile=optarg; continue; case 'e': replytoenvelope=1; continue; case 'T': if (!optarg && argn+1 < argc) optarg=argv[++argn]; if (optarg && *optarg) replymode=optarg; continue; case 'N': donotquote=1; continue; case 'F': if (!optarg && argn+1 < argc) optarg=argv[++argn]; if (optarg && *optarg) forwardsep=optarg; continue; case 'S': if (!optarg && argn+1 < argc) optarg=argv[++argn]; if (optarg && *optarg) replysalut=optarg; continue; case 'D': if (!optarg && argn+1 < argc) optarg=argv[++argn]; interval=optarg ? atoi(optarg):1; continue; case 'A': if (!optarg && argn+1 < argc) optarg=argv[++argn]; if (optarg) { struct header **h; for (h= &extra_headers; *h; h= &(*h)->next) ; if ((*h=malloc(sizeof(struct header))) == 0 || ((*h)->buf=strdup(optarg)) == 0) { perror("malloc"); exit(EX_TEMPFAIL); } (*h)->next=0; } continue; case 's': if (!optarg && argn+1 < argc) optarg=argv[++argn]; subj=optarg; continue; case 'f': if (optarg && *optarg) { sender=strdup(optarg); } else { sender=getenv("SENDER"); if (!sender) continue; sender=strdup(sender); } if (sender == NULL) { perror("malloc"); exit(1); } continue; case 'n': nosend=1; continue; default: usage(); } } if (!txtfile && !mimefile) usage(); if (txtfile && mimefile) usage(); tmpfp=tmpfile(); if (!tmpfp) { perror("tmpfile"); exit(1); } rfcp=savemessage(tmpfp); if (fseek(tmpfp, 0L, SEEK_SET) < 0) { perror("fseek(tempfile)"); exit(1); } read_headers(tmpfp); if (sender == NULL || *sender == 0) check_sender(); check_dsn(); check_recips(); #ifdef DbObj check_db(); #endif src=rfc2045src_init_fd(fileno(tmpfp)); memset(&replyinfo, 0, sizeof(replyinfo)); replyinfo.info.src=src; replyinfo.info.rfc2045partp=rfcp; replyinfo.info.voidarg=&replyinfo; replyinfo.info.write_func=mimeautoreply_write_func; replyinfo.info.writesig_func=mimeautoreply_writesig_func; replyinfo.info.myaddr_func=mimeautoreply_myaddr_func; replyinfo.info.replymode=replymode; replyinfo.info.replytoenvelope=replytoenvelope; replyinfo.info.donotquote=donotquote; replyinfo.info.replysalut=replysalut; replyinfo.info.forwarddescr="Forwarded message"; replyinfo.info.mailinglists=""; replyinfo.info.charset=charset; replyinfo.info.subject=subj; replyinfo.info.forwardsep=forwardsep; if (mimedsn && *mimedsn) { replyinfo.info.dsnfrom=mimedsn; replyinfo.info.replymode="replydsn"; } if (mimefile) { if ((replyinfo.contentf=fopen(mimefile, "r")) == NULL) { perror(mimefile); exit(1); } { struct rfc2045 *rfcp=rfc2045_alloc(); static const char mv[]="Mime-Version: 1.0\n"; char buf[BUFSIZ]; int l; const char *content_type; const char *content_transfer_encoding; const char *charset; rfc2045_parse(rfcp, mv, sizeof(mv)-1); while ((l=fread(buf, 1, sizeof(buf), replyinfo.contentf) ) > 0) { rfc2045_parse(rfcp, buf, l); } if (l < 0 || fseek(replyinfo.contentf, 0L, SEEK_SET) < 0) { perror(mimefile); exit(1); } rfc2045_mimeinfo(rfcp, &content_type, &content_transfer_encoding, &charset); if (strcasecmp(content_type, "text/plain")) { fprintf(stderr, "%s must specify text/plain MIME type\n", mimefile); exit(1); } { char *p=NULL; if (charset) p=libmail_u_convert_tobuf("", charset, libmail_u_ucs4_native, NULL); if (!p) { fprintf(stderr, "Unknown charset in %s\n", mimefile); exit(1); } free(p); replyinfo.info.charset=strdup(charset); } rfc2045_free(rfcp); } replyinfo.info.content_set_charset=copy_headers; replyinfo.info.content_specify=copy_body; } else if (txtfile) { if ((replyinfo.contentf=fopen(txtfile, "r")) == NULL) { perror(mimefile); exit(1); } replyinfo.info.content_specify=copy_body; } if (replyinfo.contentf) fcntl(fileno(replyinfo.contentf), F_SETFD, FD_CLOEXEC); if (nosend) replyinfo.outf=stdout; else { replyinfo.outf=tmpfile(); if (replyinfo.outf == NULL) { perror("tmpfile"); exit(1); } } { struct header *h; for (h=extra_headers; h; h=h->next) fprintf(replyinfo.outf, "%s\n", h->buf); } fprintf(replyinfo.outf, "Precedence: junk\n" "Auto-Submitted: auto-replied\n"); if (rfc2045_makereply(&replyinfo.info) < 0 || fflush(replyinfo.outf) < 0 || ferror(replyinfo.outf) || (!nosend && ( fseek(replyinfo.outf, 0L, SEEK_SET) < 0 || (close(0), dup(fileno(replyinfo.outf))) < 0) )) { perror("tempfile"); exit(1); } fclose(replyinfo.outf); fcntl(0, F_SETFD, 0); rfc2045_free(rfcp); rfc2045src_deinit(src); if (!nosend) opensendmail(argn, argc, argv); return (0); }
CAMLprim value caml_sqlite3_last_insert_rowid(value v_db) { db_wrap *dbw = Sqlite3_val(v_db); check_db(dbw, "last_insert_rowid"); return caml_copy_int64(sqlite3_last_insert_rowid(dbw->db)); }
CAMLprim value caml_sqlite3_errmsg(value v_db) { db_wrap *dbw = Sqlite3_val(v_db); check_db(dbw, "errmsg"); return caml_copy_string(sqlite3_errmsg(dbw->db)); }
CAMLprim value caml_sqlite3_errcode(value v_db) { db_wrap *dbw = Sqlite3_val(v_db); check_db(dbw, "errcode"); return Val_rc(sqlite3_errcode(dbw->db)); }
int auto_check_db(MYSQL* mydb) { return check_db("fscontent","localhost","fscontent",NULL,mydb); }
void *check_db_thread ( void *arg ) { int timerfd = timerfd_create (CLOCK_REALTIME, 0); int check_db_fd = timerfd_create (CLOCK_REALTIME, 0); if ( timerfd == - 1 || check_db_fd == - 1 ) { return ( void * ) NULL; } struct itimerspec tv, check_tv; memset (&tv, 0, sizeof (tv )); memset (&check_tv, 0, sizeof (check_tv )); tv.it_value.tv_sec = 1; tv.it_interval.tv_sec = release_interval; check_tv.it_value.tv_sec = 1; check_tv.it_interval.tv_sec = checkdb_interval; if ( timerfd_settime (timerfd, 0, &tv, NULL) == - 1 || timerfd_settime (check_db_fd, 0, &check_tv, NULL) == - 1 ) { return ( void * ) NULL; } struct pollfd *pfd; pfd = ( struct pollfd * ) calloc ( 3, sizeof ( struct pollfd ) ); if ( pfd == NULL ) { return ( void * ) NULL; } pfd[0].fd = timerfd; pfd[0].events = POLLIN; pfd[1].fd = check_db_fd; pfd[1].events = POLLIN; pfd[2].fd = stop_pipe[0]; pfd[2].events = POLLIN; int ret; uint64_t val; while ( is_running ) { ret = poll ( pfd, 3, - 1 ); if ( ret == - 1 ) { if ( errno == EINTR ) { continue; } continue; } if ( pfd[0].revents & POLLIN ) { read ( timerfd, &val, sizeof ( val ) ); release_file (); } if ( pfd[1].revents & POLLIN ) { read ( check_db_fd, &val, sizeof ( val ) ); check_db ( hosts ); } if ( pfd[2].revents & POLLIN ) { char buf; read ( stop_pipe[0], &buf, 1 ); } } close ( timerfd ); close ( check_db_fd ); delete client; return ( void * ) NULL; }