Exemplo n.º 1
0
Arquivo: parse.c Projeto: mfittko/oj
static void
unicode_to_chars(ParseInfo pi, Buf buf, uint32_t code) {
    if (0x0000007F >= code) {
	buf_append(buf, (char)code);
    } else if (0x000007FF >= code) {
	buf_append(buf, 0xC0 | (code >> 6));
	buf_append(buf, 0x80 | (0x3F & code));
    } else if (0x0000FFFF >= code) {
Exemplo n.º 2
0
static int telnet_putc(char c, FILE *stream) {
	if (c == '\n') {
		char r = '\r';
		buf_append(&buf, &r, 1);
	}

	buf_append(&buf, &c, 1);

	return 0;
}
Exemplo n.º 3
0
jserr_t js_print_keys(jsparser_t *p, size_t t, Buffer *b) {
  size_t v = js_tok(p, t)->first_child;
  jstok_t *tmp;
  if (js_tok(p, t)->type != JS_OBJECT) return JS_EBUG;
  while (v) {
    tmp = js_tok(p, v);
    buf_append(b, (p->js)->buf + tmp->start, tmp->end - tmp->start);
    if ((v = js_tok(p, v)->next_sibling)) buf_append(b, "\n", 1);
  }
  return 0;
}
Exemplo n.º 4
0
void append_dtls_ciphers(struct openconnect_info *vpninfo, struct oc_text_buf *buf)
{
#ifdef HAVE_DTLS12
#ifndef OPENSSL_NO_PSK
	buf_append(buf, "PSK-NEGOTIATE:");
#endif
	buf_append(buf, "OC-DTLS1_2-AES256-GCM:OC-DTLS1_2-AES128-GCM:");
#endif
	buf_append(buf, "DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:");
	buf_append(buf, "AES256-SHA:AES128-SHA:DES-CBC3-SHA:DES-CBC-SHA");
}
Exemplo n.º 5
0
PRIVATE ObjectStoreItem *read_item(FILE *f) {
  ObjectStoreItem *item = safe_malloc(sizeof(ObjectStoreItem));
  BUFFER varname;
  char str[1024];	/* %%% Yuck, a fixed-size buffer. */
  int key;

  if (fscanf(f, "%s %d [", str, &key) < 2) {
    free(item);
    return NULL;
  }

  item->tag = safe_string_dup(str);
  item->key = key;
  item->object = NULL;
  item->db = NULL;
  item->fields = g_hash_table_new(g_str_hash, g_str_equal);

  varname = newbuf(128);

  while (!feof(f)) {
    int ch;

    /* Strip leading whitespace (there _should_ always be some). */
    do { ch = fgetc(f); } while (isspace(ch) && (ch != ']') && (ch != EOF));

    if (ch == ']' || ch == EOF) {
      /* That's it. We're done with this item. */
      /* Empty line signals no more fields. */
      break;
    }

    /* Read the field name */
    do {
      buf_append(varname, ch);
      ch = fgetc(f);
    } while (!isspace(ch));

    /* Skip the whitespace and equals-sign */
    do { ch = fgetc(f); } while (isspace(ch) || ch == '=');
    ungetc(ch, f);

    /* Now we have the complete variable name in varname, and we are about to read the
       first character of the variable value. */
    buf_append(varname, '\0');
    objectstore_item_set(item, varname->buf, read_item_field_value(f));
    varname->pos = 0;	/* reset varname for next round */

    /* Trailing whitespace, if any, is dealt with at the top of the loop. */
  }

  killbuf(varname);
  return item;
}
Exemplo n.º 6
0
/* ARGSUSED */
static int
pmdoc_Fn(MDOC_ARGS)
{
	struct mdoc_node *nn;
	const char	*cp;

	nn = n->child;

	if (NULL == nn || MDOC_TEXT != nn->type)
		return(0);

	/* .Fn "struct type *name" "char *arg" */

	cp = strrchr(nn->string, ' ');
	if (NULL == cp)
		cp = nn->string;

	/* Strip away pointer symbol. */

	while ('*' == *cp)
		cp++;

	/* Store the function name. */

	buf_append(buf, cp);
	hash_put(hash, buf, TYPE_Fn);

	/* Store the function type. */

	if (nn->string < cp) {
		buf->len = 0;
		buf_appendb(buf, nn->string, cp - nn->string);
		buf_appendb(buf, "", 1);
		hash_put(hash, buf, TYPE_Ft);
	}

	/* Store the arguments. */

	for (nn = nn->next; nn; nn = nn->next) {
		if (MDOC_TEXT != nn->type)
			continue;
		buf->len = 0;
		buf_append(buf, nn->string);
		hash_put(hash, buf, TYPE_Fa);
	}

	return(0);
}
Exemplo n.º 7
0
void	command_report_error(buffer_t* out, const command_t* cmd, int error)
{
  int do_eol = 1;

  if (NULL == out || NULL == cmd)
    return;
  switch (error)
  {
  case ENONE:
    buf_append(out, "OK");
    break;
  case EIGNORE:
    do_eol = 0;
    break;
  case ENOCMD:
    buf_appendf(out, "ERR: No such command");
    break;
  case ENOSESSION:
    buf_appendf(out, "ERR: Session not found");
    break;
  case EUSAGE:
    command_usage(out, cmd);
    do_eol = 0;
    break;
  default:
    buf_appendf(out, "ERR: %s", strerror(error));
    break;
  }
  if (do_eol)
    buf_append_eol(out);
}
Exemplo n.º 8
0
puint STDCALL collect_add( pcollect pclt, puint input, uint type )
{
//   uint value;

   pclt->count++;
   buf_appenduint( ( pbuf )pclt, type );
   if ( (( povmtype )PCMD( type ))->stsize == 2 )
   {
      pclt->flag |= 0x01;
      buf_append( ( pbuf )pclt, ( pubyte )input, sizeof( long64 ));
      return input + 2;
   }
   else
   {
/*      value = *input;

      switch ( type )
      {
         case TUbyte: value = *( pubyte )input; break;
         case TByte: value = *( pbyte )input; break;
         case TUshort: value = *( pushort )input; break;
         case TShort: value = *( pshort )input; break;
         default: value = *input; break;
      }*/
      buf_appenduint( ( pbuf )pclt, *input );
   }
   return  input + 1;
}
Exemplo n.º 9
0
char * striptags(const char *s, unsigned int l)
{
	struct template_buffer *buf = buf_init(l);
	unsigned char *ptr = (unsigned char *)s;
	unsigned char *end = ptr + l;
	unsigned char *tag;
	unsigned char prev;
	char esq[8];
	int esl;

	for (prev = ' '; ptr < end; ptr++)
	{
		if ((*ptr == '<') && ((ptr + 2) < end) &&
			((*(ptr + 1) == '/') || isalpha(*(ptr + 1))))
		{
			for (tag = ptr; tag < end; tag++)
			{
				if (*tag == '>')
				{
					if (!isspace(prev))
						buf_putchar(buf, ' ');

					ptr = tag;
					prev = ' ';
					break;
				}
			}
		}
		else if (isspace(*ptr))
		{
			if (!isspace(prev))
				buf_putchar(buf, *ptr);

			prev = *ptr;
		}
		else
		{
			switch(*ptr)
			{
				case '"':
				case '\'':
				case '<':
				case '>':
				case '&':
					esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
					buf_append(buf, esq, esl);
					break;

				default:
					buf_putchar(buf, *ptr);
					break;
			}

			prev = *ptr;
		}
	}

	return buf_destroy(buf);
}
Exemplo n.º 10
0
/* Appends n characters in str to buf. */
struct Buf *buf_strnappend (struct Buf *buf, const char *str, int n)
{
	buf_append (buf, str, n + 1);

	/* "undo" the '\0' character that buf_append() already copied. */
	buf->nelts--;

	return buf;
}
Exemplo n.º 11
0
static void buf_append_unq(struct oc_text_buf *buf, const char *str)
{
	while (*str) {
		if (*str == '\"' || *str == '\\')
			buf_append(buf, "\\");
		buf_append_bytes(buf, str, 1);
		str++;
	}
}
Exemplo n.º 12
0
int v2_merge(BUFFER *mid)
{
  char fname[PATHMAX], line[LINELEN];
  BUFFER *temp, *msg;
  FILE *l, *f;
  int i, numpackets;
  struct stat sb;
  long d;
  int n;
  int err = -1;

  temp = buf_new();
  msg = buf_new();
  pool_packetfile(fname, mid, 0);
  l = fopen(fname, "a+");
  if (l != NULL)
    lock(l);

  pool_packetfile(fname, mid, 1);
  f = fopen(fname, "rb");
  if (f == NULL)
    goto end;
  fscanf(f, "%32s %ld %d %d\n", line, &d, &i, &numpackets);
  fclose(f);

  /* do we have all packets? */
  for (i = 1; i <= numpackets; i++) {
    pool_packetfile(fname, mid, i);
    if (stat(fname, &sb) != 0)
      goto end;
  }
  errlog(LOG, "Reassembling multipart message.\n");
  for (i = 1; i <= numpackets; i++) {
    pool_packetfile(fname, mid, i);
    f = fopen(fname, "rb");
    if (f == NULL)
      goto end;
    fscanf(f, "%32s %ld %d %d\n", line, &d, &n, &n);
    buf_clear(temp);
    buf_read(temp, f);
    v2body_setlen(temp);
    buf_append(msg, temp->data + 4, temp->length - 4);
    fclose(f);
    unlink(fname);
  }
  err = v2body(msg);

end:
  if (l != NULL)
    fclose(l);
  pool_packetfile(fname, mid, 0);
  unlink(fname);
  buf_free(temp);
  buf_free(msg);
  return (err);
}
Exemplo n.º 13
0
/*---------------------------------------------------------------------------*/
void
shell_default_output(const char *str1, int len1, const char *str2, int len2)
{
  if(len1 > 0 && str1[len1 - 1] == '\n') {
    --len1;
  }
  if(len2 > 0 && str2[len2 - 1] == '\n') {
    --len2;
  }

  /*  PRINTF("shell_default_output: %.*s %.*s\n", len1, str1, len2, str2);*/
  
#if TELNETD_CONF_GUI
  telnetd_gui_output(str1, len1, str2, len2);
#endif /* TELNETD_CONF_GUI */
  buf_append(&buf, str1, len1);
  buf_append(&buf, str2, len2);
  buf_append(&buf, "\r\n", 2);
}
Exemplo n.º 14
0
/* ARGSUSED */
static int
pmdoc_St(MDOC_ARGS)
{

	if (NULL == n->child || MDOC_TEXT != n->child->type)
		return(0);

	buf_append(buf, n->child->string);
	return(1);
}
Exemplo n.º 15
0
/*---------------------------------------------------------------------------*/
static void
sendopt(u8_t option, u8_t value)
{
  char line[4];
  line[0] = (char)TELNET_IAC;
  line[1] = option;
  line[2] = value;
  line[3] = 0;
  buf_append(&buf, line, 4);
}
Exemplo n.º 16
0
/* Sanitize given string and strip all invalid XML bytes
 * Validate UTF-8 sequences
 * Escape XML control chars */
char * pcdata(const char *s, unsigned int l)
{
	struct template_buffer *buf = buf_init(l);
	unsigned char *ptr = (unsigned char *)s;
	unsigned int o, v;
	char esq[8];
	int esl;

	if (!buf)
		return NULL;

	for (o = 0; o < l; o++)
	{
		/* Invalid XML bytes */
		if (((*ptr >= 0x00) && (*ptr <= 0x08)) ||
		    ((*ptr >= 0x0B) && (*ptr <= 0x0C)) ||
		    ((*ptr >= 0x0E) && (*ptr <= 0x1F)) ||
		    (*ptr == 0x7F))
		{
			ptr++;
		}

		/* Escapes */
		else if ((*ptr == 0x26) ||
		         (*ptr == 0x27) ||
		         (*ptr == 0x22) ||
		         (*ptr == 0x3C) ||
		         (*ptr == 0x3E))
		{
			esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);

			if (!buf_append(buf, esq, esl))
				break;

			ptr++;
		}

		/* ascii char */
		else if (*ptr <= 0x7F)
		{
			buf_putchar(buf, (char)*ptr++);
		}

		/* multi byte sequence */
		else
		{
			if (!(v = _validate_utf8(&ptr, l - o, buf)))
				break;

			o += (v - 1);
		}
	}

	return buf_destroy(buf);
}
Exemplo n.º 17
0
Arquivo: http.c Projeto: ttxie/comm
int main()
{
        int conn, len;
        const char *head = "HEAD /img/baidu_sylogo1.gif HTTP/1.1\r\nhost:www.baidu.com\r\nconnection:close\r\n\r\n";
        const char *get = "GET /img/baidu_sylogo1.gif HTTP/1.1\nhost:www.baidu.com\nconnection:keepalive\n\n";
        char buf_recv[256], get_buf[1024];
        struct buf_s *buf=buf_mmap(16*1024, "buf.data");

        conn = sk_connect("www.baidu.com", 80);
        if (conn == -1) {
                perror("connect err..");
                return 1;
        }
        
//        sk_nonblock(conn);
        send(conn, get, strlen(get), 0);
        if (buf == NULL) {
                perror("buf_mmap err");
                return 1;
        }
        printf("file:%s, len:%u\n", buf->buf_file, (unsigned)buf->buf_len);

        while (1) {
                len = recv(conn, buf_recv, sizeof(buf_recv), 0);
                if (len == -1) {
                        perror("recv err...\n");
                        break;
                }
                if (len == 0) {
                        printf("connection close.\n");
                        break; 
                }
                printf("recv len:%d\n", len);
                if (buf_append(buf, (u_char*)buf_recv, len) == -1) {
                        perror("buf_append err.");
                }
        }

				
        //hexdump(buf->buf_pos, buf->buf_len);
        printf("len:%d\n", (int)buf->buf_len);
        buf_pull(buf, (u_char*)get_buf, 1024);
        printf("len:%d\n", (int)buf->buf_len);
        //hexdump((u_char*)get_buf, 1024);
        //hexdump(buf->buf_start, buf->buf_len+1024);

//        printf("buf:%s\n", buf->buf_pos);
        errno = EPIPE;        
        printf("close:%d\n", close(conn)); 
        printf("errno:%d\n", errno);
        
        buf_free(buf);

        return 0;
}
Exemplo n.º 18
0
void luastr_escape(struct template_buffer *out, const char *s, unsigned int l,
				   int escape_xml)
{
	int esl;
	char esq[8];
	char *ptr;

	for (ptr = (char *)s; ptr < (s + l); ptr++)
	{
		switch (*ptr)
		{
		case '\\':
			buf_append(out, "\\\\", 2);
			break;

		case '"':
			if (escape_xml)
				buf_append(out, "&#34;", 5);
			else
				buf_append(out, "\\\"", 2);
			break;

		case '\n':
			buf_append(out, "\\n", 2);
			break;

		case '\'':
		case '&':
		case '<':
		case '>':
			if (escape_xml)
			{
				esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
				buf_append(out, esq, esl);
				break;
			}

		default:
			buf_putchar(out, *ptr);
		}
	}
}
Exemplo n.º 19
0
/*---------------------------------------------------------------------------*/
static void
sendopt(uint8_t option, uint8_t value)
{
  char line[4];
  line[0] = (char)TELNET_IAC;
  line[1] = option;
  line[2] = value;
  line[3] = 0;
  petsciiconv_topetscii(line, 4);
  buf_append(&buf, line, 4);
}
Exemplo n.º 20
0
ssize_t buf_append_read(Buffer *b, FILE *in) {
  char tmp[BUFSIZ];
  ssize_t bytes_r = 0;
  int fd = fileno(in);

  if ((bytes_r = read(fd, tmp, sizeof(tmp))) > 0)
    buf_append(b, (const char*) tmp, bytes_r);

  if (bytes_r < 0) die_err("can't read input");

  return bytes_r;
}
Exemplo n.º 21
0
static void buf_append_md5(struct oc_text_buf *buf, void *data, int len)
{
	unsigned char md5[16];
	int i;

	if (openconnect_md5(md5, data, len)) {
		buf->error = -EIO;
		return;
	}

	for (i = 0; i < 16; i++)
		buf_append(buf, "%02x", md5[i]);
}
Exemplo n.º 22
0
void buf_insert(BUFFER buf, char ch, int pos) {
  int i;

  if (pos < 0)
    pos = 0;
  if (pos > buf->pos)
    pos = buf->pos;

  buf_append(buf, 0);
  for (i = buf->pos; i > pos; i--)
    buf->buf[i] = buf->buf[i-1];
  buf->buf[pos] = ch;
}
Exemplo n.º 23
0
static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
{
	BUF *ret;

	if (pos1 < 0) return NULL;

	ret = buf_new();

	if (sz <= 0) sz = buf->size - pos1;

	buf_append(ret, buf->data + pos1, sz);

	return ret;
}
Exemplo n.º 24
0
/** Pushes "m4_undefine([[def]])m4_dnl" to end of buffer.
 * @param buf A buffer as a list of strings.
 * @param def The m4 symbol to undefine.
 * @return buf
 */
struct Buf *buf_m4_undefine (struct Buf *buf, const char* def)
{
    const char * fmt = "m4_undefine( [[%s]])m4_dnl\n";
    char * str;
    size_t strsz;

    str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2);
    if (!str)
        flexfatal (_("Allocation of buffer for m4 undef failed"));

    snprintf(str, strsz, fmt, def);
    buf_append(buf, &str, 1);
    return buf;
}
Exemplo n.º 25
0
/* ARGSUSED */
static int
pmdoc_Nm(MDOC_ARGS)
{

	if (SEC_NAME == n->sec)
		return(1);
	else if (SEC_SYNOPSIS != n->sec || MDOC_HEAD != n->type)
		return(0);

	if (NULL == n->child)
		buf_append(buf, m->name);

	return(1);
}
Exemplo n.º 26
0
/*-----------------------------------------------------------------------------
*
* ID: create_varmode 07.11.06 0.0.A.
*
* Summary: Добавление описания переменной, параметра в байткод функции
*
-----------------------------------------------------------------------------*/
STDCALL create_varmode( pbuf out, ps_desctype desctype, ps_descid descid )
{
   byte flags = 0; //Значение для поля flags
   uint off_flags; //Смещение поля с flags
   uint i;

   off_flags = out->use + sizeof( uint );
   if ( desctype )
   {
      buf_appenduint( out, desctype->idtype );
      buf_appendch( out, 0 );
      if ( desctype->oftype )
      {
         buf_appenduint( out, desctype->oftype );
         flags |= VAR_OFTYPE;
      }
   }
   else
   {
      buf_appenduint( out, descid->idtype );
      buf_appendch( out, 0 );
      if ( descid->flgdesc & DESCID_PAR )
         flags |= VAR_PARAM;
      if ( descid->flgdesc & DESCID_PAR || descid->idtype == TReserved )
      {
         if ( descid->oftype )
         {
            buf_appenduint( out, descid->oftype );
            flags |= VAR_OFTYPE;
         }
         if ( descid->msr )
         {
            buf_appendch( out, (byte)(descid->msr) );
            flags |= VAR_DIM;
            for ( i = 0; i < descid->msr; i++ )
            {
               buf_appenduint( out, descid->msrs[i] );
            }
         }
      }
      if ( _compile->flag & CMPL_DEBUG && descid->name )
      {           
         flags |= VAR_NAME;  
         buf_append( out, descid->name , mem_len( descid->name  ) + 1 );                                      
      }
   }
   *(byte *)( out->data + off_flags ) = flags;
}
Exemplo n.º 27
0
static int buf_read(BUF *buf, int fd)
{
	int len;
#ifndef MACINTOSH
	char tmp[BUFSIZE];
#else
	char *tmp;
	
	tmp = calloc( BUFSIZE , sizeof(char) );
#endif

	while ((len = read(fd, tmp, BUFSIZE)) > 0)
		buf_append(buf, tmp, len);

	return buf->size;
}
Exemplo n.º 28
0
/** Pushes "m4_define( [[def]], [[val]])m4_dnl" to end of buffer.
 * @param buf A buffer as a list of strings.
 * @param def The m4 symbol to define.
 * @param val The definition; may be NULL.
 * @return buf
 */
