Esempio n. 1
0
static void
nm_audit_log (NMAuditManager *self, GPtrArray *fields, const char *file,
              guint line, const char *func, gboolean success)
{
#if HAVE_LIBAUDIT
	NMAuditManagerPrivate *priv;
#endif
	char *msg;

	g_return_if_fail (NM_IS_AUDIT_MANAGER (self));

#if HAVE_LIBAUDIT
	priv = NM_AUDIT_MANAGER_GET_PRIVATE (self);

	if (priv->auditd_fd >= 0) {
		msg = build_message (fields, BACKEND_AUDITD);
		audit_log_user_message (priv->auditd_fd, AUDIT_USYS_CONFIG, msg,
		                        NULL, NULL, NULL, success);
		g_free (msg);
	}
#endif

	if (nm_logging_enabled (AUDIT_LOG_LEVEL, LOGD_AUDIT)) {
		msg = build_message (fields, BACKEND_LOG);
		_NMLOG (AUDIT_LOG_LEVEL, LOGD_AUDIT, "%s", msg);
		g_free (msg);
	}
}
Esempio n. 2
0
// ------------------------------------------------------------------------
// Authenticate with RACR host (handshake)
// ------------------------------------------------------------------------
int Racr::handshake(){
    char packet[PACKET_SIZE + 1];

    Serial.println("Starting handshake");
    
    // Build and send the handshake request packet.
    build_message(HANDSHAKE_REQUEST);
    if( !send_packet(_send_buffer, PACKET_SIZE) ){
        Serial.println("Handshake Failed: handshake request send failed");
        return HANDSHAKE_FAILED;
    }

    // Read the response packet from the socket.
    if( !read_packet(packet) ){
        Serial.println("Handshake Failed: could not read packet");
        return HANDSHAKE_FAILED;
    }

    // Authenticate the packet
    if( !auth_packet(packet) ){
        Serial.println("Handshake Sent: packet auth failed");
        return PACKET_AUTH_FAIL;
    }

    // Response was authenticated so lets send the confirmation packet!
    build_message(HANDSHAKE_CONFIRMATION);
    if( !send_packet(_send_buffer, PACKET_SIZE) ){
        Serial.println("Handshake Failure: Send of confirmation failed");
        return HANDSHAKE_FAILED;
    }

    Serial.println("Handshake successful");

    return CONNECTED;
}
Esempio n. 3
0
int handle_cmd(char cmd, char *send_buf, char *handle, Header *header, char *in_buf, int in_len, int *length, int *print) {
   int code = 0;

   switch (toupper(cmd)) {
      case 'M':
         code = build_message(send_buf, handle, header, in_buf, length, print);
         break;
      case 'B':
         *print = 1;
         code = build_broadcast(send_buf, handle, header, in_buf, length);
         break;
      case 'L':
         *print = 0;
         header->flag = 10;
         memcpy(send_buf, header, sizeof(Header));
         *length = sizeof(Header);
         break;
      case 'E':
         *print = 0;
         build_quit(send_buf, header);
         break;
      default:
         *print = 1;
         printf("Invalid command\n");
         code = 1;
         break;
   }
   return code;
}
Esempio n. 4
0
void mytertiarytextcallback(const char* result, size_t result_length, void* extra) { 
  APP_LOG(APP_LOG_LEVEL_DEBUG, result);
  strncpy(s_last_text[querynum], result, sizeof(s_last_text[querynum]));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Got result %d of %d.", querynum, queries[message-1]);
  querynum++;
  APP_LOG(APP_LOG_LEVEL_DEBUG, "About to build message %d of %d.", querynum, queries[message-1]);
  build_message();
}
Esempio n. 5
0
ExceptionUnknownEntity::ExceptionUnknownEntity(
    const char*         entity_name,
    const Entity*       context)
  : StringException(
        build_message(entity_name, context).c_str(),
        entity_name)
  , m_context_path(context->get_path().c_str())
{
}
Esempio n. 6
0
// ------------------------------------------------------------------------
// Send confirmation back to server, confirming the action has been committed
// ------------------------------------------------------------------------
int Racr::send_confirmation(char* packet){
    build_message(RECEIPT_CONFIRMATION);
    if( !send_packet(_send_buffer, PACKET_SIZE) ){
        Serial.println("Packet confirmation could not be sent");
        return FAIL;
    }

    return SUCCESS;
}
Esempio n. 7
0
static void down_handler(ClickRecognizerRef recognizer, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Down button pressed.");
  if (hint_layer) {
    text_layer_destroy(hint_layer);
    hint_layer = NULL;
  } else {
    message = 3;
    querynum = 0;
    build_message();
  }
}
Esempio n. 8
0
	void Simulator::packet_received(UDPConnection::SharedBuffer buf, std::size_t bytes)
	{
		try
		{
			if(bytes >= 10)
			{
				ByteBuffer tmp;
				ByteBuffer & buffer = *buf;
				if(buffer[0] & packets::MSG_ZEROCODED)
				{
					tmp.reserve(8192);
					packets::zero_decode_command(buffer, tmp);
				}
				else
				{
					tmp.assign(buf->begin(), buf->begin() + bytes);
				}
				tmp.swap(buffer);
				
				UInt32 id = 0;
				if(buffer[6] == 0xFF)
				{
					if(buffer[7] == 0xFF)
					{
						id = ( UInt32(buffer[8]) << 8 ) | buffer[9];
					}
					else
					{
						id = 0xFF000000 | buffer[8];
					}
				}
				else
				{
					id = buffer[6];
				}
	
				build_message(*this, m_network, buffer, id);
				
				m_stats.RecvBytes += buffer.size();
				++m_stats.RecvPackets;
			}
		}
		catch(std::exception const & e)
		{
			LOG_ERR << "Exception caught: " << e.what();
		}
		// don't let any exception cross because it might kill the thread		
		catch(...)
		{
			LOG_ERR << "Unknown exception caught.";
		}
	}
