Exemplo n.º 1
0
Arquivo: log.c Projeto: Estella/wraith
void logidx(int idx, const char *format, ...)
{
  char va_out[LOGLINEMAX + 1];
  va_list va;

  va_start(va, format);
  egg_vsnprintf(va_out, sizeof(va_out), format, va);
  va_end(va);

  if (idx < 0)
    putlog(LOG_DEBUG, "*", "%s", va_out);
  else
    dprintf(idx, "%s\n", va_out);
}
Exemplo n.º 2
0
void sdprintf (const char *format, ...)
{
  if (sdebug) {
    char s[2001] = "";
    va_list va;

    va_start(va, format);
    egg_vsnprintf(s, sizeof(s), format, va);
    va_end(va);
    
    remove_crlf(s);

    if (!backgrd)
      dprintf(DP_STDOUT, "[D:%d] %s%s%s\n", mypid, BOLD(-1), s, BOLD_END(-1));
    else
      printf("[D:%d] %s%s%s\n", mypid, BOLD(-1), s, BOLD_END(-1));
  }
}
Exemplo n.º 3
0
void chatout EGG_VARARGS_DEF(char *, arg1)
{
  int i, len;
  char *format;
  char s[601];
  va_list va;

  format = EGG_VARARGS_START(char *, arg1, va);

  egg_vsnprintf(s, 511, format, va);
  va_end(va);
  len = strlen(s);
  if (len > 511)
    len = 511;
  s[len + 1] = 0;

  for (i = 0; i < dcc_total; i++)
    if (dcc[i].type == &DCC_CHAT)
      if (dcc[i].u.chat->channel >= 0)
        dprintf(i, "%s", s);

}
Exemplo n.º 4
0
void sdprintf (const char *format, ...)
{
  char s[2001] = "";
  va_list va;

  va_start(va, format);
  egg_vsnprintf(s, sizeof(s), format, va);
  va_end(va);

  remove_crlf(s);

  ContextNote("dbg", s);

  if (sdebug) {
    if (!backgrd)
      dprintf(DP_STDOUT, "[D:%lu] %s%s%s\n", (unsigned long) mypid, BOLD(-1), s, BOLD_END(-1));
    else
      printf("[D:%lu] %s%s%s\n", (unsigned long) mypid, BOLD(-1), s, BOLD_END(-1));
  }
#ifdef DEBUG
  logfile(LOG_DEBUG, s);
#endif
}
Exemplo n.º 5
0
/* Print to all on this channel but one.
 */
