Пример #1
0
void GCDCGraphs::DrawXAxisVals(wxGraphicsContext& dc) {
	Draw* draw = m_draws_wdg->GetSelectedDraw();
	if (draw == NULL) 
		return;
	/* Draw ticks on axis. */
	int i = PeriodMarkShift[draw->GetPeriod()];
	int size = draw->GetValuesTable().size();

	int w, h;
	GetClientSize(&w, &h);
    
	wxDateTime prev_date;
	while (i < size) {
		int x = GetX(i);
		dc.StrokeLine(x, h - m_screen_margins.bottommargin + 1, x, h - m_screen_margins.bottommargin - 1);

		wxDateTime date = draw->GetTimeOfIndex(i);
	
		/* Print date */
		wxString datestring = get_date_string(draw->GetPeriod(), prev_date, date);

		double textw, texth, td, tel;

		dc.GetTextExtent(datestring, &textw, &texth, &td, &tel);
		dc.DrawText(datestring, x - textw / 2, h - m_screen_margins.bottommargin + 1);

		i += TimeIndex::PeriodMult[draw->GetPeriod()];
		prev_date = date;
	}
    
}
Пример #2
0
Файл: error.c Проект: E-LLP/QuIP
void _log_message(QSP_ARG_DECL  const char *msg)
{
	const char *log_time;

	log_time = get_date_string(SINGLE_QSP_ARG);

	if( HAS_PREV_LOG_MSG(THIS_QSP) ){
		if( !strcmp(msg,PREV_LOG_MSG(THIS_QSP)) ){
			INCREMENT_LOG_MSG_COUNT(THIS_QSP);
			return;
		} else {
			unsigned long c;
			if( (c=LOG_MSG_COUNT(THIS_QSP)) > 1 ){
				sprintf(ERROR_STRING,
"%s:  previous message was repeated %ld time%s", log_time,c-1,c==2?"":"s");
				advise(ERROR_STRING);
			}
		}
		rls_str(PREV_LOG_MSG(THIS_QSP));
	} else {
		SET_QS_FLAG_BITS(THIS_QSP,QS_HAS_PREV_LOG_MSG);
	}
	sprintf(ERROR_STRING,"%s:  %s", log_time,msg);
	advise(ERROR_STRING);
	SET_PREV_LOG_MSG(THIS_QSP,savestr(msg));
	SET_LOG_MSG_COUNT(THIS_QSP,1);
}
Пример #3
0
static std::unique_ptr<std::ostream> get_demostream(const PingusLevel& plf)
{
  std::string flat_levelname = plf.get_resname();

  // 'Flatten' the levelname so that we don't need directories
  for (std::string::iterator i = flat_levelname.begin(); i != flat_levelname.end(); ++i)
    if (*i == '/')
      *i = '_';

  std::string filename = System::get_userdir() + "demos/" + flat_levelname + "-" + get_date_string() + ".pingus-demo";

  std::unique_ptr<std::ofstream> out(new std::ofstream(filename.c_str()));

  if (!(*out.get()))
  {
    log_error("DemoRecorder: Error: Couldn't write DemoFile '%1%', demo recording will be disabled", filename);
    return std::unique_ptr<std::ostream>();
  }
  else
  {
    log_info("DemoRecorder: Writing demo to: %1%", filename);

    // Write file header
    FileWriter writer(*out);
    writer.begin_mapping("level");
    writer.write_string("name", plf.get_resname());
    writer.write_string("checksum", plf.get_checksum());
    writer.end_mapping();
    *out << std::endl;
    return std::unique_ptr<std::ostream>(out.release());
  }
}
Пример #4
0
/* Draw time axis (horizontal). */
void BackgroundDrawer::DrawTimeAxis(wxDC *dc, int arrow_width, int arrow_height, int tick_height, int line_width) {
	/* Get size. */
	int w, h;
	GetSize(&w, &h);

	/* Set solid white pen. */
	dc->SetPen(wxPen(GetTimeAxisCol(), line_width, wxSOLID));
	dc->SetBrush(*wxTRANSPARENT_BRUSH);
	/* Draw line with arrow. */
	dc->DrawLine(0, h - m_bottommargin, w - m_rightmargin, h - m_bottommargin);
	dc->DrawLine(w - m_rightmargin - arrow_width, h - m_bottommargin - arrow_height,
		w - m_rightmargin, h - m_bottommargin);
	dc->DrawLine(w - m_rightmargin - arrow_width, h - m_bottommargin + arrow_height,
		w - m_rightmargin, h - m_bottommargin);
    
	/* Draw ticks on axis. */
	int i = PeriodMarkShift[m_draw->GetPeriod()];
	int size = m_draw->GetValuesTable().size();
    
	wxDateTime prev_date;
	while (i < size) {
		int x = GetX(i);
		dc->DrawLine(x, h - m_bottommargin + tick_height / 2, x, h - m_bottommargin - tick_height / 2);

		wxDateTime date = m_draw->GetTimeOfIndex(i);
	
		/* Print date */
		wxString datestring = get_date_string(m_draw->GetPeriod(), prev_date, date);

		int textw, texth;

		dc->GetTextExtent(datestring, &textw, &texth);
		dc->SetTextForeground(GetTimeAxisCol());
		dc->DrawText(datestring, x - textw / 2, h - m_bottommargin + 1);

		i += TimeIndex::PeriodMult[m_draw->GetPeriod()];

		prev_date = date;
	}
    
	dc->SetPen(wxNullPen);
}
Пример #5
0
/*********************************************************************
 *
 *  Program to send email
 */
