Beispiel #1
0
static void
gmime_init (void)
{
	g_return_if_fail (!_gmime_initialized);

#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
	g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
#else
	g_mime_init(0);
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */

	_gmime_initialized = TRUE;
}
Beispiel #2
0
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 ();
}
Beispiel #3
0
int main (int argc, char* argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s MSG_FILE\n", argv[0]);
    return 1;
  }

  g_mime_init(0);

  FILE* fp = fopen(argv[1], "r");
  if (fp == NULL) {
    fprintf(stderr, "Cannot open the file %s\n", argv[1]);
    return 1;
  }

  GMimeStream* stream = g_mime_stream_file_new(fp);
  GMimeParser* parser = g_mime_parser_new_with_stream(stream);
  GMimeMessage* message = g_mime_parser_construct_message(parser);

  if (message == NULL) {
    fprintf(stderr, "Cannot construct message\n");
    return 1;
  }

  printf("Date    : %s\n", g_mime_message_get_date_as_string(message));
  printf("Subject : %s\n", g_mime_message_get_subject(message));
  printf("From    : %s\n", g_mime_message_get_sender(message));
  printf("To      : %s\n", internet_address_list_to_string(
        g_mime_message_get_all_recipients(message), FALSE));

  fclose(fp);
  return 0;
}
Beispiel #4
0
int main(int argc, char **argv) {
  GByteArray *garray;
  GMimeStream *stream;
  GMimeParser *parse;
  GMimeMessage *message;
  char buf[1];
  int len;

  g_mime_init(0);

  garray = g_byte_array_new();
  
  while (!feof(stdin)) {
    len = fread(buf, 1, 1, stdin);
    if (len == 1)
      g_byte_array_append(garray, buf, len);
  }

  stream = g_mime_stream_mem_new_with_byte_array(garray);
  parse = g_mime_parser_new_with_stream(stream);
  message = g_mime_parser_construct_message(parse);

  remove_message(message);

  printf(g_mime_object_to_string((GMimeObject*)message));
  
  g_object_unref(message);
  g_object_unref(parse);
  g_object_unref(stream);

  return 0;
}
Beispiel #5
0
void setup(void)
{
	configure_debug(255,0);
	config_read(configFile);
	GetDBParams();
	db_connect();
	g_mime_init(0);
}
Beispiel #6
0
static int load_module(void)
{
	g_mime_init(0);

	__ast_http_post_load(0);

	return AST_MODULE_LOAD_SUCCESS;
}
Beispiel #7
0
void setup(void)
{
	configure_debug(511,0);
	config_read(configFile);
	GetDBParams();
	db_connect();
	auth_connect();
	g_mime_init(0);
	init_testuser1();
}
Beispiel #8
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;
}
Beispiel #10
0
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;
}
Beispiel #11
0
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;
}
Beispiel #12
0
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;
}
Beispiel #13
0
/**
 * 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 );

}
Beispiel #14
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;
}
Beispiel #15
0
Datei: int.c Projekt: ebcode/weft
int main(int argc, char **argv)
{
  int dirn;
  struct stat stat_buf;
  char *file, *output_file_name;

  g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);

  dirn = parse_args(argc, argv);

  compile_filters();
  compile_words();

  if (0) {
    file = "/mnt/var/spool/news/articles/gmane/discuss/4482";
    output_file_name = get_cache_file_name(file);
    ensure_directory(output_file_name);
    transform_file(file, output_file_name);
    free(output_file_name);
  } else {
  
    for ( ; dirn < argc; dirn++) {
      file = argv[dirn];
      if (stat(file, &stat_buf) == -1) {
	perror("weft loop");
	break;
      }

      picon_number = 0;
      binary_number = 0;

      if (S_ISREG(stat_buf.st_mode)) {
	if (override_output_name)
	  output_file_name = override_output_name;
	else
	  output_file_name = get_cache_file_name(file);
	ensure_directory(output_file_name);
	transform_file(file, output_file_name);
	if (! override_output_name)
	  free(output_file_name);
      } else {
	fprintf(stderr, "%s is not a regular file; skipping.\n", file);
	break;
      }
    }
  }
  exit(0);
}   
Beispiel #16
0
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;
}
Beispiel #17
0
int main (int argc, const char* argv[])
{
	GMimeMessage *message;
	GMimeParser  *parser;
	GMimeStream  *stream;
	const char   *file = argv[1];

	int fd;

	if (argc < 2) {
		printf("No file name given\n");
		return 1;
	}
	
	if (argc == 3) {
		text_only = 1;
		file = argv[2];
	}
	
	g_mime_init(0);
	g_mime_iconv_init();
	
	if ((fd = open(file, O_RDONLY)) == -1) {
		printf("Error opening file %s\n", file);
		return 1;
	}
	
	stream = g_mime_stream_fs_new(fd);
	parser = g_mime_parser_new_with_stream(stream);
	
	g_mime_parser_set_scan_from(parser, FALSE);
	g_object_unref(stream);
	
	message = g_mime_parser_construct_message(parser);
	g_object_unref(parser);
	
	if (message) {
		write_part(message->mime_part);
	} else {
		printf("Error constructing message\n");
		return 1;
	}
	
	g_mime_iconv_shutdown();
	return 0;
}
Beispiel #18
0
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;
}
Beispiel #19
0
static void
init_gmime (void)
{
  GPtrArray *array;
  GSList *fallback_charsets;
  GSList *l;

  g_mime_init(0);

  array = g_ptr_array_new();

  fallback_charsets = mn_conf_get_string_list(MN_CONF_FALLBACK_CHARSETS);

  MN_LIST_FOREACH(l, fallback_charsets)
    {
      const char *charset = l->data;

      if (! strcmp(charset, "user"))
	{
	  const char *user_charset;

	  g_get_charset(&user_charset);
	  g_ptr_array_add(array, g_strdup(user_charset));
	}
      else
	g_ptr_array_add(array, g_strdup(charset));
    }

  mn_g_slist_free_deep(fallback_charsets);

  g_ptr_array_add(array, NULL);	/* canary */

  g_mime_set_user_charsets((const char **) array->pdata);

  /*
   * Note that because of
   * http://bugzilla.gnome.org/show_bug.cgi?id=509434, we do not free
   * the strings of the array (since GMime does not copy them).
   */
  g_ptr_array_free(array, TRUE);
}
Beispiel #20
0
int main(int argc, char **argv) 
{
  int dirn;
  char *group;

  g_mime_init(0);
  read_groups_file();

  dirn = parse_args(argc, argv);
  
  if (dirn < argc) {
    group = argv[dirn];
    printf("Generating NOV file for %s\n", group);
    generate_group(group);
  } else {
    generate_group("gmane.discuss");
    //fprintf(stderr, "No group name given\n");
  }

  exit(0);
}
Beispiel #21
0
void sipe_core_init(void)
{
	srand(time(NULL));
	sip_sec_init();

#ifdef ENABLE_NLS
	SIPE_DEBUG_INFO("bindtextdomain = %s",
			bindtextdomain(PACKAGE_NAME, LOCALEDIR));
	SIPE_DEBUG_INFO("bind_textdomain_codeset = %s",
			bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"));
	textdomain(PACKAGE_NAME);
#endif
#ifdef HAVE_NSS
	if (!NSS_IsInitialized()) {
		NSS_NoDB_Init(".");
		SIPE_DEBUG_INFO_NOFORMAT("NSS initialised");
	}
#endif
#ifdef HAVE_GMIME
	g_mime_init(0);
#endif
}
Beispiel #22
0
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;
}
Beispiel #23
0
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;
}
Beispiel #24
0
/**
 * 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);
  }
}
Beispiel #25
0
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_init(void)
{
	g_mime_init(0);
}
Beispiel #27
0
/* As a special-case, a value of NULL for header_desired will force
 * the entire header to be parsed if it is not parsed already. This is
 * used by the _notmuch_message_file_get_headers_end function. */
