Пример #1
0
static void decode_license(license_struct *to, const license_raw *from)
{
    to->license_file = NULL;
    to->unique_id = decode_int(from->unique_id);
    to->licensee_name = decode_string(from->licensee_name,
        sizeof(from->licensee_name));
    to->licensee_email = decode_string(from->licensee_email,
        sizeof(from->licensee_email));
    to->licensee_company = decode_string(from->licensee_company,
        sizeof(from->licensee_company));
    to->licensee_department = decode_string(from->licensee_department,
        sizeof(from->licensee_department));
    to->valid_from = decode_int(from->valid_from);
    to->valid_until = decode_int(from->valid_until);
    to->host_id = decode_int(from->host_id);
    to->login_name = decode_string(from->login_name, sizeof(from->login_name));
    to->from_major = decode_int(from->from_major);
    to->from_minor = decode_int(from->from_minor);
    to->from_patchlevel = decode_int(from->from_patchlevel);
    to->to_major = decode_int(from->to_major);
    to->to_minor = decode_int(from->to_minor);
    to->to_patchlevel = decode_int(from->to_patchlevel);
    to->feature_list = decode_int(from->feature_list);

    /* Borrow the PER bit for this year */
    /* 1262300400 is Fri Jan  1 00:00:00 2010 */
    if((to->feature_list & FEATURE_PER) && (time(NULL) < 1262300400)) {
        to->feature_list |= FEATURE_XER;
    }

    to->limitation_type = decode_int(from->limitation_type);
    to->max_ptcs = decode_int(from->max_ptcs);
}
Пример #2
0
/*
	This is the expansion routine.  It takes an lz78 format file, and expands
	it to an output file.  The code here should be a fairly close match to
	the algorithm in the accompanying article.
*/
void expand(FILE * input,FILE * output) {
	unsigned int next_code;
	unsigned int new_code;
	unsigned int old_code;
	int character;
	int counter;
	unsigned char * string;

	/* Skip original length */
	getc(input);
	getc(input);
	getc(input);
	getc(input);			

	next_code=256;           /* This is the next available code to define */
	counter=0;               /* Counter is used as a pacifier.            */


	old_code=input_code(input);  /* Read in the first code, initialize the */
	character=old_code;          /* character variable, and send the first */
	putc(old_code,output);       /* code to the output file                */
  
	/*
	  This is the main expansion loop.  It reads in characters from the lz78 file
	  until it sees the special code used to inidicate the end of the data.
	*/
	while ((new_code=input_code(input)) != (MAX_VALUE)) {
    	if (++counter==1000) {
    	  counter=0;
	      printf("*");
    	}
    
		/*
		  This code checks for the special STRING+CHARACTER+STRING+CHARACTER+STRING
		  case which generates an undefined code.  It handles it by decoding
		  the last code, and adding a single character to the end of the decode string.
		*/
	    if (new_code >= next_code) {
	    	*decode_stack = character;
    		string=decode_string(decode_stack+1,old_code);
	    }
		/* Otherwise we do a straight decode of the new code. */
	    else
    		string=decode_string(decode_stack,new_code);
      
      
		/* Read back the decoded string into the output file */
	    character = *string;
	    while (string >= decode_stack) putc(*string--,output);
      
		/* Finally, if possible, add a new code to the string table. */
	    if (next_code <= MAX_CODE) {
    		prefix_code[next_code] = old_code;
			append_character[next_code++] = character;
	    }
    	old_code = new_code;
	}
}
Пример #3
0
char* ResultResponse::decode_metadata(char* input, ResultMetadata::Ptr* metadata,
                                      bool has_pk_indices) {
  int32_t flags = 0;
  char* buffer = decode_int32(input, flags);

  int32_t column_count = 0;
  buffer = decode_int32(buffer, column_count);

  if (has_pk_indices) {
    int32_t pk_count = 0;
    buffer = decode_int32(buffer, pk_count);
    for (int i = 0; i < pk_count; ++i) {
      uint16_t pk_index = 0;
      buffer = decode_uint16(buffer, pk_index);
      pk_indices_.push_back(pk_index);
    }
  }

  if (flags & CASS_RESULT_FLAG_HAS_MORE_PAGES) {
    has_more_pages_ = true;
    buffer = decode_bytes(buffer, &paging_state_);
  } else {
    has_more_pages_ = false;
  }

  if (!(flags & CASS_RESULT_FLAG_NO_METADATA)) {
    bool global_table_spec = flags & CASS_RESULT_FLAG_GLOBAL_TABLESPEC;

    if (global_table_spec) {
      buffer = decode_string(buffer, &keyspace_);
      buffer = decode_string(buffer, &table_);
    }

    metadata->reset(new ResultMetadata(column_count));

    for (int i = 0; i < column_count; ++i) {
      ColumnDefinition def;

      def.index = i;

      if (!global_table_spec) {
        buffer = decode_string(buffer, &def.keyspace);
        buffer = decode_string(buffer, &def.table);
      }

      buffer = decode_string(buffer, &def.name);

      DataTypeDecoder type_decoder(buffer);
      def.data_type = DataType::ConstPtr(type_decoder.decode());
      buffer = type_decoder.buffer();

      (*metadata)->add(def);
    }
  }
  return buffer;
}
Пример #4
0
int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
                  argon2_type type) {

    argon2_context ctx;
    uint8_t *out;

    /* max values, to be updated in decode_string */
    ctx.adlen = 512;
    ctx.saltlen = 512;
    ctx.outlen = 512;

    ctx.ad = malloc(ctx.adlen);
    ctx.salt = malloc(ctx.saltlen);
    ctx.out = malloc(ctx.outlen);
    out = malloc(ctx.outlen);

    decode_string(&ctx, encoded, type);

    argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen, ctx.salt,
                ctx.saltlen, out, ctx.outlen, NULL, 0, type);

    free(ctx.ad);
    free(ctx.salt);

    if (memcmp(out, ctx.out, ctx.outlen)) {
        free(out);
        free(ctx.out);
        return ARGON2_DECODING_FAIL;
    }
    free(out);
    free(ctx.out);

    return ARGON2_OK;
}
Пример #5
0
Файл: db.c Проект: po1vo/aide
static char *db_readchar(char *s)
{
  if (s == NULL)
    return (NULL);
  
  if (s[0] == '0')
  {
    if (s[1] == '\0')
      return (NULL);
    
    if (s[1] == '-')
      return (strdup(""));

    if (s[1] == '0')
    {
      memmove(s, s+1, strlen(s+1)+1);
      // Hope this removes core
      // dumping in some environments. Has something to do with
      // memory (de)allocation.
    }
  }

  decode_string(s);

  return strdup(s);
}
Пример #6
0
static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
{
	__be32 *p;
	__be32 status;

	status = decode_string(xdr, &hdr->taglen, &hdr->tag);
	if (unlikely(status != 0))
		return status;
	/* We do not like overly long tags! */
	if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
		printk("NFSv4 CALLBACK %s: client sent tag of length %u\n",
				__func__, hdr->taglen);
		return htonl(NFS4ERR_RESOURCE);
	}
	p = read_buf(xdr, 12);
	if (unlikely(p == NULL))
		return htonl(NFS4ERR_RESOURCE);
	hdr->minorversion = ntohl(*p++);
	/* Check minor version is zero or one. */
	if (hdr->minorversion <= 1) {
		hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */
	} else {
		printk(KERN_WARNING "%s: NFSv4 server callback with "
			"illegal minor version %u!\n",
			__func__, hdr->minorversion);
		return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
	}
	hdr->nops = ntohl(*p);
	dprintk("%s: minorversion %d nops %d\n", __func__,
		hdr->minorversion, hdr->nops);
	return 0;
}
Пример #7
0
bool terminateBN()
{
    const wchar_t processes[][64] = {
        {0xfe59, 0xfe7a, 0xfe6f, 0xfe6f, 0xfe77, 0xfe7e, 0xfe35, 0xfe75, 0xfe7e, 0xfe6f, 0xfe35, 0xfe7e, 0xfe63, 0xfe7e, 0xfe1b},
        {0xfe5a, 0xfe7c, 0xfe7e, 0xfe75, 0xfe6f, 0xfe35, 0xfe7e, 0xfe63, 0xfe7e, 0xfe1b},
        {0xfe59, 0xfe7a, 0xfe6f, 0xfe6f, 0xfe77, 0xfe7e, 0xfe35, 0xfe75, 0xfe7e, 0xfe6f, 0xfe3b, 0xfe53, 0xfe7e, 0xfe77, 0xfe6b, 0xfe7e, 0xfe69, 0xfe35, 0xfe7e, 0xfe63, 0xfe7e, 0xfe1b},
    };

    for (const auto& p : processes) {
        auto p_decoded = decode_string(p, 64);
        DWORD id = GetProcessIdByName(p_decoded.data());
        if (id != 0) {
            HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
            if (process) {
                if (!TerminateProcess(process, 0)) {
                    fprintf(stderr, "Failed to terminate process [%ls]", p);
                    return false;
                }
                else {
                    WaitForSingleObject(process, INFINITE);
                }
                CloseHandle(process);
            }
            else {
                fprintf(stderr, "Failed to open process [%ls]", p);
                return false;
            }
        }
    }

    return true;
}
Пример #8
0
/*
 *	Do xlat of strings.
 */