Esempio n. 9
0
void RESTHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
                                Poco::Net::HTTPServerResponse &response) {
    if (verbose) {
        std::clog << "HTTP request " << request.getURI() << std::endl;
        std::clog << "Context id: " << client.context_id() << std::endl;
    }
    zmqpp::message msg, reply;
    /// Connect to broker if not connected
    client.connect(broker);
    Poco::URI url(request.getURI());
    Poco::Net::HTMLForm form(request);
    /// Filter by black list
    if (black_list.find(url.getPath()) != black_list.end()) {
        return error_black_list(response);
    }
    if (!build_message(request, form, url, msg)) {
        return error_parse(response);
    }
    if (!client.send_request(msg, reply, (form.has("timeout") ? std::stoi(form.get("timeout")) : timeout))) {
        return error_timeout(response);
    }
    /// Render response
    response.setStatus(Poco::Net::HTTPServerResponse::HTTPStatus::HTTP_OK);
    if (form.get("type", "json") == "json") {
        /// JSON in single line (FastWriter)
        std::string jsonp_callback = form.get("jsonp", form.get("callback", ""));
        Json::Value packet(Json::ValueType::arrayValue);
        response.setContentType("application/json");
        std::ostream &out = response.send();
        if (!jsonp_callback.empty())
            out << jsonp_callback << "(";
        for (size_t part = 0; part < reply.parts(); ++part)
            packet.append(reply.get(part));
        auto txt = writer.write(packet);
        if (txt[txt.size() - 1] == '\n') // Cheat for EOL in serialization
            txt = txt.substr(0, txt.size() - 1);
        out << txt << (!jsonp_callback.empty() ? ")" : "") << std::flush;
    } else {
        /// Plain text wihtout delimiters
        response.setContentType("text/plain");
        std::ostream &out = response.send();
        for (size_t part = 0; part < reply.parts(); ++part)
            out.write((char *) reply.raw_data(part), reply.size(part));
        out.flush();
    }


}
Esempio n. 10
0
std::string Exception::message() const
{
    std::string message;
    
    if(ENABLE_TERMINAL_COLORS)
    {
        message += BOLD_RED;
    }
    
    message += build_message();
    
    if(ENABLE_TERMINAL_COLORS)
    {
        message += RESET;
    }
    
    return message;
}
Esempio n. 11
0
static void dictation_session_callback(DictationSession *session, DictationSessionStatus status, char *transcription, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Got to the callback.");
  if(status == DictationSessionStatusSuccess) {
    // Display the dictated text
    APP_LOG(APP_LOG_LEVEL_DEBUG, transcription);
    strncpy(s_last_text[querynum], transcription, sizeof(s_last_text[querynum]));
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Got transcription %d of %d.", querynum, queries[message-1]);
    querynum++;
    APP_LOG(APP_LOG_LEVEL_DEBUG, "About to build message %d of %d.", querynum, queries[message-1]);
    build_message();
 } else {
    // Display the reason for any error
    snprintf(hint_text, sizeof(hint_text), "Transcription\nfailed.\nError:%d", (int)status);
    if (!hint_layer) {
      Layer *window_layer = window_get_root_layer(window);
      hint_layer = text_layer_create(hint_layer_size);
      text_layer_set_font(hint_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
      text_layer_set_text_alignment(hint_layer, GTextAlignmentCenter);
      layer_add_child(window_layer, text_layer_get_layer(hint_layer));
    }
    text_layer_set_text(hint_layer, hint_text);
  }
}
Esempio n. 12
0
Json SemanticError::json() const {
	return {focus.start.line, focus.start.column, focus.end.line, focus.end.column, build_message(type, parameters)};
}
Esempio n. 13
0
std::string SemanticError::message() const {
	return build_message(type, parameters);
}
Esempio n. 14
0
void
mm_chain (const char *filename)
{
  FILE *in;
  FILE *fptr;
  char line[256], *destination[NUMDEST], outfile[80] = "";
  char *subject[NUMSUB], *t;
  int chain[HOPMAX];
  byte numdest = 0, numsub = 0;
  int post = 0;
  int num_remailers;
  REMAILER remailer_list[256];

  /* The first line of the packet contains the keyword "post" if the
     message is to be posted. In that case we transform "Newsgroups: "
     to "post: ". */

  num_remailers = read_remailer_list (remailer_list);
  chain[0] = 0;
  in = open_mix_file (filename, "r");
  do
    {
      getline (line, sizeof (line), in);
      if ((strileft (line, "To:") || (post && strileft (line, "Newsgroups:"))) && numdest < NUMDEST)
	{
	  destination[numdest] = (char *) calloc (1, DESTSIZE);
	  if (strileft (line, "To:"))
	    {
	      t = line + sizeof ("To:") - 1;
	      while (*t == ' ' || *t == '\t')
		t++;
	      strncpy (destination[numdest], t, DESTSIZE - 1);
	    }
	  else
	    {
	      t = line + sizeof ("Newsgroups:") - 1;
	      while (*t == ' ' || *t == '\t')
		t++;
	      strcpy (destination[numdest], "post: ");
	      strncat (destination[numdest], t, DESTSIZE - sizeof ("post: "));
	    }
	  destination[numdest][DESTSIZE - 1] = '\0';
	  numdest++;
	}
      else if (streq (line, "post:"))
	post = 1;
      else if (strlen (line) >= 2 && numsub < NUMSUB)
	{
	  subject[numsub] = (char *) calloc (1, SUBSIZE);
	  strncpy (subject[numsub], line, SUBSIZE - 1);
	  subject[numsub][SUBSIZE - 1] = '\0';
	  numsub++;
	  if (strileft (line, "Newsgroups:") && !strchr (REQUIRE, 'N'))
	    strcat (REQUIRE, "N");
	}
    }
  while (strlen (line) > 0);

  if (scan_remailer_list (FORWARDTO, chain, remailer_list, num_remailers) < 0)
    return;

  strcpy (outfile, "mail");
  fptr = tempfile (outfile);
  fprintf (fptr, "temp");	/* make sure the file is created */
  fclose (fptr);

  build_message (in, numdest, destination, chain,
		 numsub, subject, outfile, 0,
		 remailer_list, num_remailers, 0);

  if ((fptr = try_open_mix_file (outfile, "r")) != NULL)
    {
      getline (line, sizeof (line), fptr);
      fclose (fptr);
      if (streq (line, "temp"))
	unlink (outfile);
    }
}
Esempio n. 15
0
int
chain_2 (int argc, char *argv[])
{
  FILE *in;
  char line[256], filename[80] = "", *destination[NUMDEST], outfile[80] = "";
  char *subject[NUMSUB], *t;
  int chain[HOPMAX];
  byte numdest = 0, numsub = 0;
  int i, num_remailers, outfileflag = 0;
  REMAILER remailer_list[256];
  int filter = 0, rfcmsg = 0, dummy = 0;

  num_remailers = read_remailer_list (remailer_list);

  chain[0] = 0;

  /* what is in those arguments */
  /* Here is the expected format */
  /* mixmaster [-c][-f][filename][-[o,O] outfile][-to who@where][-s "subject"][-l 1 2 3 4] */
  /* if no outfile given, then pipe to sendmail. outfile = stdout send to stdout */
  for (i = 1; i < argc; i++)
    {
      if (streq (argv[i], "-c"))
	{
	  /* nop */
	}
      else if (strleft (argv[i], "-h") || streq (argv[i], "--help"))
	{
	  /* Print help and exit */
	  printf ("Mixmaster %s (C) Copyright Lance M. Cottrell 1995, 1996\n",
		  VERSION);
	  printf ("Released under the GNU public license. No warranty!\n\n");
	  printf ("Client Mode command line arguments:\n");
	  printf ("mixmaster [-c] [infile] [-f] [-m] [-s subject] [-v 'Header: text' [-v ...]]\n[-n numcopies] [-[o,O] outfile] [-to who@where] [-l 1 2 3 ...]\n");
	  exit (-1);
	}
      else if (streq (argv[i], "-f"))
	{
	  /* set filter mode */
	  filter = 1;
	}
      else if (streq (argv[i], "-m"))
	{
	  filter = 1;
	  rfcmsg = 1;
	}
      else if (streq (argv[i], "-d"))
	{
	  filter = 1;
	  destination[0] = (char *) calloc (1, DESTSIZE);
	  strcpy (destination[0], "null:");
	  numdest = 1;
	  REQUIRE[0] = '\0';
	  REJECT[0] = '\0';
	  dummy = 5 + random_number (11);
	}
      else if (streq (argv[i], "-s"))
	{
	  if (i < argc - 1)
	    i++;
	  subject[numsub] = (char *) calloc (1, SUBSIZE);
	  strcpy (subject[numsub], "Subject: ");
	  strncat (subject[numsub], argv[i], SUBSIZE - sizeof ("Subject: "));
	  numsub++;
	}
      else if (streq (argv[i], "-v"))
	{
	  if (i < argc - 1)
	    i++;
	  subject[numsub] = (char *) calloc (1, SUBSIZE);
	  subject[numsub][0] = 0;
	  strncat (subject[numsub], argv[i], SUBSIZE - 1);
	  numsub++;
	}
      else if (streq (argv[i], "-o") || streq (argv[i], "-O"))
	{
	  if (streq (argv[i], "-O"))
	    outfileflag = 1;	/* add To: line */
	  if (i < argc - 1)
	    i++;
	  if (streq (argv[i], "stdout"))
	    strcpy (outfile, "-");
	  else
	    parse_filename (outfile, argv[i]);
	}
      else if (streq (argv[i], "-n"))
	{
	  if (i < argc - 1)
	    i++;
	  sscanf (argv[i], "%d", &NUMCOPIES);
	}
      else if (streq (argv[i], "-to") && numdest < NUMDEST)
	{
	  if (i < argc - 1)
	    i++;
	  destination[numdest] = (char *) calloc (1, DESTSIZE);
	  strncpy (destination[numdest], argv[i], DESTSIZE - 1);
	  destination[numdest][DESTSIZE - 1] = '\0';
	  chop (destination[numdest]);
	  numdest++;
	}
      else if (streq (argv[i], "-l"))
	{
	  for (i++; i < argc && chain[0] < HOPMAX; i++)
	    if ((chain[++chain[0]] =
		 select_remailer (remailer_list,
				  num_remailers, argv[i])) < 0)
	      exit (-1);	/* Invalid remailer */
	}
      else
	{
	  if (strlen (filename) != 0)
	    {
	      fprintf (errlog, "problem with the command line\n");
	      return (-1);
	    }
	  strncpy (filename, argv[i], sizeof (filename));
	}
    }

  if (numdest == 0 && !rfcmsg)
    {
      if (!filter)
	fprintf (errlog, "Enter final destinations (one per line return when done).\n");
      do
	{
	  if (!filter)
	    fprintf (errlog, "Enter destination :");
	  getline (line, sizeof (line), stdin);
	  if (strlen (line) >= 2 && numdest < NUMDEST)
	    {
	      destination[numdest] = (char *) calloc (1, DESTSIZE);
	      strncpy (destination[numdest], line, DESTSIZE - 1);
	      destination[numdest][DESTSIZE - 1] = '\0';
	      numdest++;
	    }
	}
      while (strlen (line) > 0 || numdest == 0);
    }
  if (numdest == 0 && filter && !rfcmsg)
    exit (-1);			/* no destination and in filter mode */

  if (numsub == 0 && !dummy)
    {
      if (!filter)
	{
	  fprintf (errlog, "Enter message headers (one per line, return when done).\n");
	  fprintf (errlog, "You must include the header name, e.g. 'Subject: foo'\n");
	}
      do
	{
	  if (!filter)
	    fprintf (errlog, "Enter header :");
	  getline (line, sizeof (line), stdin);
	  if (rfcmsg && (strileft (line, "To:") || strileft (line, "Newsgroups:")) && numdest < NUMDEST)
	    {
	      destination[numdest] = (char *) calloc (1, DESTSIZE);
	      if (strileft (line, "To:"))
		{
		  t = line + sizeof ("To:") - 1;
		  while (*t == ' ' || *t == '\t')
		    t++;
		  strncpy (destination[numdest], t, DESTSIZE - 1);
		}
	      else
		{
		  t = line + sizeof ("Newsgroups:") - 1;
		  while (*t == ' ' || *t == '\t')
		    t++;
		  strcpy (destination[numdest], "post: ");
		  strncat (destination[numdest], t, DESTSIZE - sizeof ("post: "));
		}
	      destination[numdest][DESTSIZE - 1] = '\0';
	      numdest++;
	    }
	  else if (strlen (line) > 0 && numsub < NUMSUB)
	    {
	      subject[numsub] = (char *) calloc (1, SUBSIZE);
	      strncpy (subject[numsub], line, SUBSIZE - 1);
	      subject[numsub][SUBSIZE - 1] = '\0';
	      numsub++;
	    }
	}
      while (strlen (line) > 0);
    }

  if (!strchr (REQUIRE, 'N'))
    for (i = 0; i < numdest; i++)
      if (strileft (destination[i], "post:"))
	{
	  strcat (REQUIRE, "N");
	  break;
	}

  if (chain[0] == 0 && strlen (CHAIN))
    if (scan_remailer_list (CHAIN, chain, remailer_list, num_remailers) < 0)
      return (-1);
  if (chain[0] == 0 && dummy)
    {
      while (chain[0] < dummy)
	chain[++chain[0]] = 0;
    }
  if (chain[0] == 0 && !filter)
    {
      get_chain (remailer_list, num_remailers, chain);
    }
  if (chain[0] == 0)
    {
      return (-1);
    }
#if 1
  if ((chain[chain[0]] > 0)
      && check_abilities (remailer_list[chain[chain[0]]].abilities,
			  REQUIRE, REJECT) == 0)
    {
      fprintf (errlog, "Warning: Remailer %s has insufficient capabilities!\n",
	       remailer_list[chain[chain[0]]].shortname);
    }
#else
  while ((chain[chain[0]] > 0)
	 && check_abilities (remailer_list[chain[chain[0]]].abilities,
			     REQUIRE, REJECT) == 0)
    {
      fprintf (errlog, "Remailer %s has insufficient capabilities!\n",
	       remailer_list[chain[chain[0]]].shortname);
      if (!filter)
	{
	  chain[0]--;
	  get_chain (remailer_list, num_remailers, chain);
	}
      else
	exit (-1);
    }
#endif

  /* if file = stdin then I will take stdin */
  if (strlen (filename) == 0 && !filter)
    {
      fprintf (errlog, "Please enter the name of the file to chain: ");
      getline (filename, sizeof (filename), stdin);
    }
  if (streq (filename, "stdin"))
    strcpy (filename, "-");
  parse_filename (line, filename);
  if (dummy)
    in = NULL;
  else if (streq (filename, "-") || strlen (filename) == 0)
    {
      if (!filter)
	fprintf (errlog, "Please enter the message.\n");
      in = stdin;
    }
  else
    in = open_user_file (line, "r");
  /* ok, that should be everything we need to know */

#ifdef DEBUG
  printf ("filtermode %d\n", filter);	/*debug */
  printf ("source file %s\n", filename);	/*debug */
  printf ("#destinations %d\n", numdest);	/*debug */
  for (i = 0; i < numdest; i++)
    printf ("destination %d  %s\n", i, destination[i]);	/*debug */
  for (i = 1; i <= chain[0]; i++)
    printf ("remailer %d\n", chain[i]);	/*debug */
  for (i = 0; i < numsub; i++)
    printf ("header %d  %s\n", i, subject[i]);	/*debug */
#endif

  return (build_message (in, numdest, destination, chain,
			 numsub, subject, outfile, outfileflag,
			 remailer_list, num_remailers, 1));
}
Esempio n. 16
0
/*
 * Builds the message and tries to send it
 * via the specified SMTP server. Returns 0
 * if everything went ok, -1 if someting goes
 * south and sets `global_smtp_error_msg'.
 * If AUTH is required, a dialog will pop up
 * asking the user to authenticate.
 */
int
send_pr(PROBLEM_REPORT *mypr)
{
  smtp_session_t session;
  smtp_message_t message;
  smtp_recipient_t recipient;
  const smtp_status_t *status;
  auth_context_t authctx;
  int noauth = 0;
  char *host = NULL;
  int i = 0;

  enum notify_flags notify = Notify_SUCCESS|Notify_FAILURE;
  FILE *fp;
  char tempfile[FILENAME_MAX + 1];
  char *tmpdir;
  int  tempfd;

  char my_smtp_server[1024];
  char my_recipient[1024];
  char buf[128];

  if (gsp_auth_done != TRUE) {

    my_auth = malloc(sizeof(GSP_AUTH));
    my_auth->username = malloc(1024);
    memset(my_auth->username, 0, 1024);
    my_auth->password = malloc(1024);
    memset(my_auth->password, 0, 1024);

  }

  tmpdir = getenv("TMPDIR");

  memset(tempfile, 0, sizeof(tempfile));

  if (tmpdir != NULL) {

    snprintf(tempfile, FILENAME_MAX, "%s/gtk-send-pr.XXXXXXXX", tmpdir);

  } else {

    snprintf(tempfile, FILENAME_MAX , "/tmp/gtk-send-pr.XXXXXXXX");

  }

  tempfd = mkstemp(tempfile);
  fp = fdopen(tempfd, "w");

  build_message(fp, mypr);

  fclose(fp);

  auth_client_init();
  session = smtp_create_session();
  message = smtp_add_message(session);

  switch (mypr->ssl_mode) {

  case GSP_SSL_NO :

    i = smtp_starttls_enable(session, Starttls_DISABLED);
    break;

  case GSP_SSL_EN :

    i = smtp_starttls_enable(session, Starttls_ENABLED);
    break;

  case GSP_SSL_RE :

    i = smtp_starttls_enable(session, Starttls_REQUIRED);
    break;

  }

  snprintf(my_smtp_server, 1024, "%s:%s", mypr->smtp_server, mypr->smtp_port);

  host = my_smtp_server;

  smtp_set_server(session, host);

  authctx = auth_create_context();
  auth_set_mechanism_flags(authctx, AUTH_PLUGIN_PLAIN, 0);
  auth_set_interact_cb(authctx, authinteract, NULL);

  smtp_set_eventcb(session, event_cb, NULL);

  if (!noauth) {

    smtp_auth_set_context(session, authctx);

  }

  smtp_set_header(message, "From", mypr->originator, mypr->smtp_from);
  smtp_set_header(message, "To", mypr->smtp_rcpt, mypr->smtp_to);
  smtp_set_header(message, "Subject", mypr->smtp_subject);
  smtp_set_header(message, "Message-Id", NULL);
  smtp_set_reverse_path(message, mypr->smtp_from);
  
  fp = fopen(tempfile, "r");

  smtp_set_message_fp(message, fp);

  /* Recipient must be in RFC2821 format */
  snprintf(my_recipient, 1024, "%s", mypr->smtp_to);
  recipient = smtp_add_recipient(message, my_recipient);
  smtp_dsn_set_notify(recipient, notify);

  if (mypr->smtp_cc_num > 0) {

    for (i = 0; i < mypr->smtp_cc_num; i++) {

      smtp_set_header(message, "CC", NULL, mypr->smtp_cc[i]);
      snprintf(my_recipient, 1024, "%s", mypr->smtp_cc[i]);
      recipient = smtp_add_recipient(message, my_recipient);
      smtp_dsn_set_notify(recipient, notify);			

    }

  }

  if (!smtp_start_session(session)) {

    snprintf(global_smtp_error_msg, 1024, "SMTP server problem : %s\n",
	     smtp_strerror(smtp_errno(), buf, sizeof buf));

    status = smtp_message_transfer_status(message);
    smtp_destroy_session(session);
    auth_destroy_context(authctx);
    fclose(fp);
    unlink(tempfile);
    auth_client_exit();

    return(-1);

  } else {

    status = smtp_message_transfer_status(message);

    if (status != NULL) {

      /* Something went wrong... */
      if (status->code >= 400) {

	snprintf(global_smtp_error_msg, 1024, "SMTP server problem : %i %s\n",
		 status->code, status->text);

	smtp_destroy_session(session);
	auth_destroy_context(authctx);
	fclose(fp);
	unlink(tempfile);
	auth_client_exit();

	return(-1);

      }

    }

    smtp_destroy_session(session);
    auth_destroy_context(authctx);
    fclose(fp);
    unlink(tempfile);
    auth_client_exit();

    return(0);

  }

}
Esempio n. 17
0
void parse_error::throw_with(
    const char* msg_before, const char* p, size_t n, const char* msg_after)
{
    throw parse_error(build_message(msg_before, p, n, msg_after));
}
Esempio n. 18
0
void parse_error::throw_with(const char* msg_before, char c, const char* msg_after)
{
    throw parse_error(build_message(msg_before, c, msg_after));
}
Esempio n. 19
0
int main(int argc, char ** argv)
{
  struct mailimf_fields * fields;
  char * text;
  char * filename;
  struct mailmime * message;
  struct mailmime * text_part;
  struct mailmime * file_part;
  int r;
  int col;

  if (argc < 3) {
    printf("syntax: compose-msg \"text\" filename\n");
    return 1;
  }

  fields = build_fields();
  if (fields == NULL)
    goto err;

  message = build_message(fields);
  if (message == NULL)
    goto free_fields;

  text = argv[1];
  text_part = build_body_text(text);
  if (text_part == NULL)
    goto free_message;

  filename = argv[2];
  file_part = build_body_file(filename);
  if (file_part == NULL)
    goto free_text;

  r = mailmime_smart_add_part(message, text_part);
  if (r != MAILIMF_NO_ERROR)
    goto free_file;

  r = mailmime_smart_add_part(message, file_part);
  if (r != MAILIMF_NO_ERROR)
    goto free_file_alone;
  
  col = 0;
  mailmime_write(stdout, &col, message);

  mailmime_free(message);

  return 0;

 free_file_alone:
  mailmime_free(file_part);
  goto free_text;
 free_file:
  mailmime_free(file_part);
 free_text:
  mailmime_free(text_part);
 free_message:
  mailmime_free(message);
  goto err;
 free_fields:
  mailimf_fields_free(fields);
 err:
  printf("error memory\n");
  return 1;
}
/*
 * Metodo principal
 * @param argc Tamaño del comando ejecutado
 * @param argv Contiene el comando ejecutado
 */
int main(int argc, char *argv[])
{
    int sock;                        /* Socket descriptor */
    struct sockaddr_in echoServAddr; /* Echo server address */
    unsigned short echoServPort;     /* Echo server port */
    char *servIP;                    /* Server IP address (dotted quad) */
    char echoString[FILE_SIZE];    /* String to send to echo server */
    char out_buffer[MES_SIZE]; 
    unsigned int echoStringLen;      /* Length of string to echo */
    int bytesRcvd;   /* Bytes read in single recv() 
                                        and total bytes read */

    /* Otras variables para el cifrado */
    char *longClave;
    char *dirCifrado;
    char *nombreArchivoProcesar;


    /* Puerto por defecto */
    echoServPort = 20849;

    /* Verificamos argumentos */
    if (argc < 9 || argc > 11)
        DieWithError("ERROR: Cantidad de argumentos invalidos.\n"
        "   Introduzca: scdax_cli -i <dir_ip> [-p <puerto_scdax_svr>] -c <long_clave> -a <dir_cif> -f <archivo_a_procesar> ");


    int option = 0;
    while((option = getopt(argc, argv,"i:c:a:f:p:")) != -1) 
    {
        switch (option)
        {
            case 'i':
                servIP = optarg;
                break;
            case 'c':
                longClave = optarg;
                int key;
                if (!(key=atoi(longClave)))
                    DieWithError("ERROR: EL VALOR SEGUIDO DE [-c] DEBE SER UN NUMERO ENTERO");
                if ( (key < 1) || (key > 26) )
                    DieWithError("ERROR: EL VALOR SEGUIDO DE [-c] DEBE ESTAR COMPRENDIDO ENTRE 1 Y 27");
                break;
            case 'a':
                dirCifrado = optarg;     
                 if ( !((strcmp("derecha",dirCifrado)==0) || (strcmp("izquierda",dirCifrado)==0)) )
                  DieWithError("ERROR: EL VALOR SEGUIDO DE [-a] DEBE TOMAR LOS VALORES \"izquierda\" O \"derecha\"");

                break;
            case 'f':
                nombreArchivoProcesar = optarg;
                break;
            case 'p':
                if (!(echoServPort = atoi(optarg)))
                  DieWithError("ERROR: EL VALOR SEGUIDO DE [-p] DEBE SER UN NUMERO DE PUERTO");
                break;
            case '?':
                DieWithError("ERROR: Argumentos invalidos.\n"
                "   Introduzca: scdax_cli -i <dir_ip> [-p <puerto_scdax_svr>] -c <long_clave> -a <dir_cif> -f <archivo_a_procesar> ");
                break;
        }
    }


    read_file_process(echoString, nombreArchivoProcesar);

    /* Create a reliable, stream socket using TCP */
    if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
        DieWithError("ERROR FATAL: Falló la creación del socket");

    /* Construct the server address structure */
    memset(&echoServAddr, 0, sizeof(echoServAddr));     /* Zero out structure */
    echoServAddr.sin_family      = AF_INET;             /* Internet address family */
    echoServAddr.sin_addr.s_addr = inet_addr(servIP);   /* Server IP address */
    echoServAddr.sin_port        = htons(echoServPort); /* Server port */

    int intentos = 0;

    while(intentos <= 3)
      if(intentos == 3)
        DieWithError("ERROR FATAL: No pudo ser realizada la conexion con el servidor");
      else if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
      {
        printf("%s\n%s\n", "Intento fallido de conexion con el servidor", "Intentando de nuevo en 5 segundos");
        intentos++;
        sleep(5);
      } else
        break;

    int mode;
    if(isalpha(echoString[0])) mode = 1;
    else mode = 0;

    build_message(mode, longClave, dirCifrado, echoString, out_buffer);
    echoStringLen = strlen(out_buffer);          /* Determine input length */

    /* Send the string to the server */
    if (send(sock, out_buffer, echoStringLen, 0) != echoStringLen)
        DieWithError("ERROR FATAL: El requerimiento no pudo ser enviado al servidor correctamente");

    if ((bytesRcvd = recv(sock, out_buffer, MES_SIZE - 1, 0)) <= 0)
        DieWithError("ERROR FATAL: La respuesta no pudo ser recibida correctamente por el cliente");

    out_buffer[bytesRcvd] = '\0';  /* Terminate the string! */
    
    parse_response(out_buffer, nombreArchivoProcesar);  /* Print a final linefeed */

    close(sock);
    exit(0);
}