int main (int argc, char *argv[])
{
   char buf[1000];
   int i, ch;
   unsigned long maxlines, lines;
#if defined(HAVE_WIN32)
   SOCKET s;
#else
   int s, r;
   struct passwd *pwd;
#endif
   char *cp, *p;
#ifdef HAVE_GETADDRINFO
   int res;
   struct addrinfo hints;
   struct addrinfo *ai, *rp;
   char mail_port[10];
#else
   struct hostent *hp;
   struct sockaddr_in sin;
#endif
#ifdef HAVE_IPV6
   const char *options = "468ac:d:f:h:r:s:l:?";
#else
   const char *options = "48ac:d:f:h:r:s:l:?";
#endif

   setlocale(LC_ALL, "en_US");
   bindtextdomain("bareos", LOCALEDIR);
   textdomain("bareos");

   my_name_is(argc, argv, "bsmtp");
   maxlines = 0;

   while ((ch = getopt(argc, argv, options)) != -1) {
      switch (ch) {
      case '4':
         default_resolv_type = RESOLV_PROTO_IPV4;
         break;

#ifdef HAVE_IPV6
      case '6':
         default_resolv_type = RESOLV_PROTO_IPV6;
         break;
#endif

      case '8':
         content_utf8 = true;
         break;

      case 'a':
         default_resolv_type = RESOLV_PROTO_ANY;
         break;

      case 'c':
         Dmsg1(20, "cc=%s\n", optarg);
         cc_addr = optarg;
         break;

      case 'd':                    /* set debug level */
         if (*optarg == 't') {
            dbg_timestamp = true;
         } else {
            debug_level = atoi(optarg);
            if (debug_level <= 0) {
               debug_level = 1;
            }
         }
         Dmsg1(20, "Debug level = %d\n", debug_level);
         break;

      case 'f':                    /* from */
         from_addr = optarg;
         break;

      case 'h':                    /* smtp host */
         Dmsg1(20, "host=%s\n", optarg);
         p = strchr(optarg, ':');
         if (p) {
            *p++ = 0;
            mailport = atoi(p);
         }
         mailhost = optarg;
         break;

      case 's':                    /* subject */
         Dmsg1(20, "subject=%s\n", optarg);
         subject = optarg;
         break;

      case 'r':                    /* reply address */
         reply_addr = optarg;
         break;

      case 'l':
         Dmsg1(20, "maxlines=%s\n", optarg);
         maxlines = (unsigned long) atol(optarg);
         break;

      case '?':
      default:
         usage();

      }
   }
   argc -= optind;
   argv += optind;

   if (argc < 1) {
      Pmsg0(0, _("Fatal error: no recipient given.\n"));
      usage();
      exit(1);
   }

   /*
    *  Determine SMTP server
    */
   if (mailhost == NULL) {
      if ((cp = getenv("SMTPSERVER")) != NULL) {
         mailhost = cp;
      } else {
         mailhost = "localhost";
      }
   }

#if defined(HAVE_WIN32)
   WSADATA  wsaData;

   _setmode(0, _O_BINARY);
   WSAStartup(MAKEWORD(2,2), &wsaData);
#endif

   /*
    *  Find out my own host name for HELO;
    *  if possible, get the fully qualified domain name
    */
   if (gethostname(my_hostname, sizeof(my_hostname) - 1) < 0) {
      Pmsg1(0, _("Fatal gethostname error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
#ifdef HAVE_GETADDRINFO
   memset(&hints, 0, sizeof(struct addrinfo));
   hints.ai_family = AF_UNSPEC;
   hints.ai_socktype = 0;
   hints.ai_protocol = 0;
   hints.ai_flags = AI_CANONNAME;

   if ((res = getaddrinfo(my_hostname, NULL, &hints, &ai)) != 0) {
      Pmsg2(0, _("Fatal getaddrinfo for myself failed \"%s\": ERR=%s\n"),
            my_hostname, gai_strerror(res));
      exit(1);
   }
   strncpy(my_hostname, ai->ai_canonname, sizeof(my_hostname) - 1);
   my_hostname[sizeof(my_hostname) - 1] = '\0';
   freeaddrinfo(ai);
#else
   if ((hp = gethostbyname(my_hostname)) == NULL) {
      Pmsg2(0, _("Fatal gethostbyname for myself failed \"%s\": ERR=%s\n"),
            my_hostname, strerror(errno));
      exit(1);
   }
   strncpy(my_hostname, hp->h_name, sizeof(my_hostname) - 1);
   my_hostname[sizeof(my_hostname) - 1] = '\0';
#endif
   Dmsg1(20, "My hostname is: %s\n", my_hostname);

   /*
    *  Determine from address.
    */
   if (from_addr == NULL) {
#if defined(HAVE_WIN32)
      DWORD dwSize = UNLEN + 1;
      LPSTR lpszBuffer = (LPSTR)alloca(dwSize);

      if (GetUserName(lpszBuffer, &dwSize)) {
         snprintf(buf, sizeof(buf), "%s@%s", lpszBuffer, my_hostname);
      } else {
         snprintf(buf, sizeof(buf), "unknown-user@%s", my_hostname);
      }
#else
      if ((pwd = getpwuid(getuid())) == 0) {
         snprintf(buf, sizeof(buf), "userid-%d@%s", (int)getuid(), my_hostname);
      } else {
         snprintf(buf, sizeof(buf), "%s@%s", pwd->pw_name, my_hostname);
      }
#endif
      from_addr = bstrdup(buf);
   }
   Dmsg1(20, "From addr=%s\n", from_addr);

   /*
    *  Connect to smtp daemon on mailhost.
    */
lookup_host:
#ifdef HAVE_GETADDRINFO
   memset(&hints, 0, sizeof(struct addrinfo));
   switch (default_resolv_type) {
   case RESOLV_PROTO_ANY:
      hints.ai_family = AF_UNSPEC;
      break;
   case RESOLV_PROTO_IPV4:
      hints.ai_family = AF_INET;
      break;
#ifdef HAVE_IPV6
   case RESOLV_PROTO_IPV6:
      hints.ai_family = AF_INET6;
      break;
#endif
   default:
      hints.ai_family = AF_UNSPEC;
      break;
   }
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_protocol = 0;
   hints.ai_flags = 0;
   snprintf(mail_port, sizeof(mail_port), "%d", mailport);

   if ((res = getaddrinfo(mailhost, mail_port, &hints, &ai)) != 0) {
      Pmsg2(0, _("Error unknown mail host \"%s\": ERR=%s\n"),
            mailhost, gai_strerror(res));
      if (!bstrcasecmp(mailhost, "localhost")) {
         Pmsg0(0, _("Retrying connection using \"localhost\".\n"));
         mailhost = "localhost";
         goto lookup_host;
      }
      exit(1);
   }

   for (rp = ai; rp != NULL; rp = rp->ai_next) {
#if defined(HAVE_WIN32)
      s = WSASocket(rp->ai_family, rp->ai_socktype, rp->ai_protocol, NULL, 0, 0);
#else
      s = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
#endif
      if (s < 0) {
         continue;
      }

      if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1) {
         break;
      }

      close(s);
   }

   if (!rp) {
      Pmsg1(0, _("Failed to connect to mailhost %s\n"), mailhost);
      exit(1);
   }

   freeaddrinfo(ai);
#else
   if ((hp = gethostbyname(mailhost)) == NULL) {
      Pmsg2(0, _("Error unknown mail host \"%s\": ERR=%s\n"),
            mailhost, strerror(errno));
      if (!bstrcasecmp(mailhost, "localhost")) {
         Pmsg0(0, _("Retrying connection using \"localhost\".\n"));
         mailhost = "localhost";
         goto lookup_host;
      }
      exit(1);
   }

   if (hp->h_addrtype != AF_INET) {
      Pmsg1(0, _("Fatal error: Unknown address family for smtp host: %d\n"), hp->h_addrtype);
      exit(1);
   }
   memset((char *)&sin, 0, sizeof(sin));
   memcpy((char *)&sin.sin_addr, hp->h_addr, hp->h_length);
   sin.sin_family = hp->h_addrtype;
   sin.sin_port = htons(mailport);
#if defined(HAVE_WIN32)
   if ((s = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0)) < 0) {
      Pmsg1(0, _("Fatal socket error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
#else
   if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
      Pmsg1(0, _("Fatal socket error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
#endif
   if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
      Pmsg2(0, _("Fatal connect error to %s: ERR=%s\n"), mailhost, strerror(errno));
      exit(1);
   }
   Dmsg0(20, "Connected\n");
#endif

#if defined(HAVE_WIN32)
   int fdSocket = _open_osfhandle(s, _O_RDWR | _O_BINARY);
   if (fdSocket == -1) {
      Pmsg1(0, _("Fatal _open_osfhandle error: ERR=%s\n"), strerror(errno));
      exit(1);
   }

   int fdSocket2 = dup(fdSocket);

   if ((sfp = fdopen(fdSocket, "wb")) == NULL) {
      Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
   if ((rfp = fdopen(fdSocket2, "rb")) == NULL) {
      Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
#else
   if ((r = dup(s)) < 0) {
      Pmsg1(0, _("Fatal dup error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
   if ((sfp = fdopen(s, "w")) == 0) {
      Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
   if ((rfp = fdopen(r, "r")) == 0) {
      Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno));
      exit(1);
   }
#endif

   /*
    *  Send SMTP headers.  Note, if any of the strings have a <
    *   in them already, we do not enclose the string in < >, otherwise
    *   we do.
    */
   get_response(); /* banner */
   chat("HELO %s\r\n", my_hostname);
   chat("MAIL FROM:%s\r\n", cleanup_addr(from_addr, buf, sizeof(buf)));

   for (i = 0; i < argc; i++) {
      Dmsg1(20, "rcpt to: %s\n", argv[i]);
      chat("RCPT TO:%s\r\n", cleanup_addr(argv[i], buf, sizeof(buf)));
   }

   if (cc_addr) {
      chat("RCPT TO:%s\r\n", cleanup_addr(cc_addr, buf, sizeof(buf)));
   }
   Dmsg0(20, "Data\n");
   chat("DATA\r\n");

   /*
    *  Send message header
    */
   fprintf(sfp, "From: %s\r\n", from_addr);
   Dmsg1(10, "From: %s\r\n", from_addr);
   if (subject) {
      fprintf(sfp, "Subject: %s\r\n", subject);
      Dmsg1(10, "Subject: %s\r\n", subject);
   }
   if (reply_addr) {
      fprintf(sfp, "Reply-To: %s\r\n", reply_addr);
      Dmsg1(10, "Reply-To: %s\r\n", reply_addr);
   }
   if (err_addr) {
      fprintf(sfp, "Errors-To: %s\r\n", err_addr);
      Dmsg1(10, "Errors-To: %s\r\n", err_addr);
   }

#if defined(HAVE_WIN32)
   DWORD dwSize = UNLEN + 1;
   LPSTR lpszBuffer = (LPSTR)alloca(dwSize);

   if (GetUserName(lpszBuffer, &dwSize)) {
      fprintf(sfp, "Sender: %s@%s\r\n", lpszBuffer, my_hostname);
      Dmsg2(10, "Sender: %s@%s\r\n", lpszBuffer, my_hostname);
   } else {
      fprintf(sfp, "Sender: unknown-user@%s\r\n", my_hostname);
      Dmsg1(10, "Sender: unknown-user@%s\r\n", my_hostname);
   }
#else
   if ((pwd = getpwuid(getuid())) == 0) {
      fprintf(sfp, "Sender: userid-%d@%s\r\n", (int)getuid(), my_hostname);
      Dmsg2(10, "Sender: userid-%d@%s\r\n", (int)getuid(), my_hostname);
   } else {
      fprintf(sfp, "Sender: %s@%s\r\n", pwd->pw_name, my_hostname);
      Dmsg2(10, "Sender: %s@%s\r\n", pwd->pw_name, my_hostname);
   }
#endif

   fprintf(sfp, "To: %s", argv[0]);
   Dmsg1(10, "To: %s", argv[0]);
   for (i = 1; i < argc; i++) {
      fprintf(sfp, ",%s", argv[i]);
      Dmsg1(10, ",%s", argv[i]);
   }

   fprintf(sfp, "\r\n");
   Dmsg0(10, "\r\n");
   if (cc_addr) {
      fprintf(sfp, "Cc: %s\r\n", cc_addr);
      Dmsg1(10, "Cc: %s\r\n", cc_addr);
   }

   if (content_utf8) {
      fprintf(sfp, "Content-Type: text/plain; charset=UTF-8\r\n");
      Dmsg0(10, "Content-Type: text/plain; charset=UTF-8\r\n");
   }

   get_date_string(buf, sizeof(buf));
   fprintf(sfp, "Date: %s\r\n", buf);
   Dmsg1(10, "Date: %s\r\n", buf);

   fprintf(sfp, "\r\n");

   /*
    *  Send message body
    */
   lines = 0;
   while (fgets(buf, sizeof(buf), stdin)) {
      if (maxlines > 0 && ++lines > maxlines) {
         Dmsg1(20, "skip line because of maxlines limit: %lu\n", maxlines);
         while (fgets(buf, sizeof(buf), stdin)) {
            ++lines;
         }
         break;
      }
      buf[sizeof(buf)-1] = '\0';
      buf[strlen(buf)-1] = '\0';
      if (buf[0] == '.') {         /* add extra . see RFC 2821 4.5.2 */
         fputs(".", sfp);
      }
      fputs(buf, sfp);
      fputs("\r\n", sfp);
   }

   if (lines > maxlines) {
      Dmsg1(10, "hit maxlines limit: %lu\n", maxlines);
      fprintf(sfp, "\r\n\r\n[maximum of %lu lines exceeded, skipped %lu lines of output]\r\n", maxlines, lines-maxlines);
   }

   /*
    *  Send SMTP quit command
    */
   chat(".\r\n");
   chat("QUIT\r\n");

   /*
    *  Go away gracefully ...
    */
   exit(0);
}
Пример #6
0
JS_EXPORT_API
gchar* greeter_get_date ()
{
    return get_date_string ();
}
Пример #7
0
JS_EXPORT_API
gchar* lock_get_date ()
{
   return get_date_string ();
}