예제 #1
0
static int build_csv_record(char *buf, size_t bufsize, struct cw_cdr *cdr)
{

	buf[0] = '\0';
	/* Account code */
	append_string(buf, cdr->accountcode, bufsize);
	/* Source */
	append_string(buf, cdr->src, bufsize);
	/* Destination */
	append_string(buf, cdr->dst, bufsize);
	/* Destination context */
	append_string(buf, cdr->dcontext, bufsize);
	/* Caller*ID */
	append_string(buf, cdr->clid, bufsize);
	/* Channel */
	append_string(buf, cdr->channel, bufsize);
	/* Destination Channel */
	append_string(buf, cdr->dstchannel, bufsize);
	/* Last Application */
	append_string(buf, cdr->lastapp, bufsize);
	/* Last Data */
	append_string(buf, cdr->lastdata, bufsize);
	/* Start Time */
	append_date(buf, cdr->start, bufsize);
	/* Answer Time */
	append_date(buf, cdr->answer, bufsize);
	/* End Time */
	append_date(buf, cdr->end, bufsize);
	/* Duration */
	append_int(buf, cdr->duration, bufsize);
	/* Billable seconds */
	append_int(buf, cdr->billsec, bufsize);
	/* Disposition */
	append_string(buf, cw_cdr_disp2str(cdr->disposition), bufsize);
	/* AMA Flags */
	append_string(buf, cw_cdr_flags2str(cdr->amaflags), bufsize);

#ifdef CSV_LOGUNIQUEID
	/* Unique ID */
	append_string(buf, cdr->uniqueid, bufsize);
#endif
#ifdef CSV_LOGUSERFIELD
	/* append the user field */
	append_string(buf, cdr->userfield,bufsize);	
#endif
	/* If we hit the end of our buffer, log an error */
	if (strlen(buf) < bufsize - 5) {
		/* Trim off trailing comma */
		buf[strlen(buf) - 1] = '\0';
		strncat(buf, "\n", bufsize - strlen(buf) - 1);
		return 0;
	}
	return -1;
}
예제 #2
0
파일: http.c 프로젝트: gtk-gnutella/gwc
int
http_send_status_line(http_t *ctx, unsigned int code, const char *msg)
{
  char buf[256], *p = buf;
  size_t size = sizeof buf;

  RUNTIME_ASSERT(code >= 100 && code <= 999);
  ACCLOG_SET(ctx->acclog, code, code);

  p = append_string(p, &size, "HTTP/1.1 ");
  p = append_uint(p, &size, code);
  p = append_char(p, &size, ' ');
  p = append_string(p, &size, msg);

#if 0
  DBUG("Sending HTTP response \"%s\"", buf);
#endif

  p = APPEND_CRLF(p, &size);
  
  p = APPEND_STATIC_CHARS(p, &size, "Date: ");
  p = append_date(p, &size, compat_mono_time(NULL));
  p = APPEND_CRLF(p, &size);

  if (
    0 != http_send(ctx, buf, sizeof buf - size) ||
    0 != http_send_str(ctx, http_server_header)
  )
    return -1;

  return 0;
}
예제 #3
0
파일: template.c 프로젝트: gtk-gnutella/gwc
struct mem_buf *
template_get_chunk(struct template_chunk *chunk, const gwc_full_stats_t *stats)
{
  char buf[1024], *p = buf;
  size_t avail = sizeof buf;

  switch (chunk->type) {
  case chunk_http_response:
  case chunk_http_header:
  case chunk_data:
    /* Must be handled elsewhere */
    p = NULL;
    RUNTIME_ASSERT(0);
    break;

  case crab_stats_total_updates:
    p = append_uint64(buf, &avail, stats->total.updates);
    break;
  case crab_stats_total_updates_ip:
    p = append_uint64(buf, &avail, stats->total.ip_updates);
    break;
  case crab_stats_total_updates_url:
    p = append_uint64(buf, &avail, stats->total.url_updates);
    break;
  case crab_stats_total_requests:
    p = append_uint64(buf, &avail, stats->total.requests);
    break;
  case crab_stats_total_requests_base:
    p = append_uint64(buf, &avail, stats->total.base_requests);
    break;
  case crab_stats_total_requests_data:
    p = append_uint64(buf, &avail, stats->total.data_requests);
    break;
  case crab_stats_total_requests_get:
    p = append_uint64(buf, &avail, stats->total.get_requests);
    break;
  case crab_stats_total_requests_hostfile:
    p = append_uint64(buf, &avail, stats->total.hostfile_requests);
    break;
  case crab_stats_total_requests_urlfile:
    p = append_uint64(buf, &avail, stats->total.urlfile_requests);
    break;
  case crab_stats_total_requests_ping:
    p = append_uint64(buf, &avail, stats->total.ping_requests);
    break;
  case crab_stats_total_requests_statfile:
    p = append_uint64(buf, &avail, stats->total.statfile_requests);
    break;
  case crab_stats_total_accepts:
    p = append_uint64(buf, &avail, stats->total.accepts);
    break;
  case crab_stats_total_blocked:
    p = append_uint64(buf, &avail, stats->total.blocked);
    break;
  case crab_stats_total_errors:
    p = append_uint64(buf, &avail, stats->total.errors);
    break;
  case crab_stats_total_http_400s:
    p = append_uint64(buf, &avail, stats->total.http_400s);
    break;
  case crab_stats_total_http_404s:
    p = append_uint64(buf, &avail, stats->total.http_404s);
    break;
  case crab_stats_total_too_early:
    p = append_uint64(buf, &avail, stats->total.too_early);
    break;
  case crab_stats_total_rx:
    p = append_size(buf, &avail, stats->total.rx);
    break;
  case crab_stats_total_tx:
    p = append_size(buf, &avail, stats->total.tx);
    break;

  case crab_stats_hourly_updates:
    p = append_uint64(buf, &avail, stats->hourly.updates);
    break;
  case crab_stats_hourly_updates_ip:
    p = append_uint64(buf, &avail, stats->hourly.ip_updates);
    break;
  case crab_stats_hourly_updates_url:
    p = append_uint64(buf, &avail, stats->hourly.url_updates);
    break;
  case crab_stats_hourly_requests:
    p = append_uint64(buf, &avail, stats->hourly.requests);
    break;
  case crab_stats_hourly_requests_base:
    p = append_uint64(buf, &avail, stats->hourly.base_requests);
    break;
  case crab_stats_hourly_requests_data:
    p = append_uint64(buf, &avail, stats->hourly.data_requests);
    break;
  case crab_stats_hourly_requests_get:
    p = append_uint64(buf, &avail, stats->hourly.get_requests);
    break;
  case crab_stats_hourly_requests_hostfile:
    p = append_uint64(buf, &avail, stats->hourly.hostfile_requests);
    break;
  case crab_stats_hourly_requests_urlfile:
    p = append_uint64(buf, &avail, stats->hourly.urlfile_requests);
    break;
  case crab_stats_hourly_requests_ping:
    p = append_uint64(buf, &avail, stats->hourly.ping_requests);
    break;
  case crab_stats_hourly_requests_statfile:
    p = append_uint64(buf, &avail, stats->hourly.statfile_requests);
    break;
  case crab_stats_hourly_accepts:
    p = append_uint64(buf, &avail, stats->hourly.accepts);
    break;
  case crab_stats_hourly_blocked:
    p = append_uint64(buf, &avail, stats->hourly.blocked);
    break;
  case crab_stats_hourly_errors:
    p = append_uint64(buf, &avail, stats->hourly.errors);
    break;
  case crab_stats_hourly_http_400s:
    p = append_uint64(buf, &avail, stats->hourly.http_400s);
    break;
  case crab_stats_hourly_http_404s:
    p = append_uint64(buf, &avail, stats->hourly.http_404s);
    break;
  case crab_stats_hourly_too_early:
    p = append_uint64(buf, &avail, stats->hourly.too_early);
    break;
  case crab_stats_hourly_rx:
    p = append_size(buf, &avail, stats->hourly.rx);
    break;
  case crab_stats_hourly_tx:
    p = append_size(buf, &avail, stats->hourly.tx);
    break;

  case crab_startup_time:
    p = append_date(buf, &avail, stats->start_time.tv_sec);
    break;
    
  case crab_user_agent:
    p = append_string(buf, &avail, GWC_USER_AGENT);
    break;

  case crab_uri:
    p = append_string(buf, &avail, OPTION(gwc_uri));
    break;

  case crab_url:
    p = append_string(buf, &avail, OPTION(gwc_url));
    break;

  case crab_network_id:
    p = append_string(buf, &avail,
          OPTION(network_id) ? OPTION(network_id) : "gnutella");
    break;
    
  case crab_contact_address:
    p = append_string(buf, &avail,
          OPTION(contact_address) ? OPTION(contact_address) : "");
    break;

#if defined(HAVE_GETRUSAGE)
#define RU_TIME(x) stats->ru.x
#else
#define RU_TIME(x) 0
#endif /* HAVE_GETRUSAGE */
 
  case crab_rusage_utime:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_utime.tv_sec) * 1000000 +
        RU_TIME(ru_utime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
  case crab_rusage_stime:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_stime.tv_sec) * 1000000 +
        RU_TIME(ru_stime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
    
   case crab_rusage_utime_percent:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_utime.tv_sec) * 1000000 +
        RU_TIME(ru_utime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
  case crab_rusage_stime_percent:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_stime.tv_sec) * 1000000 +
        RU_TIME(ru_stime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
    
#if defined(HAVE_GETRUSAGE) && defined(HAVE_BSD_STRUCT_RUSAGE)
#define RU(x) stats->ru.x
#else
#define RU(x) 0
#endif /* HAVE_GETRUSAGE && HAVE_BSD_STRUCT_RUSAGE */
    
  case crab_rusage_maxrss:
    p = append_uint64(buf, &avail, RU(ru_maxrss));
    break;
  case crab_rusage_ixrss:
    p = append_uint64(buf, &avail, RU(ru_ixrss));
    break;
  case crab_rusage_idrss:
    p = append_uint64(buf, &avail, RU(ru_idrss));
    break;
  case crab_rusage_isrss:
    p = append_uint64(buf, &avail, RU(ru_isrss));
    break;
  case crab_rusage_minflt:
    p = append_uint64(buf, &avail, RU(ru_minflt));
    break;
  case crab_rusage_majflt:
    p = append_uint64(buf, &avail, RU(ru_majflt));
    break;
  case crab_rusage_nswap:
    p = append_uint64(buf, &avail, RU(ru_nswap));
    break;
  case crab_rusage_inblock:
    p = append_uint64(buf, &avail, RU(ru_inblock));
    break;
  case crab_rusage_oublock:
    p = append_uint64(buf, &avail, RU(ru_oublock));
    break;
  case crab_rusage_msgsnd:
    p = append_uint64(buf, &avail, RU(ru_msgsnd));
    break;
  case crab_rusage_msgrcv:
    p = append_uint64(buf, &avail, RU(ru_msgrcv));
    break;
  case crab_rusage_nsignals:
    p = append_uint64(buf, &avail, RU(ru_nsignals));
    break;
  case crab_rusage_nvcsw:
    p = append_uint64(buf, &avail, RU(ru_nvcsw));
    break;
  case crab_rusage_nivcsw:
    p = append_uint64(buf, &avail, RU(ru_nivcsw));
    break;
    
#undef RU

  default:
    CRIT("Unknown chunk type (%u)", (unsigned) chunk->type);
    p = NULL;
    RUNTIME_ASSERT(0);
  }

  if (p && p != buf) {
    return mem_buf_new_copy(buf, p - buf);
  }
  return NULL;
}
예제 #4
0
/* Checks the Date header of the message. RFC4474 [5] Step 3 */
static int date_proc(struct sip_msg* msg, char* srt1, char* str2)
{
    str sdate;
    int iRes;
    time_t tmsg, tnow;

    if (glb_authservice_disabled) {
        LOG(L_WARN, "AUTH_IDENTITY:date_proc: Authentication Service is disabled\n");
        return -1;
    }

    getstr_dynstr(&glb_sdate).len=0;

    /* we'd like to get the DATE header of the massage */
    iRes=datehdr_proc(&sdate, NULL, msg);
    switch (iRes) {
    case AUTH_ERROR:
        return -1;
    case AUTH_NOTFOUND:
        if (append_date(&getstr_dynstr(&glb_sdate), glb_sdate.size, &tmsg, msg))
            return -2;
        break;
    /* Message has Date header so we check that */
    case AUTH_OK:
#ifdef HAVE_TIMEGM
        tmsg=timegm(&get_date(msg)->date);
#else
        tmsg=_timegm(&get_date(msg)->date);
#endif
        if (tmsg < 0) {
            LOG(L_ERR, "AUTH_IDENTITY:date_proc: timegm error\n");
            return -3;
        }
        if ((tnow=time(NULL))<0) {
            LOG(L_ERR, "AUTH_IDENTITY:date_proc: time error\n");
            return -4;
        }
        /*
         * If the value of this field contains a time different by more than
         * ten minutes from the current time noted by the authentication
         * service then it should reject the message.
         */
        if (tmsg + glb_imsgtime < tnow || tnow + glb_imsgtime < tmsg) {
            LOG(L_INFO, "AUTH_IDENTITY AUTHORIZER: Date header overdue\n");
            return -6;
        }
        break;
    default:
        /* unknown result */
        return -7;
    }

    /*
     * The authentication service MUST verify that the Date header
     * falls within the validity period of its certificate
     * RFC 4474 [6] Step 3
     */
    if (glb_imycertnotafter < tmsg) {
        LOG(L_INFO, "AUTH_IDENTITY AUTHORIZER: My certificate has been expired\n");
        return -8;
    }

    return 1;
}