const char *
notmuch_message_file_get_header (notmuch_message_file_t *message,
				 const char *header_desired)
{
    int contains;
    char *header, *decoded_value;
    const char *s, *colon;
    int match;
    static int initialized = 0;

    if (! initialized) {
	g_mime_init (0);
	initialized = 1;
    }

    message->parsing_started = 1;

    if (header_desired == NULL)
	contains = 0;
    else
	contains = g_hash_table_lookup_extended (message->headers,
						 header_desired, NULL,
						 (gpointer *) &decoded_value);

    if (contains && decoded_value)
	return decoded_value;

    if (message->parsing_finished)
	return "";

#define NEXT_HEADER_LINE(closure)				\
    while (1) {							\
	ssize_t bytes_read = getline (&message->line,		\
				      &message->line_size,	\
				      message->file);		\
	if (bytes_read == -1) {					\
	    message->parsing_finished = 1;			\
	    break;						\
	}							\
	if (*message->line == '\n') {				\
	    message->parsing_finished = 1;			\
	    break;						\
	}							\
	if (closure &&						\
	    (*message->line == ' ' || *message->line == '\t'))	\
	{							\
	    copy_header_unfolding ((closure), message->line);	\
	}							\
	if (*message->line == ' ' || *message->line == '\t')	\
	    message->header_size += strlen (message->line);	\
	else							\
	    break;						\
    }

    if (message->line == NULL)
	NEXT_HEADER_LINE (NULL);

    while (1) {

	if (message->parsing_finished)
	    break;

	colon = strchr (message->line, ':');

	if (colon == NULL) {
	    message->broken_headers++;
	    /* A simple heuristic for giving up on things that just
	     * don't look like mail messages. */
	    if (message->broken_headers >= 10 &&
		message->good_headers < 5)
	    {
		message->parsing_finished = 1;
		break;
	    }
	    NEXT_HEADER_LINE (NULL);
	    continue;
	}

	message->header_size += strlen (message->line);

	message->good_headers++;

	header = xstrndup (message->line, colon - message->line);

	if (message->restrict_headers &&
	    ! g_hash_table_lookup_extended (message->headers,
					    header, NULL, NULL))
	{
	    free (header);
	    NEXT_HEADER_LINE (NULL);
	    continue;
	}

	s = colon + 1;
	while (*s == ' ' || *s == '\t')
	    s++;

	message->value.len = 0;
	copy_header_unfolding (&message->value, s);

	NEXT_HEADER_LINE (&message->value);

	if (header_desired == 0)
	    match = 0;
	else
	    match = (strcasecmp (header, header_desired) == 0);

	decoded_value = g_mime_utils_header_decode_text (message->value.str);

	g_hash_table_insert (message->headers, header, decoded_value);

	if (match)
	    return decoded_value;
    }

    if (message->parsing_finished) {
        fclose (message->file);
        message->file = NULL;
    }

    if (message->line)
	free (message->line);
    message->line = NULL;

    if (message->value.size) {
	free (message->value.str);
	message->value.str = NULL;
	message->value.size = 0;
	message->value.len = 0;
    }

    /* We've parsed all headers and never found the one we're looking
     * for. It's probably just not there, but let's check that we
     * didn't make a mistake preventing us from seeing it. */
    if (message->restrict_headers && header_desired &&
	! g_hash_table_lookup_extended (message->headers,
					header_desired, NULL, NULL))
    {
	INTERNAL_ERROR ("Attempt to get header \"%s\" which was not\n"
			"included in call to notmuch_message_file_restrict_headers\n",
			header_desired);
    }

    return "";
}
Beispiel #28
0
/**
 * 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;
}
Beispiel #29
0
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 ();
}
Beispiel #30
0
/* As a special-case, a value of NULL for header_desired will force
 * the entire header to be parsed if it is not parsed already. This is
 * used by the _notmuch_message_file_get_headers_end function.
 * Another special case is the Received: header. For this header we
 * want to concatenate all instances of the header instead of just
 * hashing the first instance as we use this when analyzing the path
 * the mail has taken from sender to recipient.
 */