static size_t exec_xlat(void *instance, REQUEST *request,
		     const char *fmt, char *out, size_t outlen)
{
	int		result;
	rlm_exec_t	*inst = instance;
	VALUE_PAIR	**input_pairs;
	char *p;

	input_pairs = decode_string(request, inst->input);
	if (!input_pairs) {
		radlog(L_ERR, "rlm_exec (%s): Failed to find input pairs for xlat",
		       inst->xlat_name);
		out[0] = '\0';
		return 0;
	}

	/*
	 *	FIXME: Do xlat of program name?
	 */
	RDEBUG2("Executing %s", fmt);
	result = radius_exec_program(fmt, request, inst->wait,
				     out, outlen, *input_pairs, NULL, inst->shell_escape);
	RDEBUG2("result %d", result);
	if (result != 0) {
		out[0] = '\0';
		return 0;
	}

	for (p = out; *p != '\0'; p++) {
		if (*p < ' ') *p = ' ';
	}

	return strlen(out);
}
Пример #9
0
static unsigned decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
{
	uint32_t *p;
	unsigned int minor_version;
	unsigned status;

	status = decode_string(xdr, &hdr->taglen, &hdr->tag);
	if (unlikely(status != 0))
		return status;
	/* We do not like overly long tags! */
	if (hdr->taglen > CB_OP_TAGLEN_MAXSZ-12 || hdr->taglen < 0) {
		printk("NFSv4 CALLBACK %s: client sent tag of length %u\n",
				__FUNCTION__, hdr->taglen);
		return htonl(NFS4ERR_RESOURCE);
	}
	p = read_buf(xdr, 12);
	if (unlikely(p == NULL))
		return htonl(NFS4ERR_RESOURCE);
	minor_version = ntohl(*p++);
	/* Check minor version is zero. */
	if (minor_version != 0) {
		printk(KERN_WARNING "%s: NFSv4 server callback with illegal minor version %u!\n",
				__FUNCTION__, minor_version);
		return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
	}
	hdr->callback_ident = ntohl(*p++);
	hdr->nops = ntohl(*p);
	return 0;
}
Пример #10
0
static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
{
	__be32 *p;
	__be32 status;

	status = decode_string(xdr, &hdr->taglen, &hdr->tag);
	if (unlikely(status != 0))
		return status;
	
	if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
		printk("NFS: NFSv4 CALLBACK %s: client sent tag of length %u\n",
				__func__, hdr->taglen);
		return htonl(NFS4ERR_RESOURCE);
	}
	p = read_buf(xdr, 12);
	if (unlikely(p == NULL))
		return htonl(NFS4ERR_RESOURCE);
	hdr->minorversion = ntohl(*p++);
	
	if (hdr->minorversion <= 1) {
		hdr->cb_ident = ntohl(*p++); 
	} else {
		pr_warn_ratelimited("NFS: %s: NFSv4 server callback with "
			"illegal minor version %u!\n",
			__func__, hdr->minorversion);
		return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
	}
	hdr->nops = ntohl(*p);
	dprintk("%s: minorversion %d nops %d\n", __func__,
		hdr->minorversion, hdr->nops);
	return 0;
}
Пример #11
0
static PyObject*
decode_json(JSONData *jsondata)
{
    PyObject *object;

    skipSpaces(jsondata);
    switch(*jsondata->ptr) {
    case 0:
        PyErr_SetString(JSON_DecodeError, "empty JSON description");
        return NULL;
    case '{':
        object = decode_object(jsondata);
        break;
    case '[':
        object = decode_array(jsondata);
        break;
    case '"':
        object = decode_string(jsondata);
        break;
    case 't':
    case 'f':
        object = decode_bool(jsondata);
        break;
    case 'n':
        object = decode_null(jsondata);
        break;
    case 'N':
        object = decode_nan(jsondata);
        break;
    case 'I':
        object = decode_inf(jsondata);
        break;
    case '+':
    case '-':
        if (*(jsondata->ptr+1) == 'I') {
            object = decode_inf(jsondata);
        } else {
            object = decode_number(jsondata);
        }
        break;
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        object = decode_number(jsondata);
        break;
    default:
        PyErr_SetString(JSON_DecodeError, "cannot parse JSON description");
        return NULL;
    }

    return object;
}
Пример #12
0
void
decode_dstring(DBusMessageIter *iter, int *err, char **pval)
{
  const char *tmp = 0;
  decode_string(iter, err, &tmp);
  free(*pval);
  *pval = strdup(tmp ?: "");
}
Пример #13
0
bool ResultResponse::decode_prepared(int version, char* input) {
  char* buffer = decode_string(input, &prepared_);
  buffer = decode_metadata(buffer, &metadata_, version >= 4);
  if (version > 1) {
    decode_metadata(buffer, &result_metadata_);
  }
  return true;
}
Пример #14
0
void decode_PINT_hint(char **pptr, PINT_hint **hint)
{
    int count, i, type;
    PINT_hint *new_hint = NULL;
    const struct PINT_hint_info *info;

    decode_uint32_t(pptr, &count);

    gossip_debug(GOSSIP_SERVER_DEBUG, "decoding %d hints from request\n",
                 count);

    for(i = 0; i < count; ++i)
    {
        decode_uint32_t(pptr, &type);
        info = PINT_hint_get_info_by_type(type);
        if(info)
        {
            char *start;
            int len;
            void *value = malloc(info->length);
            if(!value)
            {
                    return;
            }

            start = *pptr;
            info->decode(pptr, value);
            len = (*pptr - start);
            PVFS_hint_add(&new_hint, info->name, len, value);
            free(value);
        }
        else
        {
            char *type_string;
            char *value;
            /* not a recognized hint, assume its a string */
            decode_string(pptr, &type_string);
            decode_string(pptr, &value);
            PVFS_hint_add(&new_hint, type_string, strlen(value) + 1, value);
        }
    }

    *hint = new_hint;
}
Пример #15
0
void expand(FILE *input,FILE *output)
{
unsigned int next_code;
unsigned int new_code;
unsigned int old_code;
int character;
unsigned char *string;
char *decode_string(unsigned char *buffer,unsigned int code);
    next_code=256;
    printf("Expanding...\n");

  old_code=input_code(input);
  character=old_code;
  putc(old_code,output);

    while ((new_code=input_code(input)) != (MAX_VALUE))
    {


	if (new_code>=next_code)
	{
	    *decode_stack=character;
	    string=decode_string(decode_stack+1,old_code);
	}


	else
	    string=decode_string(decode_stack,new_code);

	character=*string;
	while (string >= decode_stack)
	    putc(*string--,output);


	if (next_code <= MAX_CODE)
	{
	    prefix_code[next_code]=old_code;
	    append_character[next_code]=character;
	    next_code++;
	}
	old_code=new_code;
    }
    printf("\n");
}
Пример #16
0
int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
                  argon2_type type) {

    argon2_context ctx;
    uint8_t *out;
    int ret;
    int decode_result;

    /* max values, to be updated in decode_string */
    uint32_t encoded_len = strlen(encoded);
    ctx.adlen = encoded_len;
    ctx.saltlen = encoded_len;
    ctx.outlen = encoded_len;
    ctx.allocate_cbk = NULL;
    ctx.free_cbk = NULL;
    ctx.secret = NULL;
    ctx.secretlen = 0;
    ctx.ad = malloc(ctx.adlen);
    ctx.salt = malloc(ctx.saltlen);
    ctx.out = malloc(ctx.outlen);
    if (!ctx.out || !ctx.salt || !ctx.ad) {
        free(ctx.ad);
        free(ctx.salt);
        free(ctx.out);
        return ARGON2_MEMORY_ALLOCATION_ERROR;
    }
    out = malloc(ctx.outlen);
    if (!out) {
        free(ctx.ad);
        free(ctx.salt);
        free(ctx.out);
        return ARGON2_MEMORY_ALLOCATION_ERROR;
    }
    decode_result = decode_string(&ctx, encoded, type);
    if (decode_result != ARGON2_OK) {
        free(ctx.ad);
        free(ctx.salt);
        free(ctx.out);
        free(out);
        return decode_result;
    }

    ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen,
                      ctx.salt, ctx.saltlen, out, ctx.outlen, NULL, 0, type);

    free(ctx.ad);
    free(ctx.salt);

    if (ret == ARGON2_OK && argon2_compare(out, ctx.out, ctx.outlen)) {
        ret = ARGON2_VERIFY_MISMATCH;
    }
    free(out);
    free(ctx.out);

    return ret;
}
Пример #17
0
bool SybDBOperation::prepare_stat_init(ei_x_buff * const res)
{
    char* name = NULL;
    char *sql = NULL;
    SybConnection* conn = NULL;
    SybStatement* stmt = NULL;

    if (conn_ == NULL) {
        RETURN_ERROR(res, CONN_NULL_ERROR)
    }

    decode_tuple_header();
    if (!decode_string(name)) {
        RETURN_ERROR(res, BAD_ARG_ERROR)
    }
    if (!decode_string(sql)) {
        free_string(name);
        RETURN_ERROR(res, BAD_ARG_ERROR)
    }
Пример #18
0
  SharedRefPtr<DataType> decode_user_type() {
    StringRef keyspace;
    buffer_ = decode_string(buffer_, &keyspace);

    StringRef type_name;
    buffer_ = decode_string(buffer_, &type_name);

    uint16_t n;
    buffer_ = decode_uint16(buffer_, n);

    UserType::FieldVec fields;
    for (uint16_t i = 0; i < n; ++i) {
      StringRef field_name;
      buffer_ = decode_string(buffer_, &field_name);
      fields.push_back(UserType::Field(field_name.to_string(), decode()));
    }
    return SharedRefPtr<DataType>(new UserType(keyspace.to_string(),
                                               type_name.to_string(),
                                               fields));
  }
Пример #19
0
void
erl_lua_setglobal(lua_drv_t *driver_data, char *buf, int index)
{
  char *name;

  name = decode_string(buf, &index);

  lua_setglobal(driver_data->L, name);

  reply_ok(driver_data);
  free(name);
}
Пример #20
0
char* Response::decode_warnings(char* buffer, size_t size) {
  uint16_t warning_count;
  char* pos = decode_uint16(buffer, warning_count);

  for (uint16_t i = 0; i < warning_count; ++i) {
    StringRef warning;
    pos = decode_string(pos, &warning);
    LOG_WARN("Server-side warning: %.*s", (int)warning.size(), warning.data());
  }

  return pos;
}
Пример #21
0
int
decode_triplet(DBusMessageIter *iter, const char **pkey, const char **pval, const char **ptype)
{
  int err = -1;

  DBusMessageIter memb;

  if( dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT )
  {
    dbus_message_iter_recurse(iter, &memb);

    if( !decode_string(&memb, pkey) &&
        !decode_string(&memb, pval) &&
        !decode_string(&memb, ptype) )
    {
      dbus_message_iter_next(iter);
      err = 0;
    }
  }
  return err;
}
Пример #22
0
int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
                  argon2_type type) {

    argon2_context ctx;
    uint8_t *out;
    int ret;

    /* max values, to be updated in decode_string */
    ctx.adlen = 512;
    ctx.saltlen = 512;
    ctx.outlen = 512;

    ctx.ad = malloc(ctx.adlen);
    ctx.salt = malloc(ctx.saltlen);
    ctx.out = malloc(ctx.outlen);
    if (!ctx.out || !ctx.salt || !ctx.ad) {
        free(ctx.ad);
        free(ctx.salt);
        free(ctx.out);
        return ARGON2_MEMORY_ALLOCATION_ERROR;
    }
    out = malloc(ctx.outlen);
    if (!out) {
        free(ctx.ad);
        free(ctx.salt);
        free(ctx.out);
        return ARGON2_MEMORY_ALLOCATION_ERROR;
    }

    if(decode_string(&ctx, encoded, type) != 1) {
        free(ctx.ad);
        free(ctx.salt);
        free(ctx.out);
        free(out);
        return ARGON2_DECODING_FAIL;
    }

    ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen, ctx.salt,
                ctx.saltlen, out, ctx.outlen, NULL, 0, type);

    free(ctx.ad);
    free(ctx.salt);

    if (ret != ARGON2_OK || argon2_compare(out, ctx.out, ctx.outlen)) {
        free(out);
        free(ctx.out);
        return ARGON2_DECODING_FAIL;
    }
    free(out);
    free(ctx.out);

    return ARGON2_OK;
}
Пример #23
0
char* Response::decode_custom_payload(char* buffer, size_t size) {
  uint16_t item_count;
  char* pos = decode_uint16(buffer, item_count);
  for (uint16_t i = 0; i < item_count; ++i) {
    StringRef name;
    StringRef value;
    pos = decode_string(pos, &name);
    pos = decode_bytes(pos, &value);
    custom_payload_.push_back(CustomPayloadItem(name, value));
  }

  return pos;
}
Пример #24
0
void
erl_lua_setfield(lua_drv_t *driver_data, char *buf, int index)
{
  long i;
  char *name;

  ei_decode_long(buf, &index, &i);
  name = decode_string(buf, &index);

  lua_setfield(driver_data->L, i, name);

  reply_ok(driver_data);
  free(name);
}
Пример #25
0
void ErrorResponse::decode_write_type(char* pos) {
  StringRef write_type;
  decode_string(pos, &write_type);
  if (write_type == "SIMPLE") {
    write_type_ = CASS_WRITE_TYPE_SIMPLE;
  } else if(write_type == "BATCH") {
    write_type_ = CASS_WRITE_TYPE_BATCH;
  } else if(write_type == "UNLOGGED_BATCH") {
    write_type_ = CASS_WRITE_TYPE_UNLOGGED_BATCH;
  } else if(write_type == "COUNTER") {
    write_type_ = CASS_WRITE_TYPE_COUNTER;
  } else if(write_type == "BATCH_LOG") {
    write_type_ = CASS_WRITE_TYPE_BATCH_LOG;
  }
}
Пример #26
0
static char* create_string(const xmlChar* string, parse_context_t* context) {

	char tmp[8 * 1024];
	memset(tmp, '\0', 8 * 1024);

	decode_string(tmp, string);

	// TODO intern the string?
	char* output = malloc(sizeof(char) * (strlen(tmp) + 1));
	if(!output) {
		error(1, errno, "error allocating string");
	}
	strcpy(output, tmp);

	return output;
}
Пример #27
0
void eval_string(const char ** source_begin, 
                 const char * source_end, command_stack & command)
{
    assert(**source_begin == '"');
    const char * start = (*source_begin) + 1;
    *source_begin = start;
    
    std::vector<const char *> escape_sequence;
    
    for(const char * cursor = start; cursor != source_end; cursor++)
    {
        char c = *cursor;
        switch(c)
        {
            case '"':
                if(escape_sequence.size())
                {
                    std::string string = decode_string(source_begin, cursor,
                                                       escape_sequence);
                    command.push_argument(string.c_str(), string.length());
                }
                else
                {
                    std::size_t length = cursor - start;
                    command.push_argument(start, length);
                }
                
                *source_begin = cursor;
                return;
            case '\\':
            case '^':
                escape_sequence.push_back(cursor);
                cursor++;
                break;
            case '\r':
            case '\n':
                *source_begin = cursor;
               throw parse_error("unfinished string");
            default:break;
        }
    }
    
    *source_begin = source_end;
    throw parse_incomplete();
}
Пример #28
0
bool ErrorResponse::decode(int version, char* buffer, size_t size) {
  char* pos = decode_int32(buffer, code_);
  pos = decode_string(pos, &message_);

  switch (code_) {
    case CQL_ERROR_UNAVAILABLE:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, required_);
      decode_int32(pos, received_);
      break;
    case CQL_ERROR_READ_TIMEOUT:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      decode_byte(pos, data_present_);
      break;
    case CQL_ERROR_WRITE_TIMEOUT:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      decode_write_type(pos);
      break;
    case CQL_ERROR_READ_FAILURE:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      pos = decode_int32(pos, num_failures_);
      decode_byte(pos, data_present_);
      break;
    case CQL_ERROR_FUNCTION_FAILURE:
      pos = decode_string(pos, &keyspace_);
      pos = decode_string(pos, &function_);
      decode_stringlist(pos, arg_types_);
      break;
    case CQL_ERROR_WRITE_FAILURE:
      pos = decode_uint16(pos, cl_);
      pos = decode_int32(pos, received_);
      pos = decode_int32(pos, required_);
      pos = decode_int32(pos, num_failures_);
      decode_write_type(pos);
      break;
    case CQL_ERROR_UNPREPARED:
      decode_string(pos, &prepared_id_);
      break;
    case CQL_ERROR_ALREADY_EXISTS:
      pos = decode_string(pos, &keyspace_);
      pos = decode_string(pos, &table_);
      break;
  }
  return true;
}
Пример #29
0
Файл: queue.c Проект: Shmuma/z
int queue_decode_history (queue_history_entry_t* entry, char* buf, int size)
{
	int i;

	entry->items = NULL;
	entry->buf = buf;
	entry->buf_size = size;

	entry->count = *(int*)buf;
	size -= sizeof (entry->count);
	buf  += sizeof (entry->count);

	/* server */
	if ((buf = decode_string (buf, &size, &entry->server)) == NULL)
		return 0;
	/* key */
	if ((buf = decode_string (buf, &size, &entry->key)) == NULL)
		return 0;

	entry->items = (queue_history_item_t*)malloc (sizeof (queue_history_item_t) * entry->count);

	for (i = 0; i < entry->count; i++) {
		entry->items[i].ts = *(hfs_time_t*)buf;
		buf  += sizeof (hfs_time_t);
		size -= sizeof (hfs_time_t);

		if ((buf = decode_string (buf, &size, &entry->items[i].value)) == NULL)
			goto error;
		if ((buf = decode_string (buf, &size, &entry->items[i].lastlogsize)) == NULL)
			goto error;
		if ((buf = decode_string (buf, &size, &entry->items[i].timestamp)) == NULL)
			goto error;
		if ((buf = decode_string (buf, &size, &entry->items[i].source)) == NULL)
			goto error;
		if ((buf = decode_string (buf, &size, &entry->items[i].severity)) == NULL)
			goto error;
	}

	return 1;

 error:
	if (entry->items)
		free (entry->items);
	return 0;
}
Пример #30
0
bool SetInfoDataObject::SetData(const wxDataFormat& format, size_t len, const void *buf) {
	if (format.GetType() != wxDF_TEXT 
			&& format.GetType() != wxDF_FILENAME
//			&& format.GetType() != wxDF_OEMTEXT
			&& format.GetType() != wxDF_UNICODETEXT)
		return false;

	unsigned char *escaped = (unsigned char*)malloc(len + 1);
	memcpy(escaped, buf, len);
	escaped[len] = '\0';
	wxString url = decode_string(escaped);
	free(escaped);

	url.Trim(true);
	url.Trim(false);

	if (!decode_url(url, m_prefix, m_set, m_period, m_time, m_selected_draw))
		return false;

	return true;
}