Пример #1
0
inline int web_client_api_old_graph_request(RRDHOST *host, struct web_client *w, char *url) {
    // get the name of the data to show
    char *tok = mystrsep(&url, "/?&");
    if(tok && *tok) {
        debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok);

        // do we have such a data set?
        RRDSET *st = rrdset_find_byname(host, tok);
        if(!st) st = rrdset_find(host, tok);
        if(!st) {
            // we don't have it
            // try to send a file with that name
            buffer_flush(w->response.data);
            return mysendfile(w, tok);
        }
        st->last_accessed_time = now_realtime_sec();

        debug(D_WEB_CLIENT_ACCESS, "%llu: Sending %s.json of RRD_STATS...", w->id, st->name);
        w->response.data->contenttype = CT_APPLICATION_JSON;
        buffer_flush(w->response.data);
        rrd_graph2json_api_old(st, url, w->response.data);
        return 200;
    }

    buffer_flush(w->response.data);
    buffer_strcat(w->response.data, "Graph name?\r\n");
    return 400;
}
Пример #2
0
void ows_layer_storage_flush(ows_layer_storage * storage, FILE * output)
{
  assert(storage);
  assert(output);

  if (storage->schema) {
    fprintf(output, "schema: ");
    buffer_flush(storage->schema, output);
    fprintf(output, "\n");
  }

  if (storage->table) {
    fprintf(output, "table: ");
    buffer_flush(storage->table, output);
    fprintf(output, "\n");
  }

  if (storage->geom_columns) {
    fprintf(output, "geom_columns: ");
    list_flush(storage->geom_columns, output);
    fprintf(output, "\n");
  }

  fprintf(output, "srid: %i\n", storage->srid);
  fprintf(output, "is_degree: %i\n", storage->is_degree?1:0);

  if (storage->pkey) {
    fprintf(output, "pkey: ");
    buffer_flush(storage->pkey, output);
    fprintf(output, "\n");
  }

  fprintf(output, "pkey_column_number: %i\n", storage->pkey_column_number);

  if (storage->pkey_sequence) {
    fprintf(output, "pkey_sequence: ");
    buffer_flush(storage->pkey_sequence, output);
    fprintf(output, "\n");
  }

  if (storage->pkey_default) {
    fprintf(output, "pkey_default: ");
    buffer_flush(storage->pkey_default, output);
    fprintf(output, "\n");
  }

  if (storage->attributes) {
    fprintf(output, "attributes: ");
    array_flush(storage->attributes, output);
    fprintf(output, "\n");
  }

  if (storage->not_null_columns) {
    fprintf(output, "not_null_columns: ");
    list_flush(storage->not_null_columns, output);
    fprintf(output, "\n");
  }

}
Пример #3
0
/* output error message
 * ----------------------------------------------------------------------- */