const char *
notmuch_message_file_get_header (notmuch_message_file_t *message,
                                 const char *header_desired)
{
    int contains;
    char *header, *decoded_value, *header_sofar, *combined_header;
    const char *s, *colon;
    int match, newhdr, hdrsofar, is_received;
    static int initialized = 0;

    is_received = (strcmp(header_desired,"received") == 0);

    if (! initialized) {
        g_mime_init (0);
        initialized = 1;
    }

    message->parsing_started = 1;

    if (header_desired == NULL)
        contains = 0;
    else
        contains = g_hash_table_lookup_extended (message->headers,
                   header_desired, NULL,
                   (gpointer *) &decoded_value);

    if (contains && decoded_value)
        return decoded_value;

    if (message->parsing_finished)
        return "";

#define NEXT_HEADER_LINE(closure)				\
    while (1) {							\
	ssize_t bytes_read = getline (&message->line,		\
				      &message->line_size,	\
				      message->file);		\
	if (bytes_read == -1) {					\
	    message->parsing_finished = 1;			\
	    break;						\
	}							\
	if (*message->line == '\n') {				\
	    message->parsing_finished = 1;			\
	    break;						\
	}							\
	if (closure &&						\
	    (*message->line == ' ' || *message->line == '\t'))	\
	{							\
	    copy_header_unfolding ((closure), message->line);	\
	}							\
	if (*message->line == ' ' || *message->line == '\t')	\
	    message->header_size += strlen (message->line);	\
	else							\
	    break;						\
    }

    if (message->line == NULL)
        NEXT_HEADER_LINE (NULL);

    while (1) {

        if (message->parsing_finished)
            break;

        colon = strchr (message->line, ':');

        if (colon == NULL) {
            message->broken_headers++;
            /* A simple heuristic for giving up on things that just
             * don't look like mail messages. */
            if (message->broken_headers >= 10 &&
                    message->good_headers < 5)
            {
                message->parsing_finished = 1;
                break;
            }
            NEXT_HEADER_LINE (NULL);
            continue;
        }

        message->header_size += strlen (message->line);

        message->good_headers++;

        header = xstrndup (message->line, colon - message->line);

        if (message->restrict_headers &&
                ! g_hash_table_lookup_extended (message->headers,
                                                header, NULL, NULL))
        {
            free (header);
            NEXT_HEADER_LINE (NULL);
            continue;
        }

        s = colon + 1;
        while (*s == ' ' || *s == '\t')
            s++;

        message->value.len = 0;
        copy_header_unfolding (&message->value, s);

        NEXT_HEADER_LINE (&message->value);

        if (header_desired == NULL)
            match = 0;
        else
            match = (strcasecmp (header, header_desired) == 0);

        decoded_value = g_mime_utils_header_decode_text (message->value.str);
        header_sofar = (char *)g_hash_table_lookup (message->headers, header);
        /* we treat the Received: header special - we want to concat ALL of
         * the Received: headers we encounter.
         * for everything else we return the first instance of a header */
        if (strcasecmp(header, "received") == 0) {
            if (header_sofar == NULL) {
                /* first Received: header we encountered; just add it */
                g_hash_table_insert (message->headers, header, decoded_value);
            } else {
                /* we need to add the header to those we already collected */
                newhdr = strlen(decoded_value);
                hdrsofar = strlen(header_sofar);
                combined_header = g_malloc(hdrsofar + newhdr + 2);
                strncpy(combined_header,header_sofar,hdrsofar);
                *(combined_header+hdrsofar) = ' ';
                strncpy(combined_header+hdrsofar+1,decoded_value,newhdr+1);
                g_free (decoded_value);
                g_hash_table_insert (message->headers, header, combined_header);
            }
        } else {
            if (header_sofar == NULL) {
                /* Only insert if we don't have a value for this header, yet. */
                g_hash_table_insert (message->headers, header, decoded_value);
            } else {
                free (header);
                g_free (decoded_value);
                decoded_value = header_sofar;
            }
        }
        /* if we found a match we can bail - unless of course we are
         * collecting all the Received: headers */
        if (match && !is_received)
            return decoded_value;
    }

    if (message->parsing_finished) {
        fclose (message->file);
        message->file = NULL;
    }

    if (message->line)
        free (message->line);
    message->line = NULL;

    if (message->value.size) {
        free (message->value.str);
        message->value.str = NULL;
        message->value.size = 0;
        message->value.len = 0;
    }

    /* For the Received: header we actually might end up here even
     * though we found the header (as we force continued parsing
     * in that case). So let's check if that's the header we were
     * looking for and return the value that we found (if any)
     */
    if (is_received)
        return (char *)g_hash_table_lookup (message->headers, "received");

    /* We've parsed all headers and never found the one we're looking
     * for. It's probably just not there, but let's check that we
     * didn't make a mistake preventing us from seeing it. */
    if (message->restrict_headers && header_desired &&
            ! g_hash_table_lookup_extended (message->headers,
                                            header_desired, NULL, NULL))
    {
        INTERNAL_ERROR ("Attempt to get header \"%s\" which was not\n"
                        "included in call to notmuch_message_file_restrict_headers\n",
                        header_desired);
    }

    return "";
}