コード例 #1
0
ファイル: test-sched.c プロジェクト: bruceg/bcron
int cli_main(int argc, char* argv[])
{
  time_t start;
  time_t next;
  struct crontab c;
  str jobstr;

  msg_debug_init();
  timespec_next_init();

  memset(&c, 0, sizeof c);
  jobstr.len = strlen(jobstr.s = argv[0]);
  jobstr.size = 0;
  if (!crontab_parse(&c, &jobstr, "nobody")
      || c.jobs == 0)
    usage(111, "Invalid crontab line");

  if ((start = strtol(argv[1], 0, 10)) <= 0)
    usage(111, "Invalid timesstamp");

  next = timespec_next(&c.jobs->times, start, localtime(&start));

  obuf_put5s(&outbuf, "last: ", utoa(start), " ", fmttime(start), "\n");
  obuf_put5s(&outbuf, "next: ", utoa(next), " ", fmttime(next), "\n");
  obuf_flush(&outbuf);

  return 0;
  (void)argc;
}
コード例 #2
0
ファイル: main.c プロジェクト: bruceg/qmail-autoresponder
void usage(const char* msg)
{
  if(msg)
    msg1(msg);
  obuf_putf(&errbuf, usage_str, program, usage_args, usage_post);
  obuf_flush(&errbuf);
  exit(111);
}
コード例 #3
0
ファイル: twoftpd-conf.c プロジェクト: bruceg/twoftpd
void usage(const char* msg)
{
  if (msg)
    obuf_put4s(&outbuf, program, ": ", msg, ".\n");
  obuf_puts(&outbuf, usage_str);
  obuf_flush(&outbuf);
  exit(1);
}
コード例 #4
0
ファイル: dns_name4.c プロジェクト: bruceg/bglibs
void doit(const ipv4addr* addr)
{
  struct dns_result out = {0};
  debugfn(dns_name4(&out, addr));
  obuf_putf(&outbuf, "s{: count=}d{\n}", ipv4_format(addr), out.count);
  dump_rrs(out.count, &out.rr);
  obuf_flush(&outbuf);
}
コード例 #5
0
ファイル: main.c プロジェクト: bruceg/bglibs
void usage(int exit_value, const char* errorstr)
{
  if(errorstr)
    error1(errorstr);
  show_usage();
  cli_show_help();
  obuf_flush(&outbuf);
  exit(exit_value);
}
コード例 #6
0
ファイル: bcron-spool.c プロジェクト: 0xef53/bcron
static void respond_okstr(const str* s)
{
  obuf_putu(&outbuf, s->len + 1);
  obuf_putc(&outbuf, ':');
  obuf_putc(&outbuf, 'K');
  obuf_putstr(&outbuf, s);
  obuf_putc(&outbuf, ',');
  obuf_flush(&outbuf);
  exit(0);
}
コード例 #7
0
ファイル: bcron-spool.c プロジェクト: 0xef53/bcron
static void respond(const char* msg)
{
  obuf_putnetstring(&outbuf, msg, strlen(msg));
  obuf_flush(&outbuf);
  switch (msg[0]) {
  case 'K':
    exit(0);
  case 'Z':
    die3sys(111, username, ": ", msg + 1);
  default:
    die3(100, username, ": ", msg + 1);
  }
}
コード例 #8
0
ファイル: main.c プロジェクト: bruceg/twoftpd
static int read_request(void)
/* Returns number of bytes read before the LF, or -1 for EOF */
{
  unsigned offset;
  int saw_esc;
  int saw_esc_respond;
  int saw_esc_ignore;
  char byte[1];

  saw_esc = saw_esc_respond = saw_esc_ignore = 0;
  offset = 0;
  while (offset < sizeof request - 1) {
    if (!ibuf_getc(&inbuf, byte)) { inbuf_errmsg(); return -1; }
    if (saw_esc) {
      saw_esc = 0;
      switch (*byte) {
      case TELNET_DONT:
      case TELNET_WONT:
	saw_esc_ignore = *byte; break;
      case TELNET_WILL: saw_esc_respond = TELNET_DONT; break;
      case TELNET_DO  : saw_esc_respond = TELNET_WONT; break;
      case TELNET_IAC : request[offset++] = TELNET_IAC; break;
      }
    }
    else if (saw_esc_ignore) {
      saw_esc_ignore = 0;
    }
    else if (saw_esc_respond) {
      obuf_putc(&outbuf, TELNET_IAC);
      obuf_putc(&outbuf, saw_esc_respond);
      obuf_putc(&outbuf, *byte);
      obuf_flush(&outbuf);
      saw_esc_respond = 0;
    }
    else if (*byte == TELNET_IAC)
      saw_esc = 1;
    else if (*byte == LF)
      break;
    else
      request[offset++] = *byte ? *byte : LF;
  }
  while (*byte != LF)
    if (!ibuf_getc(&inbuf, byte)) { inbuf_errmsg(); return -1; }
  return offset;
}
コード例 #9
0
ファイル: ipv4_scan.c プロジェクト: bruceg/bglibs
static void test(const char* start)
{
  ipv4addr ip;
  int i;
  const char* end;
  obuf_put2s(&outbuf, start, ": ");
  end = ipv4_scan(start, &ip);
  if (end == 0)
    obuf_puts(&outbuf, "NULL");
  else {
    for (i = 0; i < 4; ++i) {
      if (i > 0) obuf_putc(&outbuf, '.');
      obuf_puti(&outbuf, ip.addr[i]);
    }
    if (*end != 0)
      obuf_put2s(&outbuf, " + ", end);
  }
  NL();
  obuf_flush(&outbuf);
}
コード例 #10
0
ファイル: iobuf_copy.c プロジェクト: bruceg/bglibs
/** Copy all the data from an \c ibuf to an \c obuf, and flush the
    \c obuf after writing is completed. */
int iobuf_copyflush(ibuf* in, obuf* out)
{
  if (!iobuf_copy(in, out)) return 0;
  return obuf_flush(out);
}
コード例 #11
0
ファイル: obuf_putsflush.c プロジェクト: bruceg/bglibs
/** Write a C string to the \c obuf and flush it. */
int obuf_putsflush(obuf* out, const char* str)
{
  return obuf_puts(out, str) && obuf_flush(out);
}