struct Buf *buf_m4_define (struct Buf *buf, const char* def, const char* val)
{
    const char * fmt = "m4_define( [[%s]], [[[[%s]]]])m4_dnl\n";
    char * str;
    size_t strsz;

    val = val?val:"";
    strsz = strlen(fmt) + strlen(def) + strlen(val) + 2;
    str = malloc(strsz);
    if (!str)
        flexfatal (_("Allocation of buffer for m4 def failed"));

    snprintf(str, strsz, fmt, def, val);
    buf_append(buf, &str, 1);
    return buf;
}
Exemplo n.º 29
0
static void http_post(int sd, cptr url, BUF *buf)
{
	BUF *output;

	output = buf_new();
	buf_sprintf(output, "POST %s HTTP/1.0\n", url);
	buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
		    FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);

	buf_sprintf(output, "Content-Length: %d\n", buf->size);
	buf_sprintf(output, "Content-Encoding: binary\n");
	buf_sprintf(output, "Content-Type: application/octet-stream\n");
	buf_sprintf(output, "\n");
	buf_append(output, buf->data, buf->size);

	soc_write(sd, output->data, output->size);
}
Exemplo n.º 30
0
/*
 * Recursively add all text from a given node.  
 * This is optimised for general mdoc nodes in this context, which do
 * not consist of subexpressions and having a recursive call for n->next
 * would be wasteful.
 * The "f" variable should be 0 unless called from pmdoc_Nd for the
 * description buffer, which does not start at the beginning of the
 * buffer.
 */
static void
buf_appendmdoc(struct buf *buf, const struct mdoc_node *n, int f)
{

	for ( ; n; n = n->next) {
		if (n->child)
			buf_appendmdoc(buf, n->child, f);

		if (MDOC_TEXT == n->type && f) {
			f = 0;
			buf_appendb(buf, n->string, 
					strlen(n->string) + 1);
		} else if (MDOC_TEXT == n->type)
			buf_append(buf, n->string);

	}
}