int sh_errorn(const char *s, unsigned int len) {
  sh_msg(NULL);
  buffer_put(fd_err->w, s, len);
  buffer_putm(fd_err->w, ": ", strerror(errno), "\n", NULL);
  buffer_flush(fd_err->w);
  return 1;
}
Пример #4
0
int main(int argc,char **argv)
{
  char *name;
  char *value;
  unsigned char ch;
  char octal[4];

  name = argv[1];
  if (!name) _exit(100);
  value = argv[2];
  if (!value) _exit(100);

  puts("char ");
  puts(name);
  puts("[] = \"\\\n");

  while ((ch = *value++)) {
    puts("\\");
    octal[3] = 0;
    octal[2] = '0' + (ch & 7); ch >>= 3;
    octal[1] = '0' + (ch & 7); ch >>= 3;
    octal[0] = '0' + (ch & 7);
    puts(octal);
  }

  puts("\\\n\";\n");
  if (buffer_flush(&b) == -1) _exit(111);
  _exit(0);
}
Пример #5
0
int flushread(int fd,char *buf,int len)
{
  int j;

  for (j = 0;j < cnum;++j)
    buffer_flush(&c[j].ss);
  if (flagforcerotate) {
    for (j = 0;j < cnum;++j)
      if (c[j].bytes > 0)
	fullcurrent(&c[j]);
    flagforcerotate = 0;
  }

  if (!len) return 0;
  if (flagexitasap) {
    if (flagnewline) return 0;
    len = 1;
  }

  sig_unblock(sig_term);
  sig_unblock(sig_alarm);

  len = read(fd,buf,len);

  sig_block(sig_term);
  sig_block(sig_alarm);

  if (len <= 0) return len;
  flagnewline = (buf[len - 1] == '\n');
  return len;
}
Пример #6
0
int main(int argc,char **argv)
{
    int i;

    dns_random_init(seed);

    if (*argv) ++argv;

    while (*argv) {
        if (!stralloc_copys(&fqdn,*argv))
            strerr_die2x(111,FATAL,"out of memory");
        if (dns_ip4(&out,&fqdn) == -1)
            strerr_die4sys(111,FATAL,"unable to find IP address for ",*argv,": ");

        for (i = 0; i + 4 <= out.len; i += 4) {
            buffer_put(buffer_1,str,ip4_fmt(str,out.s + i));
            buffer_puts(buffer_1," ");
        }
        buffer_puts(buffer_1,"\n");

        ++argv;
    }

    buffer_flush(buffer_1);
    _exit(0);
}
Пример #7
0
static int
_search_flush_and_process_buffer(ReaderArgs *args)
{
	int status = PROCESS_STATUS_OK;

	assert(args != NULL);
	assert(args->buffer != NULL);

	args->count = 0;

	if(args->cb && !buffer_is_empty(args->buffer))
	{
		status = _search_process_lines_from_buffer(args);

		if(status == PROCESS_STATUS_OK && buffer_flush(args->buffer, &args->line, &args->llen))
		{
			if(_search_process_line(args) == PROCESS_STATUS_OK)
			{
				if(args->count < INT32_MAX)
				{
					++args->count;
				}
			}
		}
	}

	return status;
}
Пример #8
0
int main (int argc, char const *const *argv)
{
  stralloc sa = STRALLOC_ZERO ;
  int path = 0, nl = 1 ;
  PROG = "s6-linkname" ;
  {
    subgetopt_t l = SUBGETOPT_ZERO ;
    for (;;)
    {
      register int opt = subgetopt_r(argc, argv, "nf", &l) ;
      if (opt == -1) break ;
      switch(opt)
      {
        case 'n' : nl = 0 ; break ;
        case 'f' : path = 1 ; break ;
        default :  dieusage() ;
      }
    }
    argv += l.ind ; argc -= l.ind ;
  }
  if (!argc) dieusage() ;

  if ((path ? sarealpath(&sa, *argv) : sareadlink(&sa, *argv)) == -1)
    strerr_diefu2sys(111, "resolve ", *argv) ;

  if ((buffer_putalign(buffer_1small, sa.s, sa.len) == -1)
   || (nl && (buffer_putalign(buffer_1small, "\n", 1)) == -1)
   || (buffer_flush(buffer_1small) == -1))
    strerr_diefu1sys(111, "write to stdout") ;

 /* stralloc_free(&sa) ; */
  return 0 ;
}
int iobufferu_flush (iobufferu_ref b)
{
  register int r = buffer_flush(&b->b[1]) ;
  b->b[0].n = b->b[1].n ;
  b->b[0].p = b->b[1].p ;
  return r ;
}
Пример #10
0
int
sln(const char* path) {
  stralloc s, d;
  char* to;
  ssize_t i;
  stralloc_init(&s);
  stralloc_copys(&s, path);

  stralloc_init(&d);
  stralloc_copy(&d, &s);

  while(reduce(&d)) {

    buffer_puts(buffer_2, "'");
    buffer_putsa(buffer_2, &d);
    buffer_puts(buffer_2, "' -> '");
    buffer_putsa(buffer_2, &s);
    buffer_puts(buffer_2, "'\n");
    buffer_flush(buffer_2);

    stralloc_nul(&s);
    stralloc_nul(&d);

    if(mklink_sa(&s, &d) == -1) {
      errmsg_warnsys("symlink failed", NULL);
      exit(2);
    }
    stralloc_copy(&s, &d);
  }

  return 0;
}
Пример #11
0
int
main(int argc, char* argv[]) {
  int fd;
  static struct cdb c;
  errmsg_iam("cdbget");
  if(argc < 3)
    die(1, "usage: cdbget data.cdb key");
  fd = open(argv[1], O_RDONLY | O_BINARY);
  if(fd == -1)
    diesys(1, "open");
  cdb_init(&c, fd);
  if(cdb_find(&c, argv[2], str_len(argv[2])) > 0) {
    do {
      char* x = malloc(cdb_datalen(&c));
      if(!x)
        die(1, "out of memory");
      if(cdb_read(&c, x, cdb_datalen(&c), cdb_datapos(&c)) == -1)
        diesys(1, "cdb_read");
      buffer_put(buffer_1, x, cdb_datalen(&c));
      buffer_put(buffer_1, "\n", 1);
      free(x);
    } while(cdb_findnext(&c, argv[2], str_len(argv[2])) > 0);
  }
  buffer_flush(buffer_1);
}
Пример #12
0
/*
 * stop
 */