void chanout_but EGG_VARARGS_DEF(int, arg1)
{
  int i, x, chan, len;
  char *format;
  char s[601];
  va_list va;

  x = EGG_VARARGS_START(int, arg1, va);
  chan = va_arg(va, int);
  format = va_arg(va, char *);

  egg_vsnprintf(s, 511, format, va);
  va_end(va);
  len = strlen(s);
  if (len > 511)
    len = 511;
  s[len + 1] = 0;

  for (i = 0; i < dcc_total; i++)
    if ((dcc[i].type == &DCC_CHAT) && (i != x))
      if (dcc[i].u.chat->channel == chan)
        dprintf(i, "%s", s);

}
Exemplo n.º 6
0
Arquivo: log.c Projeto: Estella/wraith
void
irc_log(struct chanset_t *chan, const char *format, ...)
{
#ifdef NOTHANKS
  char va_out[LOGLINEMAX + 1];
  va_list va;

  va_start(va, format);
  egg_vsnprintf(va_out, sizeof(va_out), format, va);
  va_end(va);

  if ((chan && egg_strcasecmp(chan->dname, "#!obs")) || !chan)
    dprintf(DP_HELP, "PRIVMSG #!obs :[%s] %s\n", chan ? chan->dname : "*" , va_out);
/*
  chanout_but(-1, 1, "[%s] %s\n", chan->dname, va_out);
  botnet_send_chan(-1, conf.bot->nick, chan->dname, 1, va_out);
   if (chan)
     putlog(LOG_PUBLIC, "*", "[%s] %s", chan->dname, va_out);
   else
     putlog(LOG_PUBLIC, "*", "%s", va_out);
  sdprintf("%s", va_out);
*/
#endif 
}
Exemplo n.º 7
0
void dprintf EGG_VARARGS_DEF(int, arg1)
{
  char buf[1024];
  char *format;
  int idx, len;
  va_list va;

  idx = EGG_VARARGS_START(int, arg1, va);
  format = va_arg(va, char *);

  egg_vsnprintf(buf, 1023, format, va);
  va_end(va);
  /* We can not use the return value vsnprintf() to determine where
   * to null terminate. The C99 standard specifies that vsnprintf()
   * shall return the number of bytes that would be written if the
   * buffer had been large enough, rather then -1.
   */
  /* We actually can, since if it's < 0 or >= sizeof(buf), we know it wrote
   * sizeof(buf) bytes. But we're not doing that anyway.
   */
  buf[sizeof(buf) - 1] = 0;
  len = strlen(buf);

  if (idx < 0) {
    tputs(-idx, buf, len);
  } else if (idx > 0x7FF0) {
    switch (idx) {
    case DP_LOG:
      putlog(LOG_MISC, "*", "%s", buf);
      break;
    case DP_STDOUT:
      tputs(STDOUT, buf, len);
      break;
    case DP_STDERR:
      tputs(STDERR, buf, len);
      break;
    case DP_SERVER:
    case DP_HELP:
    case DP_MODE:
    case DP_MODE_NEXT:
    case DP_SERVER_NEXT:
    case DP_HELP_NEXT:
      qserver(idx, buf, len);
      break;
    }
    return;
  } else {
    if (len > 500) {            /* Truncate to fit */
      buf[500] = 0;
      strcat(buf, "\n");
      len = 501;
    }
    if (dcc[idx].type && ((long) (dcc[idx].type->output) == 1)) {
      char *p = add_cr(buf);

      tputs(dcc[idx].sock, p, strlen(p));
    } else if (dcc[idx].type && dcc[idx].type->output)
      dcc[idx].type->output(idx, buf, dcc[idx].u.other);
    else
      tputs(dcc[idx].sock, buf, len);
  }
}
Exemplo n.º 8
0
Arquivo: log.c Projeto: Estella/wraith
void putlog(int type, const char *chname, const char *format, ...)
{
  char va_out[LOGLINEMAX + 1] = "";
  va_list va;

  va_start(va, format);
  egg_vsnprintf(va_out, sizeof(va_out), format, va);
  va_end(va);

  if (!va_out[0]) {
    putlog(LOG_ERRORS, "*", "Empty putlog() detected");
    return;
  }

  if (!log_repeated) {
    if (type == last_type && 
        !egg_strncasecmp(chname, last_chname, sizeof(last_chname)) && 
        !egg_strncasecmp(va_out, last_log, sizeof(last_log))) {
      ++log_repeats;

      return;
    }
    if (log_repeats) {
      log_repeated = 1;
      putlog(type, last_chname, "Last message repeated %d times.\n", log_repeats);
      log_repeats = 0;
    }
    strlcpy(last_log, va_out, sizeof(last_log));
    last_type = type;
    strlcpy(last_chname, chname, sizeof(last_chname));
  } else
    log_repeated = 0;

  char *p = NULL;

  if ((p = strchr(va_out, '\n')))		/* make sure no trailing newline */
     *p = 0;

  int idx = 0;
  char out[LOGLINEMAX + 1] = "";

  if (conf.bot && conf.bot->hub) {
    char stamp[34] = "";
    struct tm *t = gmtime(&now);

    egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
    /* Place the timestamp in the string to be printed */
    strlcpy(out, stamp, sizeof(out));
    strlcat(out, " ", sizeof(out));
    strlcat(out, va_out, sizeof(out));
  } else
    strlcpy(out, va_out, sizeof(out));

  /* strcat(out, "\n"); */

#ifdef no
  /* FIXME: WRITE LOG HERE */
  int logfile_masks = LOG_CMDS|LOG_ERRORS|LOG_WARN|LOG_BOTS|LOG_MISC;

  if (logfile_masks && (logfile_masks & type))
    logfile(type, out);
#endif
  /* broadcast to hubs */
  if (chname[0] == '*' && conf.bot && conf.bot->nick)
    botnet_send_log(-1, conf.bot->nick, type, out);

  for (idx = 0; idx < dcc_total; idx++) {
    if (dcc[idx].type && (dcc[idx].type == &DCC_CHAT && dcc[idx].simul == -1) && (dcc[idx].u.chat->con_flags & type)) {
      if ((chname[0] == '@') || (chname[0] == '*') || (dcc[idx].u.chat->con_chan[0] == '*') ||
          (!rfc_casecmp(chname, dcc[idx].u.chat->con_chan)))
        dprintf(idx, "%s\n", out);
    }
  }

  if ((!backgrd) && (!term_z)) {
    dprintf(DP_STDOUT, "%s\n", out);
  } else if ((type & LOG_ERRORS || type & LOG_MISC) && use_stderr) {
    dprintf(DP_STDERR, "%s\n", va_out);
  }
}