示例#1
0
static const char* markup_unescape2(const char *in, char **out, size_t *size)
{
    unsigned int   n;
    char  temp[2], buf[7];

    while (*in != 0) {
        if (*in == '&' && *(in + 1) == '#'
                && (sscanf(in, "&#%u%1[;]", &n, temp) == 2
                    || sscanf(in, "&#x%x%1[;]", &n, temp) == 2)
                && n != 0)
        {
            size_t buflen = uni2utf8(n, buf, sizeof(buf));

            if (copy_buf(out, size, buf, buflen) > 0)
                break;

            n = *(in + 2) == 'x' ? 3 : 2;
            while (isxdigit(in[n]))
                n++;

            if(in[n] == ';')
                n++;
            in += n;
        } else {
            if (*size <= 0)
                break;
            **out = *in++;
            *out += 1;
            *size -= 1;
        }
    }

    return in;
}
示例#2
0
const char *acl_xml_encode2(const char *in, size_t ilen, char **out, size_t *olen)
{
    const unsigned char *ptr = (const unsigned char*) in;
    const char *s;

    if (*olen == 0)
        return in;

    *olen -= 1;  /* reserve space for '\0' */

    while (ilen > 0) {
        if ((s = __charmap[*ptr]) != NULL) {
            if (copy_buf(out, olen, s, strlen(s)) > 0)
                break;
        } else if (*olen > 0) {
            **out = *ptr;
            *out += 1;
            *olen -= 1;
            if (*olen == 0)
                break;
        } else
            break;
        ptr++;
        ilen--;
    }

    **out = '\0';
    *out += 1;

    return (const char*) ptr;
}
示例#3
0
文件: ft_gnl.c 项目: thomasLeMeur/fdf
int			ft_gnl(int const fd, char **line)
{
	int			ret;
	char		*tmp;
	static char	buf[GNL_BUFF_SIZE];

	tmp = NULL;
	ft_memdel((void **)line);
	if (fd < 0 || !line)
		return (-1);
	if (*buf)
		if ((ret = copy_buf(buf, &tmp, 0)))
			return ((*line = tmp) ? ret : ret);
	while ((ret = read(fd, buf, GNL_BUFF_SIZE)) > 0)
		if ((ret = copy_buf(buf, &tmp, 1)))
			return ((*line = tmp) ? ret : ret);
	return (((*line = tmp) && ret != -1 && *tmp) ? 1 : ret);
}
示例#4
0
int read_file(int fd , char const   *uptime , size_t uptimelen , int outfd , char *outbuf ,
              size_t *outlen ) 
{ 
  int tmp ;
  int tmp___0 ;
  int tmp___1 ;

  {
  {
#line 132
  lseek(fd, (__off_t )0, 0);
#line 134
  tmp = append_buf(uptime, uptimelen, outfd, outbuf, outlen);
  }
#line 134
  if (tmp < 0) {
#line 135
    return (-1);
  }
  {
#line 137
  tmp___0 = copy_buf(fd, outfd, outbuf, outlen);
  }
#line 137
  if (tmp___0 < 0) {
#line 138
    return (-1);
  }
  {
#line 140
  tmp___1 = append_buf("\n", (size_t )1, outfd, outbuf, outlen);
  }
#line 140
  if (tmp___1 < 0) {
#line 141
    return (-1);
  }
#line 143
  return (0);
}
}
示例#5
0
void ofxSyncClient::synchronize() {
	// send data!
	std::iostream o(&request_);
	//ldir: "client" directory which we want to keep up2date
	//rdit: the "remote" directory on server with which we want to sync
	std::string ldir = "/Users/diederickhuijbers/Documents/programming/c++/of61fatxcode/apps/diederick/0059_sync_client/bin/data/test/";
	std::string rdir = "/Users/diederickhuijbers/Documents/programming/c++/of61fatxcode/apps/diederick/0058_sync_server/bin/data/images/";
	
	//o << "local_dir" << std::endl;
	//o << "remote_dir" << std::endl;
	dir_list_.getList(ldir, o);

	std::cout << "synchronize!" <<std::endl;

	uint32_t size = request_.size();
	uint32_t transfer_port = atoi(transfer_server_port_.c_str());
	std::iostream copy_buf(&size_buf_);
	copy_buf.write((char*)&size, sizeof(size));
	copy_buf.write((char*)&transfer_port, sizeof(transfer_port));
	ldir += "\n";
	rdir += "\n";
	copy_buf.write(ldir.c_str(), ldir.size());
	copy_buf.write(rdir.c_str(), rdir.size());
	copy_buf.write("\n", 1);

	cout << "size: "<< request_.size() << std::endl;

	boost::asio::async_write(
				socket_
				,size_buf_
				,boost::bind(
					&ofxSyncClient::handleSize
					,shared_from_this()
					,boost::asio::placeholders::error
				)
	);
	//io_service_.run_one();
}
static int reassemble(struct net_buf *mbuf)
{
  /* size of the IP packet (read from fragment) */
  uint16_t frag_size = 0;
  int8_t frag_context = 0;
  /* offset of the fragment in the IP packet */
  uint8_t frag_offset = 0;
  uint8_t is_fragment = 0;
  /* tag of the fragment */
  uint16_t frag_tag = 0;
  uint8_t first_fragment = 0, last_fragment = 0;
  struct net_buf *buf = NULL; 

  /* init */
  uip_uncomp_hdr_len(mbuf) = 0;
  uip_packetbuf_hdr_len(mbuf) = 0;

  /* The MAC puts the 15.4 payload inside the packetbuf data buffer */
  uip_packetbuf_ptr(mbuf) = packetbuf_dataptr(mbuf);

  /* Save the RSSI of the incoming packet in case the upper layer will
     want to query us for it later. */
  last_rssi = (signed short)packetbuf_attr(mbuf, PACKETBUF_ATTR_RSSI);

   /*
   * Since we don't support the mesh and broadcast header, the first header
   * we look for is the fragmentation header
   */
  switch((GET16(uip_packetbuf_ptr(mbuf), PACKETBUF_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) {
    case SICSLOWPAN_DISPATCH_FRAG1:
      PRINTF("reassemble: FRAG1 ");
      frag_offset = 0;
      frag_size = GET16(uip_packetbuf_ptr(mbuf), PACKETBUF_FRAG_DISPATCH_SIZE) & 0x07ff;
      frag_tag = GET16(uip_packetbuf_ptr(mbuf), PACKETBUF_FRAG_TAG);

      PRINTF("size %d, tag %d, offset %d\n", frag_size, frag_tag, frag_offset);

      if (frag_size > IP_BUF_MAX_DATA) {
        PRINTF("Too big packet %d bytes (max %d), fragment discarded\n",
	       frag_size, IP_BUF_MAX_DATA);
	goto fail;
      }

      uip_packetbuf_hdr_len(mbuf) += SICSLOWPAN_FRAG1_HDR_LEN;
      first_fragment = 1;
      is_fragment = 1;

      /* Add the fragment to the fragmentation context (this will also copy the payload)*/
      frag_context = add_fragment(mbuf, frag_tag, frag_size, frag_offset);
      if(frag_context == -1) {
        goto fail;
      }

      break;

    case SICSLOWPAN_DISPATCH_FRAGN:
      /*
       * set offset, tag, size
       * Offset is in units of 8 bytes
       */
      PRINTF("reassemble: FRAGN ");
      frag_offset = uip_packetbuf_ptr(mbuf)[PACKETBUF_FRAG_OFFSET];
      frag_tag = GET16(uip_packetbuf_ptr(mbuf), PACKETBUF_FRAG_TAG);
      frag_size = GET16(uip_packetbuf_ptr(mbuf), PACKETBUF_FRAG_DISPATCH_SIZE) & 0x07ff;

      PRINTF("reassemble: size %d, tag %d, offset %d\n", frag_size, frag_tag, frag_offset);

      uip_packetbuf_hdr_len(mbuf) += SICSLOWPAN_FRAGN_HDR_LEN;

      /* If this is the last fragment, we may shave off any extrenous
         bytes at the end. We must be liberal in what we accept. */
      /* Add the fragment to the fragmentation context  (this will also copy the payload) */
      frag_context = add_fragment(mbuf, frag_tag, frag_size, frag_offset);
      if(frag_context == -1) {
        goto fail;
      }

      if(frag_info[frag_context].reassembled_len >= frag_size) {
        last_fragment = 1;
      }
      is_fragment = 1;
      break;

    default:
      /* If there is no fragmentation header, then assume that the packet
       * is not fragmented and pass it as is to IP stack.
       */
      buf = copy_buf(mbuf);
      if(!buf || net_driver_15_4_recv(buf) < 0) {
        goto fail;
      }
      goto out;
  }

  /*
   * copy "payload" from the packetbuf buffer to the sicslowpan_buf
   * if this is a first fragment or not fragmented packet,
   * we have already copied the compressed headers, uncomp_hdr_len
   * and packetbuf_hdr_len are non 0, frag_offset is.
   * If this is a subsequent fragment, this is the contrary.
   */
  if(packetbuf_datalen(mbuf) < uip_packetbuf_hdr_len(mbuf)) {
    PRINTF("reassemble: packet dropped due to header > total packet\n");
    goto fail;
  }

  uip_packetbuf_payload_len(mbuf) = packetbuf_datalen(mbuf) - uip_packetbuf_hdr_len(mbuf);

  /* Sanity-check size of incoming packet to avoid buffer overflow */
  {
    int req_size = UIP_LLH_LEN + (uint16_t)(frag_offset << 3)
        + uip_packetbuf_payload_len(mbuf);

    if(req_size > UIP_BUFSIZE) {
      PRINTF("reassemble: packet dropped, minimum required IP_BUF size: %d+%d+%d=%d (current size: %d)\n", UIP_LLH_LEN, (uint16_t)(frag_offset << 3),
              uip_packetbuf_payload_len(mbuf), req_size, UIP_BUFSIZE);
      goto fail;
    }
  }

  if(frag_size > 0) {
    /* Add the size of the header only for the first fragment. */
    if(first_fragment != 0) {
      frag_info[frag_context].reassembled_len = uip_uncomp_hdr_len(mbuf) + uip_packetbuf_payload_len(mbuf);
    }

    /* For the last fragment, we are OK if there is extrenous bytes at
       the end of the packet. */
    if(last_fragment != 0) {
      frag_info[frag_context].reassembled_len = frag_size;
      /* copy to uip(net_buf) */
      buf = copy_frags2uip(frag_context);
      if(!buf)
        goto fail;
    }
  }

  /*
   * If we have a full IP packet in sicslowpan_buf, deliver it to
   * the IP stack
   */
  if(!is_fragment || last_fragment) {
    /* packet is in uip already - just set length */
    if(is_fragment != 0 && last_fragment != 0) {
      uip_len(buf) = frag_size;
    } else {
      uip_len(buf) = uip_packetbuf_payload_len(mbuf) + uip_uncomp_hdr_len(mbuf);
    }

    PRINTF("reassemble: IP packet ready (length %d)\n", uip_len(buf));

    if(net_driver_15_4_recv(buf) < 0) {
      goto fail;
    }
  }

out:
  /* free MAC buffer */
  l2_buf_unref(mbuf);
  return 1;

fail:
   if(buf) {
     ip_buf_unref(buf);
   }
   return 0;
}
示例#7
0
int read_proc(DIR *proc , char const   *uptime , size_t uptimelen , int outfd , char *outbuf ,
              size_t *outlen ) 
{ 
  struct dirent *ent ;
  int tmp ;
  char filename[4096] ;
  int fd ;
  int tmp___0 ;
  int tmp___1 ;
  int tmp___2 ;

  {
  {
#line 156
  rewinddir(proc);
#line 158
  tmp = append_buf(uptime, uptimelen, outfd, outbuf, outlen);
  }
#line 158
  if (tmp < 0) {
#line 159
    return (-1);
  }
  {
#line 161
  while (1) {
    while_continue: /* CIL Label */ ;
    {
#line 161
    ent = readdir(proc);
    }
#line 161
    if (! ((unsigned long )ent != (unsigned long )((void *)0))) {
#line 161
      goto while_break;
    }
#line 165
    if ((int )ent->d_name[0] < 48) {
#line 166
      goto while_continue;
    } else
#line 165
    if ((int )ent->d_name[0] > 57) {
#line 166
      goto while_continue;
    }
    {
#line 168
    sprintf((char */* __restrict  */)(filename), (char const   */* __restrict  */)"/proc/%s/stat",
            ent->d_name);
#line 170
    fd = open((char const   *)(filename), 0);
    }
#line 171
    if (fd < 0) {
#line 172
      goto while_continue;
    }
    {
#line 174
    tmp___0 = copy_buf(fd, outfd, outbuf, outlen);
#line 177
    tmp___1 = close(fd);
    }
#line 177
    if (tmp___1 < 0) {
#line 178
      goto while_continue;
    }
  }
  while_break: /* CIL Label */ ;
  }
  {
#line 181
  tmp___2 = append_buf("\n", (size_t )1, outfd, outbuf, outlen);
  }
#line 181
  if (tmp___2 < 0) {
#line 182
    return (-1);
  }
#line 184
  return (0);
}
}