void teardown(void) { auth_disconnect(); db_disconnect(); config_free(); g_mime_shutdown(); }
int main (int argc, char **argv) { g_mime_init (); testsuite_init (argc, argv); testsuite_start ("indexing"); test_indexing (); testsuite_end (); testsuite_start ("removing"); test_remove (); testsuite_end (); testsuite_start ("removing at an index"); test_remove_at (); testsuite_end (); testsuite_start ("header synchronization"); test_content_type_sync (); test_disposition_sync (); test_address_sync (); testsuite_end (); testsuite_start ("header formatting"); test_header_formatting (); testsuite_end (); g_mime_shutdown (); return testsuite_exit (); }
static void gmime_uninit (void) { g_return_if_fail (_gmime_initialized); g_mime_shutdown(); _gmime_initialized = FALSE; }
int main (int argc, char **argv) { struct rspamd_config *cfg; rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main)); memset (rspamd_main, 0, sizeof (struct rspamd_main)); rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL); cfg = rspamd_config_new (); rspamd_main->cfg = cfg; cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL); cfg->log_type = RSPAMD_LOG_CONSOLE; cfg->log_level = G_LOG_LEVEL_INFO; rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"), &rspamd_main->logger, rspamd_main->server_pool); (void)rspamd_log_open (rspamd_main->logger); g_test_init (&argc, &argv, NULL); cfg->libs_ctx = rspamd_init_libs (); base = event_init (); rspamd_stat_init (cfg, base); if (g_test_verbose ()) { cfg->log_level = G_LOG_LEVEL_DEBUG; rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"), &rspamd_main->logger, rspamd_main->server_pool); (void)rspamd_log_reopen (rspamd_main->logger); } g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger); g_test_add_func ("/rspamd/mem_pool", rspamd_mem_pool_test_func); g_test_add_func ("/rspamd/radix", rspamd_radix_test_func); g_test_add_func ("/rspamd/dns", rspamd_dns_test_func); g_test_add_func ("/rspamd/dkim", rspamd_dkim_test_func); g_test_add_func ("/rspamd/rrd", rspamd_rrd_test_func); g_test_add_func ("/rspamd/upstream", rspamd_upstream_test_func); g_test_add_func ("/rspamd/shingles", rspamd_shingles_test_func); g_test_add_func ("/rspamd/http", rspamd_http_test_func); g_test_add_func ("/rspamd/lua", rspamd_lua_test_func); g_test_add_func ("/rspamd/cryptobox", rspamd_cryptobox_test_func); g_test_add_func ("/rspamd/heap", rspamd_heap_test_func); #if 0 g_test_add_func ("/rspamd/url", rspamd_url_test_func); g_test_add_func ("/rspamd/statfile", rspamd_statfile_test_func); g_test_add_func ("/rspamd/aio", rspamd_async_test_func); #endif g_test_run (); g_mime_shutdown (); rspamd_regexp_library_finalize (); return 0; }
int main (int argc, char **argv) { const char *datadir = "data/filters"; struct stat st; int i; g_mime_init (); testsuite_init (argc, argv); //verbose = 4; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { datadir = argv[i]; break; } } if (i < argc && (stat (datadir, &st) == -1 || !S_ISDIR (st.st_mode))) return 0; testsuite_start ("GMimeFilter"); //test_charset_conversion (datadir, "chinese", "utf-8", "big5"); // Note: utf-8 -> big5 drops characters test_charset_conversion (datadir, "cyrillic", "utf-8", "cp1251"); test_charset_conversion (datadir, "cyrillic", "cp1251", "utf-8"); test_charset_conversion (datadir, "cyrillic", "utf-8", "iso-8859-5"); test_charset_conversion (datadir, "cyrillic", "iso-8859-5", "utf-8"); test_charset_conversion (datadir, "cyrillic", "utf-8", "koi8-r"); test_charset_conversion (datadir, "cyrillic", "koi8-r", "utf-8"); test_charset_conversion (datadir, "japanese", "utf-8", "iso-2022-jp"); test_charset_conversion (datadir, "japanese", "iso-2022-jp", "utf-8"); test_charset_conversion (datadir, "japanese", "utf-8", "shift-jis"); test_charset_conversion (datadir, "japanese", "shift-jis", "utf-8"); test_enriched (datadir, "enriched.txt", "enriched.html"); test_gzip (datadir, "lorem-ipsum.txt"); test_gunzip (datadir, "lorem-ipsum.txt"); test_html (datadir, "html-input.txt", "html-output.blockquote.html", GMIME_FILTER_HTML_BLOCKQUOTE_CITATION); test_html (datadir, "html-input.txt", "html-output.mark.html", GMIME_FILTER_HTML_MARK_CITATION); test_html (datadir, "html-input.txt", "html-output.cite.html", GMIME_FILTER_HTML_CITE); test_smtp_data (datadir, "smtp-input.txt", "smtp-output.txt"); test_windows (datadir, "french-fable.cp1252.txt", "iso-8859-1", "windows-cp1252"); testsuite_end (); g_mime_shutdown (); return testsuite_exit (); }
int main(void) { int nf; g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); Suite *s = dbmail_suite(); SRunner *sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL); nf = srunner_ntests_failed(sr); srunner_free(sr); g_mime_shutdown(); return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(void) { int nf; g_mime_init(0); Suite *s = dbmail_message_suite(); SRunner *sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL); nf = srunner_ntests_failed(sr); srunner_free(sr); g_mime_shutdown(); return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }
GByteArray *gmimex_get_part(gchar *path, guint part_id) { g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); GMimeMessage *message = gmime_message_from_path(path); if (!message) return NULL; GByteArray *attachment = gmime_message_get_part_data(message, part_id); g_object_unref(message); g_mime_shutdown(); return attachment; }
GString *gmimex_get_json(gchar *path, guint content_option) { g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); GMimeMessage *message = gmime_message_from_path(path); if (!message) return NULL; GString *json_message = gmime_message_to_json(message, content_option); g_object_unref(message); g_mime_shutdown(); return json_message; }
/** * For each argument, do the dumping. */ int main( int argc, char *argv[] ) { g_mime_init(0); for( int i = 1; i <argc; i++ ) { dump_mail( argv[i] ); } g_mime_shutdown(); return ( 0 ); }
static gboolean run(const gchar* sfn, const gchar* ofn) { GSList* atoms = parse(sfn); gboolean rv = FALSE; if ( atoms ) { g_mime_init(0); interpret(atoms, ofn); g_mime_shutdown(); rv = TRUE; } return rv; }
void sipe_core_destroy(void) { #ifdef HAVE_NSS /* do nothing. * We don't want accedently switch off NSS possibly used by other plugin - * ssl-nss in Pidgin for example. */ #endif #ifdef HAVE_GMIME g_mime_shutdown(); #endif sip_sec_destroy(); }
int main (int argc, char *argv[]) { gboolean rv; GMimeStream *out_stream; out_stream = g_mime_stream_file_new (stdout); if (argc < 2) { g_printerr ("usage: %s <msg-files>\n", argv[0]); return 1; } setlocale (LC_ALL, ""); g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); if (argc == 2) { g_mime_stream_printf (out_stream, "%%{"); g_mime_stream_printf (out_stream, "path: \"%s\", ", argv[1]); rv = test_file (argv[1], out_stream); g_mime_stream_printf (out_stream, "}"); } else { g_mime_stream_printf (out_stream, "["); int x; for (x = 1; x < argc; x++ ) { /* printf("File: %s\n", argv[x]); */ if (x > 1) { g_mime_stream_printf (out_stream, ", "); } g_mime_stream_printf (out_stream, "%%{"); g_mime_stream_printf (out_stream, "path: \"%s\", ", argv[x]); rv = test_file (argv[x], out_stream); g_mime_stream_printf (out_stream, "}"); } g_mime_stream_printf (out_stream, "]"); } g_mime_shutdown (); /* flush stdout */ g_mime_stream_flush (out_stream); /* free/close the stream */ g_object_unref (out_stream); return rv ? 0 : 1; }
int main (int argc, char *argv[]) { gboolean rv; if (argc != 2) { g_printerr ("usage: %s <msg-file>\n", argv[0]); return 1; } setlocale (LC_ALL, ""); g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); rv = test_file (argv[1]); g_mime_shutdown (); return rv ? 0 : 1; }
int main(int argc, char *argv[]) { serverConfig_t config; int result; g_mime_init(0); g_mime_parser_get_type(); g_mime_stream_get_type(); g_mime_stream_mem_get_type(); g_mime_stream_file_get_type(); g_mime_stream_buffer_get_type(); g_mime_stream_filter_get_type(); g_mime_filter_crlf_get_type(); openlog(PNAME, LOG_PID, LOG_MAIL); memset(&config, 0, sizeof(serverConfig_t)); result = server_getopt(&config, "HTTP", argc, argv); if (result == -1) goto shutdown; if (result == 1) { server_showhelp("dbmail-httpd", "This daemon provides HTTP services."); goto shutdown; } config.cb = Request_cb; result = server_mainloop(&config, "HTTP", "dbmail-httpd"); shutdown: g_mime_shutdown(); config_free(); TRACE(TRACE_INFO, "exit"); return result; }
int main (int argc, char **argv) { const char *datadir = "data/mbox"; char input[256], output[256], *tmp, *p, *q; GMimeStream *istream, *ostream, *mstream, *pstream; GMimeParser *parser; const char *dent; const char *path; struct stat st; GDir *dir; int i; #ifdef ENABLE_MBOX_MATCH int fd; if (mkdir ("./tmp", 0755) == -1 && errno != EEXIST) return 0; #endif g_mime_init (); testsuite_init (argc, argv); path = datadir; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { path = argv[i]; break; } } testsuite_start ("Mbox parser"); if (stat (path, &st) == -1) goto exit; if (S_ISDIR (st.st_mode)) { /* automated testsuite */ p = g_stpcpy (input, path); *p++ = G_DIR_SEPARATOR; p = g_stpcpy (p, "input"); if (!(dir = g_dir_open (input, 0, NULL))) goto exit; *p++ = G_DIR_SEPARATOR; *p = '\0'; q = g_stpcpy (output, path); *q++ = G_DIR_SEPARATOR; q = g_stpcpy (q, "output"); *q++ = G_DIR_SEPARATOR; *q = '\0'; while ((dent = g_dir_read_name (dir))) { if (!g_str_has_suffix (dent, ".mbox")) continue; strcpy (p, dent); strcpy (q, dent); tmp = NULL; parser = NULL; istream = NULL; ostream = NULL; mstream = NULL; pstream = NULL; testsuite_check ("%s", dent); try { if (!(istream = g_mime_stream_fs_open (input, O_RDONLY, 0, NULL))) { throw (exception_new ("could not open `%s': %s", input, g_strerror (errno))); } if (!(ostream = g_mime_stream_fs_open (output, O_RDONLY, 0, NULL))) { throw (exception_new ("could not open `%s': %s", output, g_strerror (errno))); } #ifdef ENABLE_MBOX_MATCH tmp = g_strdup_printf ("./tmp/%s", dent); if ((fd = open (tmp, O_CREAT | O_RDWR | O_TRUNC, 0644)) == -1) { throw (exception_new ("could not open `%s': %s", tmp, g_strerror (errno))); } mstream = g_mime_stream_fs_new (fd); #endif parser = g_mime_parser_new_with_stream (istream); g_mime_parser_set_persist_stream (parser, TRUE); g_mime_parser_set_format (parser, GMIME_FORMAT_MBOX); if (!g_mime_parser_get_persist_stream (parser)) throw (exception_new ("persist stream check failed")); if (g_mime_parser_get_format (parser) != GMIME_FORMAT_MBOX) throw (exception_new ("format check failed")); if (strstr (dent, "content-length") != NULL) { g_mime_parser_set_respect_content_length (parser, TRUE); if (!g_mime_parser_get_respect_content_length (parser)) throw (exception_new ("respect content-length check failed")); } else { g_mime_parser_set_respect_content_length (parser, FALSE); if (g_mime_parser_get_respect_content_length (parser)) throw (exception_new ("respect content-length check failed")); } g_mime_parser_set_header_regex (parser, "^X-Evolution", xevcb, NULL); pstream = g_mime_stream_mem_new (); test_parser (parser, mstream, pstream); #ifdef ENABLE_MBOX_MATCH g_mime_stream_flush (mstream); g_mime_stream_reset (istream); g_mime_stream_reset (mstream); if (!streams_match (istream, mstream)) throw (exception_new ("mboxes do not match for `%s'", dent)); #endif g_mime_stream_reset (ostream); g_mime_stream_reset (pstream); if (!streams_match (ostream, pstream)) throw (exception_new ("summaries do not match for `%s'", dent)); testsuite_check_passed (); #ifdef ENABLE_MBOX_MATCH unlink (tmp); #endif } catch (ex) { if (parser != NULL) testsuite_check_failed ("%s: %s", dent, ex->message); else testsuite_check_warn ("%s: %s", dent, ex->message); } finally; if (mstream != NULL) g_object_unref (mstream); if (pstream != NULL) g_object_unref (pstream); if (istream != NULL) g_object_unref (istream); if (ostream != NULL) g_object_unref (ostream); if (parser != NULL) g_object_unref (parser); g_free (tmp); } g_dir_close (dir); } else if (S_ISREG (st.st_mode)) { /* manually run test on a single file */ if (!(istream = g_mime_stream_fs_open (path, O_RDONLY, 0, NULL))) goto exit; parser = g_mime_parser_new_with_stream (istream); g_mime_parser_set_format (parser, GMIME_FORMAT_MBOX); #ifdef ENABLE_MBOX_MATCH tmp = g_strdup ("./tmp/mbox-test.XXXXXX"); if ((fd = g_mkstemp (tmp)) == -1) { g_object_unref (istream); g_object_unref (parser); g_free (tmp); goto exit; } mstream = g_mime_stream_fs_new (fd); #else mstream = NULL; #endif ostream = g_mime_stream_file_new (stdout); g_mime_stream_file_set_owner ((GMimeStreamFile *) ostream, FALSE); testsuite_check ("user-input mbox: `%s'", path); try { test_parser (parser, mstream, ostream); #ifdef ENABLE_MBOX_MATCH g_mime_stream_reset (istream); g_mime_stream_reset (mstream); if (!streams_match (istream, mstream)) throw (exception_new ("`%s' does not match `%s'", tmp, path)); unlink (tmp); #endif testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("user-input mbox `%s': %s", path, ex->message); } finally; g_object_unref (istream); g_object_unref (ostream); g_object_unref (parser); #ifdef ENABLE_MBOX_MATCH g_object_unref (mstream); g_free (tmp); #endif } else { goto exit; } exit: #ifdef ENABLE_MBOX_MATCH //if ((dir = g_dir_open ("./tmp", 0, NULL))) { // p = g_stpcpy (input, "./tmp"); // *p++ = G_DIR_SEPARATOR; // // while ((dent = g_dir_read_name (dir))) { // strcpy (p, dent); // unlink (input); // } // // g_dir_close (dir); //} //rmdir ("./tmp"); #endif testsuite_end (); g_mime_shutdown (); return testsuite_exit (); }
int main(int argc, char *argv[]) { int opt = 0, opt_prev = 0; int show_help = 0; int result = 0, delete_after_dump = 0, recursive = 0; char *user=NULL, *mailbox=NULL, *outfile=NULL, *basedir=NULL, *search=NULL; openlog(PNAME, LOG_PID, LOG_MAIL); setvbuf(stdout, 0, _IONBF, 0); g_mime_init(0); /* get options */ opterr = 0; /* suppress error message from getopt() */ while ((opt = getopt(argc, argv, "-u:m:o:b:s:dDr" /* Major modes */ "f:qvVh" /* Common options */ )) != -1) { /* The initial "-" of optstring allows unaccompanied * options and reports them as the optarg to opt 1 (not '1') */ if (opt == 1) opt = opt_prev; opt_prev = opt; switch (opt) { /* export specific options */ case 'u': if (optarg && strlen(optarg)) user = optarg; break; case 'm': if (optarg && strlen(optarg)) mailbox = optarg; break; case 'b': if (optarg && strlen(optarg)) basedir = optarg; break; case 'o': if (optarg && strlen(optarg)) outfile = optarg; break; case 'd': delete_after_dump |= 1; break; case 'D': delete_after_dump |= 2; break; case 'r': recursive = 1; break; case 's': if (optarg && strlen(optarg)) search = optarg; else { qerrorf("dbmail-mailbox: -s requires a value\n\n"); result = 1; } break; /* Common options */ case 'f': if (optarg && strlen(optarg) > 0) configFile = optarg; else { qerrorf("dbmail-mailbox: -f requires a filename\n\n"); result = 1; } break; case 'h': show_help = 1; break; case 'q': /* If we get q twice, be really quiet! */ if (quiet) reallyquiet = 1; if (!verbose) quiet = 1; break; case 'v': if (!quiet) verbose = 1; break; case 'V': /* Show the version and return non-zero. */ PRINTF_THIS_IS_DBMAIL; result = 1; break; default: /* printf("unrecognized option [%c], continuing...\n",optopt); */ break; } /* If there's a non-negative return code, * it's time to free memory and bail out. */ if (result) goto freeall; } /* If nothing is happening, show the help text. */ if (!user || (basedir && outfile) || show_help) { do_showhelp(); result = 1; goto freeall; } /* read the config file */ if (config_read(configFile) == -1) { qerrorf("Failed. Unable to read config file %s\n", configFile); result = -1; goto freeall; } SetTraceLevel("DBMAIL"); GetDBParams(); /* open database connection */ if (db_connect() != 0) { qerrorf ("Failed. Could not connect to database (check log)\n"); result = -1; goto freeall; } /* open authentication connection */ if (auth_connect() != 0) { qerrorf("Failed. Could not connect to authentication (check log)\n"); result = -1; goto freeall; } /* Loop over all user accounts if there's a wildcard. */ if (strchr(user, '?') || strchr(user, '*')) { GList *all_users = auth_get_known_users(); GList *matching_users = match_glob_list(user, all_users); GList *users = g_list_first(matching_users); if (!users) { qerrorf("Error: no users matching [%s] were found.\n", user); g_list_destroy(all_users); result = -1; goto freeall; } while (users) { result = do_export(users->data, mailbox, basedir, outfile, search, delete_after_dump, recursive); if (!g_list_next(users)) break; users = g_list_next(users); } g_list_destroy(all_users); g_list_destroy(matching_users); } else { /* No globbing, just run with this one user. */ result = do_export(user, mailbox, basedir, outfile, search, delete_after_dump, recursive); } /* Here's where we free memory and quit. * Be sure that all of these are NULL safe! */ freeall: db_disconnect(); auth_disconnect(); config_free(); g_mime_shutdown(); if (result < 0) qerrorf("Command failed.\n"); return result; }
void teardown(void) { db_disconnect(); g_mime_shutdown(); }
int main (int argc, char **argv) { #ifdef ENABLE_CRYPTO const char *datadir = "data/pgp"; GMimeStream *istream, *ostream; GMimeFilterOpenPGP *filter; GMimeCryptoContext *ctx; const char *what; char *gpg, *key; struct stat st; int i; g_mime_init (); testsuite_init (argc, argv); if (!(gpg = g_find_program_in_path ("gpg2"))) if (!(gpg = g_find_program_in_path ("gpg"))) return EXIT_FAILURE; if (testsuite_setup_gpghome (gpg) != 0) return EXIT_FAILURE; g_free (gpg); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { datadir = argv[i]; break; } } if (i < argc && (stat (datadir, &st) == -1 || !S_ISDIR (st.st_mode))) return 0; testsuite_start ("GnuPG crypto context"); ctx = g_mime_gpg_context_new (); g_mime_crypto_context_set_request_password (ctx, request_passwd); testsuite_check ("GMimeGpgContext::import"); try { key = g_build_filename (datadir, "gmime.gpg.pub", NULL); import_key (ctx, key); g_free (key); key = g_build_filename (datadir, "gmime.gpg.sec", NULL); import_key (ctx, key); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("GMimeGpgContext::import failed: %s", ex->message); return EXIT_FAILURE; } finally; key = g_build_filename (datadir, "gmime.gpg.pub", NULL); testsuite_check ("GMimeGpgContext::export"); try { test_export (ctx, key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("GMimeGpgContext::export failed: %s", ex->message); } finally; g_free (key); istream = g_mime_stream_mem_new (); ostream = g_mime_stream_mem_new (); g_mime_stream_write_string (istream, "this is some cleartext\r\n"); g_mime_stream_reset (istream); what = "GMimeGpgContext::sign"; testsuite_check ("%s", what); try { test_sign (ctx, FALSE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::verify"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_verify (ctx, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (ostream); g_mime_stream_reset (istream); ostream = g_mime_stream_mem_new (); what = "GMimeGpgContext::sign (detached)"; testsuite_check ("%s", what); try { test_sign (ctx, TRUE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::verify (detached)"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_verify_detached (ctx, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (ostream); g_mime_stream_reset (istream); ostream = g_mime_stream_mem_new (); what = "GMimeGpgContext::encrypt"; testsuite_check ("%s", what); try { test_encrypt (ctx, FALSE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::decrypt"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_decrypt (ctx, FALSE, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (ostream); g_mime_stream_reset (istream); ostream = g_mime_stream_mem_new (); what = "GMimeGpgContext::encrypt+sign"; testsuite_check ("%s", what); try { test_encrypt (ctx, TRUE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::decrypt+verify"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_decrypt (ctx, TRUE, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (istream); g_object_unref (ostream); g_object_unref (ctx); filter = (GMimeFilterOpenPGP *) g_mime_filter_openpgp_new (); what = "GMimeFilterOpenPGP::public key block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "gmime.gpg.pub", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_PUBLIC_KEY, 0, 1720); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_mime_filter_reset ((GMimeFilter *) filter); what = "GMimeFilterOpenPGP::private key block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "gmime.gpg.sec", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_PRIVATE_KEY, 0, 1928); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_mime_filter_reset ((GMimeFilter *) filter); what = "GMimeFilterOpenPGP::signed message block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "signed-message.txt", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_SIGNED, 162, 440); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_mime_filter_reset ((GMimeFilter *) filter); what = "GMimeFilterOpenPGP::encrypted message block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "encrypted-message.txt", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_ENCRYPTED, 165, 1084); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (filter); testsuite_end (); g_mime_shutdown (); if (testsuite_destroy_gpghome () != 0) return EXIT_FAILURE; return testsuite_exit (); #else fprintf (stderr, "PGP support not enabled in this build.\n"); return EXIT_SUCCESS; #endif }
/** * Function: main * * The calling convention for this function is: * * wl2kax25 -c targetcall -a ax25port -t timeoutsecs -e emailaddress * * The parameters are: * mycall : my call sign, which MUST be set in wl2k.conf * targetcall: callsign for the RMS * ax25port: name of the ax25 port to use (e.g., sm0) * timeoutsecs: timeout in seconds * emailaddress: email address where the retrieved message will be sent via sendmail * * The targetcall parameter does not support a path yet. */ int main(int argc, char *argv[]) { int s; FILE *fp; unsigned int addrlen = 0; union { struct full_sockaddr_ax25 ax25; struct sockaddr_rose rose; } sockaddr; char *dev; pid_t procID; int sv[2]; int ready; struct pollfd fds[2]; ssize_t len; unsigned char *pbuf; ssize_t byteswritten; static cfg_t cfg; loadconfig(argc, argv, &cfg); g_mime_init(0); setlinebuf(stdout); if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv)) { perror("socketpair"); exit(EXIT_FAILURE); } // Begin AX25 socket code if (ax25_config_load_ports() == 0) fprintf(stderr, "wl2kax25: no AX.25 port data configured\n"); if (cfg.ax25port != NULL) { if ((dev = ax25_config_get_dev(cfg.ax25port)) == NULL) { fprintf(stderr, "wl2kax25: invalid port name - %s\n", cfg.ax25port); return(EXIT_FAILURE); } } if ((s = socket(AF_AX25, SOCK_SEQPACKET, 0)) == -1) { perror("socket"); printf("%d\n", __LINE__); exit(EXIT_FAILURE); } ax25_aton(ax25_config_get_addr(cfg.ax25port), &sockaddr.ax25); ax25_aton(cfg.mycall, &sockaddr.ax25); if (sockaddr.ax25.fsa_ax25.sax25_ndigis == 0) { ax25_aton_entry(ax25_config_get_addr(cfg.ax25port), sockaddr.ax25.fsa_digipeater[0]. ax25_call); sockaddr.ax25.fsa_ax25.sax25_ndigis = 1; } sockaddr.ax25.fsa_ax25.sax25_family = AF_AX25; addrlen = sizeof(struct full_sockaddr_ax25); if (bind(s, (struct sockaddr *) &sockaddr, addrlen) == -1) { perror("bind"); close(s); exit(EXIT_FAILURE); } if (ax25_aton(cfg.targetcall, &sockaddr.ax25) < 0) { close(s); perror("ax25_aton()"); exit(EXIT_FAILURE); } sockaddr.rose.srose_family = AF_AX25; addrlen = sizeof(struct full_sockaddr_ax25); settimeout(cfg.timeoutsecs); if (connect(s, (struct sockaddr *) &sockaddr, addrlen) != 0) { close(s); perror("connect()"); exit(EXIT_FAILURE); } unsettimeout(); printf("Connected to AX.25 stack\n"); fflush(stdout); // End AX25 socket code // Fork a process if ((procID = fork())) { // Parent processing if (-1 == procID) { fprintf(stderr, "fork\n"); exit(EXIT_FAILURE); } close(sv[1]); fds[0].fd = s; fds[0].events = POLLIN; fds[1].fd = sv[0]; fds[1].events = POLLIN; // poll here and feed to the ax25 socket. // Data must be chunked to the appropriate size for (;;) { ready = poll(fds, sizeof(fds)/sizeof(struct pollfd), -1); if (-1 == ready) { if (EINTR == errno) break; close(s); perror("poll"); exit(EXIT_FAILURE); } // Inbound if (fds[0].revents & POLLIN) { len = read(fds[0].fd, axread, sizeof(axread)); if ( len > 0 ) { pbuf = axread; while(len > 0) { byteswritten = write(fds[1].fd, pbuf, MIN(paclen, (size_t)len)); if (byteswritten == 0 || (byteswritten < 0 && errno != EAGAIN)) { fprintf(stderr,"%s error on inbound write: %s)\n", getprogname(), strerror(errno)); break; } pbuf += byteswritten; len -= byteswritten; } } else if (len == 0) { close(s); printf("EOF on ax25 socket, exiting...\n"); exit(EXIT_FAILURE); } } // Outbound if (fds[1].revents & POLLIN) { len = read(fds[1].fd, axwrite, sizeof(axwrite)); if (len > 0 ) { pbuf = axwrite; while(len > 0) { byteswritten = write(fds[0].fd, pbuf, MIN(paclen, (size_t)len)); if (byteswritten == 0 || (byteswritten < 0 && errno != EAGAIN)) { fprintf(stderr,"%s error on outbound write: %s)\n", getprogname(), strerror(errno)); break; } pbuf += byteswritten; len -= byteswritten; } } else if (len == 0) { printf("EOF on child fd, terminating communications loop.\n"); break; } } } printf("Closing ax25 connection\n"); #if 1 { time_t start_time, current_time; bool bax25conn; start_time = time(NULL); /* get current time in seconds */ if ((bax25conn=isax25connected(s)) == TRUE) { printf("Waiting for AX25 peer ... "); while(isax25connected(s)){ current_time = time(NULL); if (difftime(current_time, start_time) > 5) { break; } } if (isax25connected(s)) { printf("timeout\n"); }else { printf("disconnected\n"); } } } #endif g_mime_shutdown(); close(sv[0]); close(s); exit(EXIT_SUCCESS); return 1; } else { // Child processing printf("Child process\n"); close(sv[0]); if ((fp = fdopen(sv[1], "r+b")) == NULL) { close(sv[1]); perror("fdopen()"); _exit(EXIT_FAILURE); } /* set buf size to paclen */ setvbuf(fp, NULL, _IOFBF, paclen); /* * The messages are exchanged in this call * * TODO: The sid sent by the client should contain an NXX, * where NXX represents N followed by two digits of SSID. * This allows the RMS to find the correct registered * user in case the SSID has been changed in the network. */ if(cfg.bVerbose) { printf("Child process calling wl2kexchange()\n"); } settimeout(cfg.timeoutsecs); wl2kexchange(cfg.mycall, cfg.targetcall, fp, fp, cfg.emailaddr); fclose(fp); printf("Child process exiting\n"); _exit(EXIT_SUCCESS); } }
int main (int argc, char **argv) { const char *datadir = "data/streams"; gboolean gen_data = TRUE; char *stream_name = NULL; char path[256], *p; GDir *dir, *outdir; const char *dent; int i; g_mime_init (0); testsuite_init (argc, argv); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { datadir = argv[i]; break; } } testsuite_start ("Stream tests"); p = g_stpcpy (path, datadir); *p++ = G_DIR_SEPARATOR; strcpy (p, "output"); if (!(outdir = g_dir_open (path, 0, NULL))) { if (gen_test_data (datadir, &stream_name) == -1 || !(outdir = g_dir_open (path, 0, NULL))) goto exit; gen_data = FALSE; } p = g_stpcpy (p, "input"); if (!(dir = g_dir_open (path, 0, NULL))) { if (!gen_data || gen_test_data (datadir, &stream_name) == -1 || !(dir = g_dir_open (path, 0, NULL))) { g_dir_close (outdir); goto exit; } gen_data = FALSE; } if (gen_data) { while ((dent = g_dir_read_name (dir))) { if (dent[0] == '.' || !strcmp (dent, "README")) continue; gen_data = FALSE; break; } g_dir_rewind (dir); if (gen_data && gen_test_data (datadir, &stream_name) == -1) goto exit; } *p++ = G_DIR_SEPARATOR; *p = '\0'; while ((dent = g_dir_read_name (dir))) { if (dent[0] == '.' || !strcmp (dent, "README")) continue; test_streams (outdir, datadir, dent); strcpy (p, dent); test_stream_buffer_gets (path); } if (gen_data && stream_name && testsuite_total_errors () == 0) { /* since all tests were successful, unlink the generated test data */ strcpy (p, stream_name); unlink (path); p = g_stpcpy (path, datadir); *p++ = G_DIR_SEPARATOR; p = g_stpcpy (p, "output"); *p++ = G_DIR_SEPARATOR; g_dir_rewind (outdir); while ((dent = g_dir_read_name (outdir))) { if (!strncmp (dent, stream_name, strlen (stream_name))) { strcpy (p, dent); unlink (path); } } g_free (stream_name); } g_dir_close (outdir); g_dir_close (dir); exit: testsuite_end (); g_mime_shutdown (); return testsuite_exit (); }
void sipe_mime_shutdown(void) { g_mime_shutdown(); }
/** * Function: main * * The calling convention for this function is: * * wl2ktelnet -c targetcall -t timeoutsecs -e emailaddress -p password HOSTNAME PORT * * The parameters are: * mycall : my call sign, which MUST be set in wl2k.conf * targetcall: callsign for the telnet server (WL2K) * timeoutsecs: timeout in seconds * emailaddress: email address where the retrieved message will be sent via sendmail * password of the telnet host (CMSTelnet) * hostname of the telnet host (server.winlink.org) * port to be used for the telnet host (8772) * */ int main(int argc, char *argv[]) { struct hostent *host; int s; struct sockaddr_in s_in; FILE *fp; char *line; static cfg_t cfg; loadconfig(argc, argv, &cfg); g_mime_init(0); setlinebuf(stdout); if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("socket()"); exit(EXIT_FAILURE); } memset(&s_in, '\0', sizeof(struct sockaddr_in)); #if HAVE_SOCKADDR_IN_SIN_LEN s_in.sin_len = sizeof(struct sockaddr_in); #endif s_in.sin_family = AF_INET; s_in.sin_addr.s_addr = inet_addr(cfg.hostname); if ((int) s_in.sin_addr.s_addr == -1) { host = gethostbyname(cfg.hostname); if (host) { memcpy(&s_in.sin_addr.s_addr, host->h_addr, (unsigned) host->h_length); } else { herror(cfg.hostname); exit(EXIT_FAILURE); } } s_in.sin_port = htons((unsigned short)cfg.hostport); printf("Connecting to %s %d ...\n", cfg.hostname, cfg.hostport); settimeout(cfg.timeoutsecs); if (connect(s, (struct sockaddr *) &s_in, sizeof(struct sockaddr_in)) != 0) { close(s); perror("connect()"); exit(EXIT_FAILURE); } resettimeout(); printf("Connected.\n"); if ((fp = fdopen(s, "r+b")) == NULL) { close(s); perror("fdopen()"); exit(EXIT_FAILURE); } while ((line = wl2kgetline(fp)) != NULL) { printf("%s", line); if (strncmp("Callsign", line, 8) == 0) { fprintf(fp, ".%s\r\n", cfg.mycall); printf(" %s\n", cfg.mycall); break; } putchar('\n'); } if (line == NULL) { fprintf(stderr, "Connection closed by foreign host.\n"); exit(EXIT_FAILURE); } while ((line = wl2kgetline(fp)) != NULL) { printf("%s\n", line); if (strncmp("Password", line, 8) == 0) { fprintf(fp, "%s\r\n", cfg.password); break; } } if (line == NULL) { fprintf(stderr, "Connection closed by foreign host.\n"); exit(EXIT_FAILURE); } wl2kexchange(cfg.mycall, cfg.targetcall, fp, fp, cfg.emailaddr); fclose(fp); g_mime_shutdown(); exit(EXIT_SUCCESS); return 1; }
int main(int argc, char *argv[]) { int check_integrity = 0; int check_iplog = 0, check_replycache = 0; char *timespec_iplog = NULL, *timespec_replycache = NULL; int vacuum_db = 0, purge_deleted = 0, set_deleted = 0, dangling_aliases = 0, rehash = 0; int show_help = 0; int do_nothing = 1; int is_header = 0; int migrate = 0, migrate_limit = 10000; static struct option long_options[] = { { "rehash", 0, 0, 0 }, { 0, 0, 0, 0 } }; int opt_index = 0; int opt; g_mime_init(0); openlog(PNAME, LOG_PID, LOG_MAIL); setvbuf(stdout, 0, _IONBF, 0); /* get options */ opterr = 0; /* suppress error message from getopt() */ while ((opt = getopt_long(argc, argv, "-acbtl:r:pudsMm:" "i" "f:qnyvVh", long_options, &opt_index)) != -1) { /* The initial "-" of optstring allows unaccompanied * options and reports them as the optarg to opt 1 (not '1') */ switch (opt) { case 0: do_nothing = 0; if (strcmp(long_options[opt_index].name,"rehash")==0) rehash = 1; break; case 'a': /* This list should be kept up to date. */ vacuum_db = 1; purge_deleted = 1; set_deleted = 1; dangling_aliases = 1; check_integrity = 1; is_header = 1; do_nothing = 0; break; case 'c': vacuum_db = 1; do_nothing = 0; break; case 'b': is_header = 1; do_nothing = 0; break; case 'p': purge_deleted = 1; do_nothing = 0; break; case 'd': set_deleted = 1; do_nothing = 0; break; case 's': dangling_aliases = 1; do_nothing = 0; break; case 't': check_integrity = 1; do_nothing = 0; break; case 'u': /* deprecated */ break; case 'l': check_iplog = 1; do_nothing = 0; if (optarg) timespec_iplog = g_strdup(optarg); break; case 'r': check_replycache = 1; do_nothing = 0; if (optarg) timespec_replycache = g_strdup(optarg); break; case 'M': migrate = 1; do_nothing = 0; break; case 'm': if (optarg) migrate_limit = atoi(optarg); break; case 'i': qerrorf("Interactive console is not supported in this release.\n"); return 1; /* Common options */ case 'h': show_help = 1; do_nothing = 0; break; case 'n': no_to_all = 1; break; case 'y': yes_to_all = 1; break; case 'q': /* If we get q twice, be really quiet! */ if (quiet) reallyquiet = 1; if (!verbose) quiet = 1; break; case 'f': if (optarg && strlen(optarg) > 0) configFile = optarg; else { qerrorf("dbmail-util: -f requires a filename\n\n" ); return 1; } break; case 'v': verbose = 1; break; case 'V': PRINTF_THIS_IS_DBMAIL; return 1; default: printf("unrecognized option [%c]\n", optopt); show_help = 1; break; } } if (do_nothing || show_help || (no_to_all && yes_to_all)) { do_showhelp(); return 1; } /* Don't make any changes unless specifically authorized. */ if (!yes_to_all) { qprintf("Choosing dry-run mode. No changes will be made at this time.\n"); no_to_all = 1; } config_read(configFile); SetTraceLevel("DBMAIL"); GetDBParams(); qverbosef("Opening connection to database... \n"); if (db_connect() != 0) { qerrorf("Failed. An error occured. Please check log.\n"); return -1; } qverbosef("Opening connection to authentication... \n"); if (auth_connect() != 0) { qerrorf("Failed. An error occured. Please check log.\n"); return -1; } qverbosef("Ok. Connected.\n"); if (check_integrity) do_check_integrity(); if (purge_deleted) do_purge_deleted(); if (is_header) do_header_cache(); if (set_deleted) do_set_deleted(); if (dangling_aliases) do_dangling_aliases(); if (check_iplog) do_check_iplog(timespec_iplog); if (check_replycache) do_check_replycache(timespec_replycache); if (vacuum_db) do_vacuum_db(); if (rehash) do_rehash(); if (migrate) do_migrate(migrate_limit); if (!has_errors && !serious_errors) { qprintf("\nMaintenance done. No errors found.\n"); } else { qerrorf("\nMaintenance done. Errors were found"); if (serious_errors) { qerrorf(" but not fixed due to failures.\n"); qerrorf("Please check the logs for further details, " "turning up the trace level as needed.\n"); // Indicate that something went really wrong has_errors = 3; } else if (no_to_all) { qerrorf(" but not fixed.\n"); qerrorf("Run again with the '-y' option to " "repair the errors.\n"); // Indicate that the program should be run with -y has_errors = 2; } else if (yes_to_all) { qerrorf(" and fixed.\n"); qerrorf("We suggest running dbmail-util again to " "confirm that all errors were repaired.\n"); // Indicate that the program should be run again has_errors = 1; } } auth_disconnect(); db_disconnect(); config_free(); g_mime_shutdown(); return has_errors; }
int main (int argc, char **argv) { const char *datadir = "data/cat"; struct _StreamPart *list, *tail, *n; gboolean failed = FALSE; gint64 wholelen, left; GMimeStream *whole; guint32 part = 0; gint64 start = 0; char *filename; struct stat st; gint64 len; int fd, i; srand (time (NULL)); g_mime_init (0); testsuite_init (argc, argv); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { datadir = argv[i]; break; } } if (i < argc) { if (stat (datadir, &st) == -1) { if (errno == ENOENT) { g_mkdir_with_parents (datadir, 0755); if (stat (datadir, &st) == -1) return EXIT_FAILURE; } else return EXIT_FAILURE; } if (S_ISREG (st.st_mode)) { /* test a particular input file */ if ((fd = open (argv[i], O_RDONLY, 0)) == -1) return EXIT_FAILURE; filename = g_strdup (argv[i]); whole = g_mime_stream_fs_new (fd); } else if (S_ISDIR (st.st_mode)) { /* use path as test suite data dir */ whole = random_whole_stream (argv[i], &filename); } else { return EXIT_FAILURE; } } else { whole = random_whole_stream (datadir, &filename); } if ((wholelen = g_mime_stream_length (whole)) == -1) { fprintf (stderr, "Error: length of test stream unknown\n"); g_object_unref (whole); return EXIT_FAILURE; } else if (wholelen == 64) { fprintf (stderr, "Error: length of test stream is unsuitable for testing\n"); g_object_unref (whole); return EXIT_FAILURE; } list = NULL; tail = (struct _StreamPart *) &list; left = wholelen; while (left > 0) { len = 1 + (gint64) (left * (rand () / (RAND_MAX + 1.0))); n = g_new (struct _StreamPart, 1); sprintf (n->filename, "%s.%u", filename, part++); n->pstart = (gint64) 0; /* FIXME: we could make this a random offset */ n->pend = n->pstart + len; n->wend = start + len; n->wstart = start; tail->next = n; tail = n; start += len; left -= len; } tail->next = NULL; testsuite_start ("GMimeStreamCat"); for (i = 0; i < G_N_ELEMENTS (checks) && !failed; i++) { testsuite_check (checks[i].what); try { checks[i].check (whole, list, checks[i].bounded); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", checks[i].what, ex->message); failed = TRUE; } finally; } testsuite_end (); while (list != NULL) { n = list->next; if (!failed) unlink (list->filename); g_free (list); list = n; } g_object_unref (whole); if (!failed) unlink (filename); g_free (filename); g_mime_shutdown (); return testsuite_exit (); }