void process_stop()
{
   //flush buffer, close & free things
   buffer_flush();
   close(fd);
   free(buffer);
}
Пример #13
0
static int doit(stralloc *out,int s,char ipremote[16],uint16 portremote,char iplocal[16],uint16 portlocal,unsigned int timeout,uint32 netif)
{
  buffer b;
  char bspace[128];
  char strnum[FMT_ULONG];
  int numcolons;
  char ch;

  if (socket_bind6(s,iplocal,0,netif) == -1) return -1;
  if (timeoutconn6(s,ipremote,113,timeout,netif) == -1) return -1;

  buffer_init(&b,mywrite,s,bspace,sizeof bspace);
  buffer_put(&b,strnum,fmt_ulong(strnum,portremote));
  buffer_put(&b," , ",3);
  buffer_put(&b,strnum,fmt_ulong(strnum,portlocal));
  buffer_put(&b,"\r\n",2);
  if (buffer_flush(&b) == -1) return -1;

  buffer_init(&b,myread,s,bspace,sizeof bspace);
  numcolons = 0;
  for (;;) {
    if (buffer_get(&b,&ch,1) != 1) return -1;
    if ((ch == ' ') || (ch == '\t') || (ch == '\r')) continue;
    if (ch == '\n') return 0;
    if (numcolons < 3) {
      if (ch == ':') ++numcolons;
    }
    else {
      if (!stralloc_append(out,&ch)) return -1;
      if (out->len > 256) return 0;
    }
  }
}
Пример #14
0
int
main (int argc, char *argv[])
{
    int n = 0;
    char *x = NULL;
    dns_random_init (seed);

    prog = strdup ((x = strrchr (argv[0], '/')) != NULL ? x + 1 : argv[0]);
    n = check_option (argc, argv);
    argv += n;
    argc -= n;

    while (*argv)
    {
        if (!ip4_scan (*argv, ip))
            errx (-1, "could not parse IP address `%s'", *argv);
        if (dns_name4 (&out, ip) == -1)
            errx (-1, "could not find host name for `%s'", *argv);

        buffer_put (buffer_1, out.s, out.len);
        buffer_puts (buffer_1,"\n");

        ++argv;
    }
    buffer_flush (buffer_1);

    return 0;
}
Пример #15
0
int count_depth() {
  char buffer[MAXIMUM_PATH_LENGTH];
  size_t len, i, c;
  for(;;) {
    buffer[0] = '\0';
    len = buffer_getline(buffer_0, buffer, sizeof(buffer));

    if(len == 0 || buffer[0] == '\0')
      break;

    if(buffer[len - 1 ] == '/')
      len--;

    c = 0;
    for(i = 0; i < len; i++) {
      if(buffer[i] == '/')
        c++;
    }
    buffer_putulong(buffer_1, (unsigned long)c);
    buffer_put(buffer_1, " ", 1);
    buffer_put(buffer_1, buffer, len);
    buffer_put(buffer_1, "\n", 1);
  }
  buffer_flush(buffer_1);
  return 0;
}
Пример #16
0
int buffer_putflush (buffer *b, char const *s, unsigned int len)
{
  int r = buffer_put(b, s, len) ;
  if (r < 0) return -1 ;
  if (!buffer_flush(b)) return -1 ;
  return r ;
}
Пример #17
0
void snap_dump(char *filename, stralloc *sa)
{
  dAVLCursor c;
  dAVLNode *node;
  char strip[IP6_FMT];
  char strnum[FMT_ULONG];
  int fd;

  fd = open_trunc("filename");  
  if(fd == -1)
    strerr_warn1(ARGV0 "warning: unable to open for tcp.tmp for writing", &strerr_sys);
  
  buffer_init(&wb, write, fd, wbspace, sizeof wbspace);

  node = dAVLFirst(&c, t);
  while(node)
    {
      buffer_put(&wb, strnum, fmt_ulong(strnum, node->key));
      buffer_puts(&wb, ",");
      buffer_put(&wb, strip, ip4_fmt(strip, node->ip4));
      buffer_puts(&wb, ",");
      buffer_put(&wb, strip, ip6_fmt(strip, node->ip6));
      buffer_puts(&wb, ",LOC\n");
      
      node = dAVLNext(&c);
    }
 
  buffer_flush(&wb);
  close(fd);
}
Пример #18
0
int main(int argc,char **argv)
{
  int i;
  char *x;
  char *y;
  unsigned int u;
  uint32 ttl;

  if (!cache_init(200)) _exit(111);

  if (*argv) ++argv;

  while (x = *argv++) {
    i = str_chr(x,':');
    if (x[i])
      cache_set(x,i,x + i + 1,str_len(x) - i - 1,86400,0);
    else {
      y = cache_get(x,i,&u,&ttl,0);
      if (y)
        buffer_put(buffer_1,y,u);
      buffer_puts(buffer_1,"\n");
    }
  }

  buffer_flush(buffer_1);
  _exit(0);
}
Пример #19
0
static int outputlines (stralloc const *s, unsigned int len)
{
  register unsigned int i = 0 ;
  for (; i < len ; i++)
    if (buffer_put(buffer_1, s[i].s, s[i].len) < 0) return 0 ;
  return buffer_flush(buffer_1) ;
}
Пример #20
0
static void carp(const char* routine) {
  buffer_flush(buffer_1);
  buffer_puts(buffer_2,"httpbench: ");
  buffer_puts(buffer_2,routine);
  buffer_puts(buffer_2,": ");
  buffer_puterror(buffer_2);
  buffer_putnlflush(buffer_2);
}
Пример #21
0
/*
 * write 1 event into the buffer
 */
