Example #1
0
static int
encode_elem(struct exmpp_xml_ctx *ctx, ei_x_buff *tree,
    const char *elem, int elem_len)
{
	int ret;

	/* Check if the element is known and encode it. */
	if (elem_len <= MAXATOMLEN && ctx->names_as_atom) {
		if (is_known_elem(ctx, elem, elem_len))
			if (elem_len == -1)
				ret = ei_x_encode_atom(tree, elem);
			else
				ret = ei_x_encode_atom_len(tree,
				    elem, elem_len);
		else
			if (elem_len == -1)
				ret = ei_x_encode_string(tree, elem);
			else
				ret = ei_x_encode_string_len(tree,
				    elem, elem_len);
	} else {
		if (elem_len == -1)
			ret = ei_x_encode_string(tree, elem);
		else
			ret = ei_x_encode_string_len(tree, elem, elem_len);
	}

	return (ret);
}
Example #2
0
static int
encode_attr(struct exmpp_xml_ctx *ctx, ei_x_buff *tree,
    const char *attr, int attr_len)
{
	int ret;

	/* Check if the attribute is known and encode it. */
	if (attr_len <= MAXATOMLEN && ctx->names_as_atom) {
		if (is_known_attr(ctx, attr, attr_len))
			if (attr_len == -1)
				ret = ei_x_encode_atom(tree, attr);
			else
				ret = ei_x_encode_atom_len(tree,
				    attr, attr_len);
		else
			if (attr_len == -1)
				ret = ei_x_encode_string(tree, attr);
			else
				ret = ei_x_encode_string_len(tree,
				    attr, attr_len);
	} else {
		if (attr_len == -1)
			ret = ei_x_encode_string(tree, attr);
		else
			ret = ei_x_encode_string_len(tree, attr, attr_len);
	}

	return (ret);
}
Example #3
0
static int
encode_ns(struct exmpp_xml_ctx *ctx, ei_x_buff *tree,
    const char *ns, int ns_len)
{
	int ret;

	if (ns != NULL) {
		/* Check if the namespace is known and encode it. */
		if (ns_len <= MAXATOMLEN && ctx->names_as_atom) {
			if (is_known_ns(ctx, ns, ns_len))
				if (ns_len == -1)
					ret = ei_x_encode_atom(tree, ns);
				else
					ret = ei_x_encode_atom_len(tree,
					    ns, ns_len);
			else
				if (ns_len == -1)
					ret = ei_x_encode_string(tree, ns);
				else
					ret = ei_x_encode_string_len(tree,
					    ns, ns_len);
		} else {
			if (ns_len == -1)
				ret = ei_x_encode_string(tree, ns);
			else
				ret = ei_x_encode_string_len(tree,
				    ns, ns_len);
		}
	} else {
		/* The namespace is "empty". The element may have none. */
		ret = ei_x_encode_atom(tree, "undefined");
	}

	return (ret);
}
Example #4
0
int ei_x_encode_error_tuple_string_len(ei_x_buff *buff, char *str, int strlen) {
    EI(ei_x_encode_version(buff));
    EI(ei_x_encode_tuple_header(buff, 2));
    EI(ei_x_encode_atom(buff, "error"));
    EI(ei_x_encode_string_len(buff, str, strlen));
    return 0;
}
Example #5
0
void encode_name(const XML_Char *name)
{
  char *name_start;
  char *prefix_start;
  char *buf;
  int name_len, prefix_len, buf_len;

  if ((name_start = strchr(name, '\n'))) {
    if ((prefix_start = strchr(name_start+1, '\n'))) {
      name_len = prefix_start - name_start;
      prefix_len = strlen(prefix_start+1);
      buf_len = prefix_len + name_len;
      buf = driver_alloc(buf_len);
      memcpy(buf, prefix_start+1, prefix_len);
      memcpy(buf+prefix_len, name_start, name_len);
      buf[prefix_len] = ':';
      ei_x_encode_string_len(&event_buf, buf, buf_len);
      driver_free(buf);
    } else {
      ei_x_encode_string(&event_buf, name_start+1);
    };
  } else {
    ei_x_encode_string(&event_buf, name);
  }
}
Example #6
0
File: q2e.c Project: csurface/gen_q
int ei_x_encode_kstring(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {
    EI(ei_x_encode_atom(types, "string"));
    if(r->n == 0) {
        EI(ei_x_encode_empty_list(values));
    } else {
        EI(ei_x_encode_string_len(values, (const char*)kC(r), r->n));
    }
    return 0;
}
Example #7
0
File: q2e.c Project: csurface/gen_q
int ei_x_encode_same_list_byte(ei_x_buff* types, ei_x_buff* values, const char* t, K r, QOpts* opts) {
    EI(ei_x_encode_tuple_header(types, 2));
    EI(ei_x_encode_atom(types, "list"));
    EI(ei_x_encode_atom(types, t));
    if(r->n == 0) {
        EI(ei_x_encode_empty_list(values));
    } else {
        EI(ei_x_encode_string_len(values, (const char*)kG(r), r->n));
    }
    return 0;
}
Example #8
0
static int erl_json_ei_number(void* ctx, const char * val, unsigned int len) {
  State* pState = (State*) ctx;

  flog(stderr, "number", 0, val, len);

  list_header_for_value(pState);

  switch(numbers_as(pState)) {
    case EEP0018_PARSE_NUMBERS_AS_NUMBER:
    {
      if(memchr(val, '.', len) || memchr(val, 'e', len) || memchr(val, 'E', len))
        ei_x_encode_double(&pState->ei_buf, strtod(val, 0));
      else
        ei_x_encode_long(&pState->ei_buf, strtol(val, 0, 10));
      break;
    }
    case EEP0018_PARSE_NUMBERS_AS_FLOAT:
    {
      ei_x_encode_double(&pState->ei_buf, strtod(val, 0));
      break;
    }
    case EEP0018_PARSE_NUMBERS_AS_TUPLE:
    {
      /* 
        While "1e1" is a valid JSON number, it is not a valid parameter to list_to_float/1 
        We fix that by inserting ".0" before the exponent e. 
      */
      const char* exp = memchr(val, 'e', len);
      if(exp && exp > val) {
        const char* dot = memchr(val, '.', exp - val);
        if(!dot) {
          char* tmp = alloca(len + 5);
          memcpy(tmp, val, exp - val);
          memcpy(tmp + (exp - val), ".0", 2);
          memcpy(tmp + (exp - val) + 2, exp, len - (exp - val));
          len += 2;
          val = tmp;
          tmp[len] = 0;
        }
      }

      ei_x_encode_tuple_header(&pState->ei_buf, 3);
      ei_x_encode_atom_len(&pState->ei_buf, "number", 6);
      ei_x_encode_string_len(&pState->ei_buf, val, len);
      ei_x_encode_atom_len(&pState->ei_buf, "a", 1);      // a dummy
      break;
    }
  }

  
  return 1;
}
static ei_x_buff pack_parse_data(parse_result parse_result_){

	ei_x_buff x;
	ei_x_new_with_version(&x);
	ei_x_encode_tuple_header(&x,2);
	//{caly_tekst,[link]} kodujemy caly tekst
	ei_x_encode_string(&x, parse_result_.second.c_str());
	int link_list_length = parse_result_.first.size();
	ei_x_encode_list_header(&x,link_list_length);
	vector<std::string>& links = parse_result_.first;
	for (vector<std::string>::iterator it = links.begin(); it != links.end(); it++){
		ei_x_encode_string_len(&x,(*it).c_str(),(*it).size());
	}
	ei_x_encode_empty_list(&x);

	return x;
}
Example #10
0
/* "string" */
static int pstring(const char** fmt, ei_x_buff* x)
{
    const char* start = ++(*fmt); /* skip first quote */
    char c;
    int res;
    
    for (;;) {
	c = *(*fmt)++;
	if (c == '\0')
	    return -1;
	if (c == '"') {
	    if (*((*fmt)-1) == '\\')
		continue;
	    else
		break;
	} else
	    continue;
    }
    res = ei_x_encode_string_len(x, start, *fmt - start - 1);
    return res;
}
Example #11
0
File: q2e.c Project: csurface/gen_q
int ei_x_encode_general_list(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {
    LOG("ei_x_encode_general_list length "FMT_KN"\n", r->n);

    EI(ei_x_encode_tuple_header(types, 2));
    EI(ei_x_encode_atom(types, "list"));

    if(r->n > 0) {
        int all_strings = 1;
        EI(ei_x_encode_list_header(values, r->n));
        int i;
        for(i=0; i<r->n; ++i) {
            K elem = kK(r)[i];
            if(elem->t != KC) {
                all_strings = 0;
                break;
            }
            EI(ei_x_encode_string_len(values, (const char*)kC(elem), elem->n));
        }

        if(all_strings) {
            EI(ei_x_encode_atom(types, "string"));
        } else {
            EI(ei_x_encode_list_header(types, r->n));
            int j;
            for(j=0; j<i; ++j) {
                EI(ei_x_encode_atom(types, "string"));
            }

            for(; i<r->n; ++i) {
                EI(ei_x_encode_k_tv(types, values, kK(r)[i], opts));
            }
            EI(ei_x_encode_empty_list(types));
        }
    } else {
        EI(ei_x_encode_empty_list(types));
    }
    EI(ei_x_encode_empty_list(values));
    return 0;
}
Example #12
0
int
make_attribute_legacy(struct exmpp_xml_ctx *ctx,
    const char *attr, int attr_len,
    const char *value, int value_len)
{
	ei_x_buff *tree;

	tree = ctx->current_tree;

	/* Start a simple tuple. */
	ei_x_encode_list_header(tree, 1);
	ei_x_encode_tuple_header(tree, 2);

	/* Check if the attribute is known and encode it. */
	encode_attr(ctx, tree, attr, attr_len);

	/* Encode the value. */
	if (value_len == -1)
		ei_x_encode_string(tree, value);
	else
		ei_x_encode_string_len(tree, value, value_len);

	return (0);
}
Example #13
0
int
make_declared_ns_in_buf(struct exmpp_xml_ctx *ctx, ei_x_buff *buf,
    const char *ns, int ns_len,
    const char *prefix, int prefix_len)
{

	/* Start declared namespace entry. */
	ei_x_encode_list_header(buf, 1);
	ei_x_encode_tuple_header(buf, 2);

	/* Check if the namespace is known and encode it. */
	encode_ns(ctx, buf, ns, ns_len);

	/* Encode prefix. */
	if (prefix != NULL)
		if (prefix_len == -1)
			ei_x_encode_string(buf, prefix);
		else
			ei_x_encode_string_len(buf, prefix, prefix_len);
	else
		ei_x_encode_atom(buf, "none");

	return (0);
}
Example #14
0
void uwsgi_erlang_rpc(int fd, erlang_pid *from, ei_x_buff *x) {

	int etype, esize;
	int arity;

	char *gen_call;
	char *module;
	char *call;
	char buffer[0xffff];

	char *argv[256] ;
	uint16_t argvs[256] ;
	int argc = 0;
	uint16_t ret;
	ei_x_buff xr;

	erlang_ref eref;

	ei_get_type(x->buff, &x->index, &etype, &esize);

#ifdef UWSGI_DEBUG
	uwsgi_log("%d %c %c %c\n", etype, etype, ERL_SMALL_TUPLE_EXT, ERL_LARGE_TUPLE_EXT);
#endif
	if (etype != ERL_SMALL_TUPLE_EXT && etype != ERL_LARGE_TUPLE_EXT) return;

	ei_decode_tuple_header(x->buff, &x->index, &arity);

#ifdef UWSGI_DEBUG
	uwsgi_log("rpc arity %d\n", arity);
#endif
	if (arity != 3) return ;

	ei_get_type(x->buff, &x->index, &etype, &esize);

	if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;

	gen_call = uwsgi_malloc(esize);

	if (etype == ERL_ATOM_EXT) {
                ei_decode_atom(x->buff, &x->index, gen_call);
        }
        else {
                ei_decode_string(x->buff, &x->index, gen_call);
        }

#ifdef UWSGI_DEBUG
	uwsgi_log("gen call = %s\n", gen_call);
#endif

	ei_get_type(x->buff, &x->index, &etype, &esize);
	
	if (etype != ERL_SMALL_TUPLE_EXT) return ;

	ei_decode_tuple_header(x->buff, &x->index, &arity);
	if (arity != 2) return ;

	ei_get_type(x->buff, &x->index, &etype, &esize);
	ei_skip_term(x->buff, &x->index);
	ei_get_type(x->buff, &x->index, &etype, &esize);
	ei_decode_ref(x->buff, &x->index, &eref);

	ei_get_type(x->buff, &x->index, &etype, &esize);

	module = uwsgi_malloc(esize);

	if (etype == ERL_ATOM_EXT) {
		ei_decode_atom(x->buff, &x->index, module);
	}
	else {
		ei_decode_string(x->buff, &x->index, module);
	}

	ei_get_type(x->buff, &x->index, &etype, &esize);

	if (etype != ERL_SMALL_TUPLE_EXT) return ;

	ei_decode_tuple_header(x->buff, &x->index, &arity);

#ifdef UWSGI_DEBUG
	uwsgi_log("arity: %d\n", arity);
#endif
	if (arity != 5) return ;

	ei_get_type(x->buff, &x->index, &etype, &esize);

        char *method = uwsgi_malloc(esize);

        if (etype == ERL_ATOM_EXT) {
                ei_decode_atom(x->buff, &x->index, method);
        }
        else {
                ei_decode_string(x->buff, &x->index, method);
        }

        if (strcmp(method, "call")) return;

        ei_get_type(x->buff, &x->index, &etype, &esize);

	if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;

	module = uwsgi_malloc(esize);

	if (etype == ERL_ATOM_EXT) {
		ei_decode_atom(x->buff, &x->index, module);
	}
	else {
		ei_decode_string(x->buff, &x->index, module);
	}

	ei_get_type(x->buff, &x->index, &etype, &esize);

	if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;

	call = uwsgi_malloc(esize);

	if (etype == ERL_ATOM_EXT) {
		ei_decode_atom(x->buff, &x->index, call);
	}
	else {
		ei_decode_string(x->buff, &x->index, call);
	}

#ifdef UWSGI_DEBUG
	uwsgi_log("RPC %s %s\n", module, call);
#endif

	ei_get_type(x->buff, &x->index, &etype, &esize);

	if (etype == ERL_ATOM_EXT) {
		argc = 1;
		argv[0] = uwsgi_malloc(esize+1);
		ei_decode_atom(x->buff, &x->index, argv[0]);	
		argvs[1] = esize;
	}
	else if (etype == ERL_STRING_EXT) {
		argc = 1;
		argv[0] = uwsgi_malloc(esize+1);
		ei_decode_string(x->buff, &x->index, argv[0]);	
		argvs[1] = esize;
	}

	ret = uwsgi_rpc(call, argc, argv, argvs, buffer);

#ifdef UWSGI_DEBUG
	uwsgi_log("buffer: %.*s\n", ret, buffer);
#endif

	ei_x_new_with_version(&xr);

	ei_x_encode_tuple_header(&xr, 2);
	//ei_x_encode_atom(&xr, "rex");
	ei_x_encode_ref(&xr, &eref);
	ei_x_encode_string_len(&xr, buffer, ret);

	uwsgi_log("ei_send to %d %s %d %d %d: %d %d\n", fd, from->node, from->num , from->serial, from->creation, xr.index, ei_send(fd, from, xr.buff, xr.index));
	//uwsgi_log("ei_send to %d %s %d %d %d: %d %d\n", fd, from->node, from->num , from->serial, from->creation, xr.index, ei_reg_send(&uerl.cnode, fd, "rex", xr.buff, xr.index));
	
	
}
Example #15
0
int ei_x_encode_string(ei_x_buff* x, const char* s)
{
    return ei_x_encode_string_len(x, s, strlen(s));
}
Example #16
0
static inline void write_string(State *p, const char* s, unsigned len)
  { ei_x_encode_string_len(&p->ei_buf, s, len); }
Example #17
0
static int accept_sec_context(char *buf, int index, ei_x_buff *presult)
{
    ei_x_buff result = *presult;

    /*
      {accept_sec_context, {Idx, In}} ->
      {ok, {Idx, Name, CCName, Out}} |
      {needsmore, {Idx, Out}}
    */

    int arity;
    gss_buffer_desc in;
    gss_buffer_desc out;
    gss_buffer_desc name;
    int res;
    char *ccname = NULL;
    long idx;
    OM_uint32 min_stat;

    memset(&in, 0, sizeof(in));
    memset(&out, 0, sizeof(out));
    memset(&name, 0, sizeof(name));

    EI(ei_decode_tuple_header(buf, &index, &arity));
    
    EI(arity != 2);

    EI(ei_decode_long(buf, &index, &idx));

    EI(decode_gssapi_binary(buf, &index, &in));

    if (idx < 0) {
	idx = session_find_free();
	if (idx < 0) ENCODE_ERROR("no_mem");
	g_sessions[idx] = GSS_C_NO_CONTEXT;
    } else {
	if (idx < 0 || idx >= MAX_SESSIONS || !g_sessions[idx])
	    ENCODE_ERROR("bad_instance");
    }

    res = accept_user(&g_sessions[idx], &in, &out, &name, &ccname);

    if (!GSS_ERROR(res)) {
	if (res & GSS_S_CONTINUE_NEEDED) {
	    EI(ei_x_encode_atom(&result, "needsmore") ||
	       ei_x_encode_tuple_header(&result, 2) ||
	       ei_x_encode_long(&result, idx) ||
	       ei_x_encode_binary(&result, out.value, out.length)
		);
	} else {
	    const char *ret_ccname = ccname;
	    if (!ret_ccname)
		ret_ccname = "";

	    EI(ei_x_encode_atom(&result, "ok") ||
	       ei_x_encode_tuple_header(&result, 4) ||
	       ei_x_encode_long(&result, idx) ||
	       ei_x_encode_string_len(&result, name.value, name.length) ||
	       ei_x_encode_string(&result, ret_ccname) ||
	       ei_x_encode_binary(&result, out.value, out.length)
		);

	}
    } else {
	EI(ei_x_encode_atom(&result, "error") || ei_x_encode_atom(&result, "unauthorized"));
    }

error:
    if (ccname)
	free(ccname);

    if (in.value)
	gss_release_buffer(&min_stat, &in);

    if (out.value)
	gss_release_buffer(&min_stat, &out);

    if (name.value)
	gss_release_buffer(&min_stat, &name);

    *presult = result;
    return 0;
}
Example #18
0
int main(void)
#endif
{
  ErlConnect conp;
  Erl_IpAddr thisipaddr = (Erl_IpAddr)0;
  FILE *fp = (FILE *)0;
  char* charp = "foo";
  double *doublep = NULL;
  double doublex = 0.0;
  ei_cnode xec;
  ei_reg *ei_regp = NULL;
  ei_term eterm;
  ei_x_buff eix;
  erlang_big *bigp = NULL;
  erlang_fun efun;
  erlang_msg *msgp = NULL;
  erlang_msg emsg;
  erlang_pid *pidp = NULL;
  erlang_pid epid;
  erlang_port eport;
  erlang_ref eref;
  erlang_trace etrace;
  int *intp = NULL;
  int intx = 0;
  long *longp = NULL;
  long longx = 0;
  short creation = 0;
  struct ei_reg_stat *ei_reg_statp = NULL;
  struct ei_reg_tabstat *ei_reg_tabstatp = NULL;
  struct hostent *hostp = NULL;
  unsigned char * ucharp = (unsigned char *)"foo";
  unsigned long *ulongp = NULL;
  unsigned long ulongx = 0;
  void *voidp = NULL;
#ifndef VXWORKS
  EI_LONGLONG *longlongp = (EI_LONGLONG*)NULL;
  EI_LONGLONG longlongx = 0;
  EI_ULONGLONG *ulonglongp = (EI_ULONGLONG*)NULL;
  EI_ULONGLONG ulonglongx = 0;
#endif
  enum erlang_char_encoding enc;

  intx = erl_errno;

  ei_connect_init(&xec, charp, charp, creation);
  ei_connect_xinit (&xec, charp, charp, charp, thisipaddr, charp, creation);

  ei_connect(&xec, charp);
  ei_xconnect (&xec, thisipaddr, charp);

  ei_receive(intx, ucharp, intx);
  ei_receive_msg(intx, &emsg, &eix);
  ei_xreceive_msg(intx, &emsg, &eix);

  ei_send(intx, &epid, charp, intx);
  ei_reg_send(&xec, intx, charp, charp, intx);

  ei_rpc(&xec, intx, charp, charp, charp, intx, &eix);
  ei_rpc_to(&xec, intx, charp, charp, charp, intx);
  ei_rpc_from(&xec, intx, intx, &emsg, &eix);

  ei_publish(&xec, intx);
  ei_accept(&xec, intx, &conp);
  ei_unpublish(&xec);

  ei_thisnodename(&xec);
  ei_thishostname(&xec);
  ei_thisalivename(&xec);

  ei_self(&xec);

  ei_gethostbyname(charp);
  ei_gethostbyaddr(charp, intx, intx);
  ei_gethostbyname_r(charp, hostp, charp, intx, intp);
  ei_gethostbyaddr_r(charp, intx, intx, hostp, charp, intx, intp);

  ei_encode_version(charp, intp);
  ei_x_encode_version(&eix);
  ei_encode_long(charp, intp, longx);
  ei_x_encode_long(&eix, longx);
  ei_encode_ulong(charp, intp, ulongx);
  ei_x_encode_ulong(&eix, ulongx);
  ei_encode_double(charp, intp, doublex);
  ei_x_encode_double(&eix, doublex);
  ei_encode_boolean(charp, intp, intx);
  ei_x_encode_boolean(&eix, intx);
  ei_encode_char(charp, intp, 'a');
  ei_x_encode_char(&eix, 'a');
  ei_encode_string(charp, intp, charp);
  ei_encode_string_len(charp, intp, charp, intx);
  ei_x_encode_string(&eix, charp);
  ei_x_encode_string_len(&eix, charp, intx);
  ei_encode_atom(charp, intp, charp);
  ei_encode_atom_as(charp, intp, charp, ERLANG_LATIN1, ERLANG_UTF8);
  ei_encode_atom_len(charp, intp, charp, intx);
  ei_encode_atom_len_as(charp, intp, charp, intx, ERLANG_ASCII, ERLANG_LATIN1);
  ei_x_encode_atom(&eix, charp);
  ei_x_encode_atom_as(&eix, charp, ERLANG_LATIN1, ERLANG_UTF8);
  ei_x_encode_atom_len(&eix, charp, intx);
  ei_x_encode_atom_len_as(&eix, charp, intx, ERLANG_LATIN1, ERLANG_UTF8);
  ei_encode_binary(charp, intp, (void *)0, longx);
  ei_x_encode_binary(&eix, (void*)0, intx);
  ei_encode_pid(charp, intp, &epid);
  ei_x_encode_pid(&eix, &epid);
  ei_encode_fun(charp, intp, &efun);
  ei_x_encode_fun(&eix, &efun);
  ei_encode_port(charp, intp, &eport);
  ei_x_encode_port(&eix, &eport);
  ei_encode_ref(charp, intp, &eref);
  ei_x_encode_ref(&eix, &eref);
  ei_encode_trace(charp, intp, &etrace);
  ei_x_encode_trace(&eix, &etrace);
  ei_encode_tuple_header(charp, intp, intx);
  ei_x_encode_tuple_header(&eix, longx);
  ei_encode_list_header(charp, intp, intx);
  ei_x_encode_list_header(&eix, longx);
/* #define ei_encode_empty_list(buf,i) ei_encode_list_header(buf,i,0) */
  ei_x_encode_empty_list(&eix);

  ei_get_type(charp, intp, intp, intp);
  ei_get_type_internal(charp, intp, intp, intp);

  ei_decode_version(charp, intp, intp);
  ei_decode_long(charp, intp, longp);
  ei_decode_ulong(charp, intp, ulongp);
  ei_decode_double(charp, intp, doublep);
  ei_decode_boolean(charp, intp, intp);
  ei_decode_char(charp, intp, charp);
  ei_decode_string(charp, intp, charp);
  ei_decode_atom(charp, intp, charp);
  ei_decode_atom_as(charp, intp, charp, MAXATOMLEN_UTF8, ERLANG_WHATEVER, &enc, &enc);
  ei_decode_binary(charp, intp, (void *)0, longp);
  ei_decode_fun(charp, intp, &efun);
  free_fun(&efun);
  ei_decode_pid(charp, intp, &epid);
  ei_decode_port(charp, intp, &eport);
  ei_decode_ref(charp, intp, &eref);
  ei_decode_trace(charp, intp, &etrace);
  ei_decode_tuple_header(charp, intp, intp);
  ei_decode_list_header(charp, intp, intp);

  ei_decode_ei_term(charp, intp, &eterm);

  ei_print_term(fp, charp, intp);
  ei_s_print_term(&charp, charp, intp);

  ei_x_format(&eix, charp);
  ei_x_format_wo_ver(&eix, charp);

  ei_x_new(&eix);
  ei_x_new_with_version(&eix);
  ei_x_free(&eix);
  ei_x_append(&eix, &eix);
  ei_x_append_buf(&eix, charp, intx);
  ei_skip_term(charp, intp);

  ei_reg_open(intx);
  ei_reg_resize(ei_regp, intx);
  ei_reg_close(ei_regp);

  ei_reg_setival(ei_regp, charp, longx);
  ei_reg_setfval(ei_regp, charp, doublex);
  ei_reg_setsval(ei_regp, charp, charp);
  ei_reg_setpval(ei_regp, charp, voidp, intx);

  ei_reg_setval(ei_regp, charp, intx);

  ei_reg_getival(ei_regp, charp);
  ei_reg_getfval(ei_regp, charp);
  ei_reg_getsval(ei_regp, charp);
  ei_reg_getpval(ei_regp, charp, intp);

  ei_reg_getval(ei_regp, charp, intx);

  ei_reg_markdirty(ei_regp, charp);

  ei_reg_delete(ei_regp, charp);

  ei_reg_stat(ei_regp, charp, ei_reg_statp);

  ei_reg_tabstat(ei_regp, ei_reg_tabstatp);

  ei_reg_dump(intx, ei_regp, charp, intx);
  ei_reg_restore(intx, ei_regp, charp);
  ei_reg_purge(ei_regp);

#if defined(HAVE_GMP_H) && defined(HAVE_LIBGMP)
  {
      mpz_t obj;
      ei_decode_bignum(charp, intp, obj);
      ei_encode_bignum(charp, intp, obj);
      ei_x_encode_bignum(&eix, obj);
  }
#endif /* HAVE_GMP_H && HAVE_LIBGMP */

#ifndef VXWORKS

  ei_decode_longlong(charp, intp, longlongp);
  ei_decode_ulonglong(charp, intp, ulonglongp);
  ei_encode_longlong(charp, intp, longlongx);
  ei_encode_ulonglong(charp, intp, ulonglongx);
  ei_x_encode_longlong(&eix, longlongx);
  ei_x_encode_ulonglong(&eix, ulonglongx);

#endif

#ifdef USE_EI_UNDOCUMENTED

  ei_decode_intlist(charp, intp, longp, intp);

  ei_receive_encoded(intx, &charp, intp, msgp, intp);
  ei_send_encoded(intx, pidp, charp, intx);
  ei_send_reg_encoded(intx, pidp, charp, charp, intx);

  ei_decode_big(charp, intp, bigp);
  ei_big_comp(bigp, bigp);
  ei_big_to_double(bigp, doublep);
  ei_small_to_big(intx, bigp);
  ei_alloc_big(intx);
  ei_free_big(bigp);

#endif /* USE_EI_UNDOCUMENTED */

  return
      BUFSIZ +
      EAGAIN +
      EHOSTUNREACH +
      EIO +
      EI_BIN +
      EI_DELET +
      EI_DIRTY +
      EI_FLT +
      EI_FORCE +
      EI_INT +
      EI_NOPURGE +
      EI_STR +
      EMSGSIZE +
      ENOMEM +
      ERL_ERROR +
      ERL_EXIT +
      ERL_LINK +
      ERL_MSG +
      ERL_NO_TIMEOUT +
      ERL_REG_SEND +
      ERL_SEND +
      ERL_TICK +
      ERL_TIMEOUT +
      ERL_UNLINK +
      ETIMEDOUT +
      MAXATOMLEN;
}
int srdb1_encode_kv(int tupsize,const db_key_t* _k, const db_op_t* _op, const db_val_t* _v,
				const int _n, ei_x_buff *argbuf) {
	int i;
	struct tm* tt;
	time_t t_t;

	if(_k) {
	    ei_x_encode_list_header(argbuf, _n);
	    for(i = 0; i < _n; i++) {
		db_val_t *vv;
		ei_x_encode_tuple_header(argbuf, tupsize);
		ei_x_encode_atom_len(argbuf,_k[i]->s,_k[i]->len);
		if(tupsize == 3 ) {
		    if (_op) {
			ei_x_encode_atom(argbuf,_op[i]);
		    } else {
			ei_x_encode_atom(argbuf,"=");
		    }
		}
		vv=&(_v[i]);
		if (VAL_NULL(vv)) {
		    ei_x_encode_atom(argbuf,"undefined");
		} else {
		    switch(VAL_TYPE(vv)) {
			case DB1_INT:
			    ei_x_encode_ulong(argbuf, VAL_INT(vv));
			    break;
			case DB1_BIGINT:
			    ei_x_encode_longlong(argbuf, VAL_BIGINT(vv));
			    break;
			case DB1_DOUBLE:
			    ei_x_encode_double(argbuf, VAL_DOUBLE(vv));
			    break;
			case DB1_STRING:
			    ei_x_encode_string(argbuf,VAL_STRING(vv));
			    break;
			case DB1_STR:
			    ei_x_encode_string_len(argbuf,VAL_STR(vv).s,VAL_STR(vv).len);
			    break;
			case DB1_DATETIME:
			    t_t=VAL_TIME(vv);
			    tt= localtime(&t_t);
			    ei_x_encode_tuple_header(argbuf, 2);
			    ei_x_encode_tuple_header(argbuf, 3);
			    ei_x_encode_long(argbuf, tt->tm_year + 1900);
			    ei_x_encode_long(argbuf, tt->tm_mon +1);
			    ei_x_encode_long(argbuf, tt->tm_mday);
			    ei_x_encode_tuple_header(argbuf, 3);
			    ei_x_encode_long(argbuf, tt->tm_hour);
			    ei_x_encode_long(argbuf, tt->tm_min);
			    ei_x_encode_long(argbuf, tt->tm_sec);
			    break;
			case DB1_BLOB:
			    ei_x_encode_binary(argbuf,VAL_BLOB(vv).s,VAL_BLOB(vv).len);
			    break;
			case DB1_BITMAP:
			    ei_x_encode_ulong(argbuf,VAL_BITMAP(vv));
			    break;
		    }
		}
	    }
	    ei_x_encode_empty_list(argbuf);
	} else {
	    ei_x_encode_list_header(argbuf, 0);
	}
	return 0;
}
Example #20
-4
void json_parse_to_ei(ErlDrvData session, const unsigned char* s, int len, int opts) {
  int parseValue = opts & EEP0018_PARSE_VALUE;
  
  unsigned char* yajl_msg = 0;
  unsigned char* msg = 0;
  ErlDrvPort port = (ErlDrvPort) session;

  /*
   * initialize yajl parser
   */
  State state;
  init(&state, opts);
  
  yajl_parser_config conf = { YAJL_ALLOW_COMMENTS }; // , YAJL_CHECK_UTF8 };
  yajl_handle handle = yajl_alloc(&callbacks, &conf, &state);

  /* start parser */
  yajl_status stat;
  if(parseValue) stat = yajl_parse(handle, (const unsigned char*) "[ ", 2);
  stat = yajl_parse(handle, s, len);
  if(parseValue) stat = yajl_parse(handle, (const unsigned char*) " ]", 2);

  /*
   * sometimes the parser is still stuck inside a JSON token. This finishs
   * the token no matter what.
   */
  if(stat == yajl_status_insufficient_data)
    stat = yajl_parse(handle, (const unsigned char*) " ", 1);

  /* 
   * get an error message on errors
   */
  switch(stat) {
    case yajl_status_ok: break;
    case yajl_status_insufficient_data: 
      msg = (unsigned char*)"Insufficient data"; 
      break;
    default:
      msg = yajl_msg = yajl_get_error(handle, 0, s, len);
      break;
  }

  /* 
   * if result is not ok: we write {error, "reason"} instead. This is 
   * something that will never be encoded from any JSON data.
   */
  if(msg) {
    ei_x_free(&state.ei_buf);
    ei_x_new_with_version(&state.ei_buf);

    ei_x_encode_tuple_header(&state.ei_buf, 2);
    ei_x_encode_atom_len(&state.ei_buf, "error", 5);
    ei_x_encode_string_len(&state.ei_buf, (const char*) msg, strlen((const char*) msg));

    if(yajl_msg) yajl_free_error(yajl_msg);
  } 

  send_data(port, EEP0018_EI, state.ei_buf.buff, state.ei_buf.index);
  deinit(&state);
}