static void buffer_event(event_t *e)
{
   hwe_cont *hwe = e->hwe;
   comp_t *c = e->comp;
	hwe_id_t ids[HWE_REF_MAX];

   // write main event into the buffer
   {
		for (unsigned i = 0; i < hwe_getnref(&hwe->common); i += 1) {
			ids[i] = hwe_ref2id(hwe_getref(&hwe->common, i));
		}

      size_t size = hwe_sizeof(hwe);
      if (bufsize + size + HWE_ID_SIZEOF > BUFFERSIZE)
         buffer_flush();

      // if necessary insert a HWE_ID
      if (!hwe_head_rid_compute(&hwe->common, c->data.lastid)) {
         hwe_id_write(&hwe->common, buffer + bufsize);
         bufsize += HWE_ID_SIZEOF;
      }

      hwe_write(hwe, &ids[0], buffer + bufsize);
      bufsize += size;
      
      //update id
      c->data.lastid = hwe->common.id.index;
   }
   
   // write additionals containers
   while ((hwe = ((hwe_cont *) hwe->common.refnext))) {
		for (unsigned i = 0; i < hwe_getnref(&hwe->common); i += 1) {
			ids[i] = hwe_ref2id(hwe_getref(&hwe->common, i));
		}
      
      size_t size = hwe_sizeof(hwe);
      if (bufsize + size > BUFFERSIZE)
         buffer_flush();

      //set rid to 0 (ie: same event)
      hwe_head_rid_zero(&hwe->common);

      hwe_write(hwe, &ids[0], buffer + bufsize);
      bufsize += size;
   }
}
Пример #22
0
void print(char *buf,unsigned int len)
{
  char tcpheader[2];
  uint16_pack_big(tcpheader,len);
  buffer_put(&netwrite,tcpheader,2);
  buffer_put(&netwrite,buf,len);
  buffer_flush(&netwrite);
}
Пример #23
0
inline int web_client_api_old_all_json(RRDHOST *host, struct web_client *w, char *url) {
    (void)url;

    w->response.data->contenttype = CT_APPLICATION_JSON;
    buffer_flush(w->response.data);
    rrd_all2json_api_old(host, w->response.data);
    return 200;
}
Пример #24
0
inline int web_client_api_request_v1_charts(RRDHOST *host, struct web_client *w, char *url) {
    (void)url;

    buffer_flush(w->response.data);
    w->response.data->contenttype = CT_APPLICATION_JSON;
    rrd_stats_api_v1_charts(host, w->response.data);
    return 200;
}
Пример #25
0
static int outputlines (stralloc const *s, unsigned int len)
{
  register unsigned int i = 0 ;
  for (; i < len ; i++)
    if (buffer_putalign(buffer_1, s[i].s, s[i].len) == -1) return -1 ;
  if (buffer_flush(buffer_1) == -1) return -1 ;
  return 0 ;
}
Пример #26
0
int buffer_put (register buffer_ref b, char const *buf, unsigned int len)
{
    if (len > (b->a - b->n))
    {
        buffer_clean(b) ;
        if ((len > (b->a - b->n)) && (buffer_flush(b) == -1)) return -1 ;
    }
    return buffer_putalign(b, buf, len) ;
}
Пример #27
0
static ssize_t
io_err_check(ssize_t ret) {
  if(ret == -1) {
    buffer_putm_3(buffer_2, "ERROR: ", strerror(errno), "\n");
    buffer_flush(buffer_2);
    exit(errno);
    /* return -1; */
  }
  return ret;
}
Пример #28
0
void
b64encode(const char* c, long len) {
  char* buf = malloc(len * 2 + 4);
  buffer_put(buffer_1, buf, fmt_base64(buf, c, len));
  if(isatty(1))
    buffer_putnlflush(buffer_1);
  else
    buffer_flush(buffer_1);
  free(buf);
}
Пример #29
0
void buffer_reset(BUFFER *wb)
{
    buffer_flush(wb);

    wb->contenttype = CT_TEXT_PLAIN;
    wb->options = 0;
    wb->date = 0;

    buffer_overflow_check(wb);
}
Пример #30
0
int write_fifodir(char *dirname, stralloc *sa, void (*oaw_func)(char *, stralloc *))
{
  DIR *dir = NULL;
  stralloc name = {0};
  struct dirent *x = NULL;
  static struct stat st;

  /* read directory */
  dir = opendir(dirname);
  if(dir == NULL)
    {
      strerr_warn3("can't opendir() ", dirname, ": ", &strerr_sys);
      return -1;
    }

  while (x = readdir(dir))
    {
      if(x == NULL)
	{
	  strerr_warn3("can't readdir() ", dirname, ": ", &strerr_sys);
	  if(name.a) 
	    stralloc_free(&name);
	  return -1;
	}

      /* Ignore everything starting with a . */
      if(x->d_name[0] != '.')
	{ 
	  stralloc_copys(&name, dirname);
	  stralloc_cats(&name, "/");
	  stralloc_cats(&name, x->d_name);
	  stralloc_0(&name);

	  if(stat(name.s, &st) == -1)
	    {
	      strerr_warn2("can't stat ", name.s, &strerr_sys);
	    }

	  if(S_ISFIFO(st.st_mode))
	    {
	      oaw_func(name.s, sa);
	    }
	  else
	    {
	      buffer_puts(buffer_2, "ddnsd: warning: ");
	      buffer_puts(buffer_2, name.s);
	      buffer_puts(buffer_2, " is no fifo, ignoring\n");
	      buffer_flush(buffer_2);
	    }
	}
    }
  closedir(dir);  

  return 0;
}