Esempio n. 1
0
void reply_avframe(AVPacket *pkt, AVCodec *codec) {
  ei_x_buff x;
  ei_x_new_with_version(&x);
  struct video_frame r;

  r.content = codec->type == AVMEDIA_TYPE_VIDEO ? frame_content_video :
    codec->type == AVMEDIA_TYPE_AUDIO ? frame_content_audio : 0;

  r.dts = pkt->dts / 90.0;
  r.pts = pkt->pts / 90.0;
  r.stream_id = 0;
  r.codec = codec->id == AV_CODEC_ID_H264 ? frame_codec_h264 :
    codec->id == AV_CODEC_ID_AAC ? frame_codec_aac : 0;

  r.flavor = pkt->flags & CODEC_FLAG_GLOBAL_HEADER ? frame_flavor_config :
    pkt->flags & AV_PKT_FLAG_KEY ? frame_flavor_keyframe : 
    frame_flavor_frame;

  r.track_id = codec->type == AVMEDIA_TYPE_VIDEO ? 1 : 2;
  r.body.data = pkt->data;
  r.body.size = pkt->size;
  write_video_frame(&x, r);
  write_x(&x);
  ei_x_free(&x);
}
Esempio n. 2
0
static void send_atom(ErlDrvPort port, const char *str) {
  ei_x_buff x;
  ei_x_new_with_version(&x);
  ei_x_encode_atom(&x, str);
  driver_output(port, x.buff, x.index);
  ei_x_free(&x);
}
Esempio n. 3
0
int gn_start_cnode(char **argv) { 
  extern ei_cnode ec;
  char rem_node_name[MAXATOMLEN] = "";	/* other node name */
  ei_x_buff xbuf;
  erlang_pid *self = ei_self(&ec);

  strcat(rem_node_name,REMNODE);
  strcat(rem_node_name,"@");
  strcat(rem_node_name,REMHOST);
  rem_regname = g_strdup(REMREG);
  g_print("I am %s, you are %s (%d)\n", NODE_NAME, rem_node_name, ERL_DIST_VSN);

  ei_set_compat_rel(ERL_DIST_VSN); /* erlnode version of dist. protocol */

  if ( ei_connect_init(&ec, NODE_NAME, COOKIE, CREATION) < 0 )
    g_critical("ei_connect_init");

  if ( (fd = ei_connect(&ec, rem_node_name)) < 0 )
    g_critical("ei_connect failed.\nwrong cookie? erl-dist version mismatch?");
  
  self->num = fd;		/* bug?? in ei_reg_send_tmo */

  ei_x_new_with_version(&xbuf);
  gn_wrap_ans("handshake", &xbuf);
  ei_x_encode_empty_list(&xbuf);
  gn_send(&xbuf);
  ei_x_free(&xbuf);
  
  return fd;
} 
Esempio n. 4
0
/* 
 * Sends an Erlang message to a process at an Erlang node
 */
int erl_send(int fd, ETERM *to ,ETERM *msg)
{
    erlang_pid topid;
    ei_x_buff x;
    int r;

    ei_x_new_with_version(&x);
    ei_x_encode_term(&x, msg);
    /* make the to-pid */
    if (!ERL_IS_PID(to)) {
	ei_x_free(&x);
	erl_errno = EINVAL;
	return -1;
    }

    if (to->uval.pidval.node.latin1) {
	strcpy(topid.node, to->uval.pidval.node.latin1);
    }
    else {
	strcpy(topid.node, to->uval.pidval.node.utf8);
    }    
    topid.num = ERL_PID_NUMBER(to);
    topid.serial = ERL_PID_SERIAL(to);
    topid.creation = ERL_PID_CREATION(to);
    r = ei_send(fd, &topid, x.buff, x.index);
    ei_x_free(&x);
    return r == 0;
}
Esempio n. 5
0
  bool CCESUT::TradeOrder(PTradeOrderTxnInput pTxnInput,
                          INT32 iTradeType, bool bExecutorIsAccountOwner) {
    ei_x_buff x;

    ei_x_new_with_version(&x);
    ei_x_encode_tuple_header(&x, 2);
    {
      ei_x_encode_atom(&x, "ok");
      ei_x_encode_tuple_header(&x, 2);
      {
        ei_x_encode_atom(&x, APP ".BH.TO");
        ei_x_encode_tuple_header(&x, 3);
        {
          m_Encoder.encode(&x, "trade_type", iTradeType);
          m_Encoder.encode(&x, "executor_is_account_owner", bExecutorIsAccountOwner);
          m_Encoder.encode(&x, *pTxnInput);
        }
      }
    }

    int result = driver_output(m_ErlDrvPort, x.buff, x.index);

#ifdef _TRACE
    cout << "[TO] ! " << *pTxnInput << ", result=" << result << '\r' << endl;
#endif

    ei_x_free(&x);

    return result;
  }
Esempio n. 6
0
/* called from gtk main loop when there's data on the cnode socket */
gboolean gn_handle_read(GIOChannel *source,GIOCondition cond,gpointer data){
  erlang_msg msg;
  ei_x_buff xbuf;
  
  /*   fd = g_io_channel_unix_get_fd(source); */
  ei_x_new_with_version(&xbuf);
  switch ( ei_xreceive_msg(fd, &msg, &xbuf) ){
  case ERL_TICK:
    break;			/* ignore */
  case ERL_MSG:
    switch (msg.msgtype) {
    case ERL_SEND:
    case ERL_REG_SEND:
      reply(&msg, &xbuf);
      break;
    case ERL_LINK:
    case ERL_UNLINK:
    case ERL_GROUP_LEADER:
      break;			/* ignore */
    case ERL_EXIT:
    case ERL_EXIT2:
    case ERL_NODE_LINK:
      gtk_main_quit();		/* crash and burn */
      return FALSE;
    }
    break;
  case ERL_ERROR:
    gtk_main_quit();		/* crash and burn */
    return FALSE;
  }
  ei_x_free(&xbuf);
  return TRUE;
}
Esempio n. 7
0
  bool CCESUT::MarketWatch(PMarketWatchTxnInput pTxnInput) {

    ei_x_buff x;

    ei_x_new_with_version(&x);
    ei_x_encode_tuple_header(&x, 2);
    {
      ei_x_encode_atom(&x, "ok");
      ei_x_encode_tuple_header(&x, 2);
      {
        ei_x_encode_atom(&x, APP ".BH.MW");
        m_Encoder.encode(&x, *pTxnInput);
      }
    }

    int result = driver_output(m_ErlDrvPort, x.buff, x.index);

#ifdef _TRACE
    cout << "[MW] ! " << *pTxnInput << ", result=" << result << '\r' << endl;
#endif

    ei_x_free(&x);

    return result;
  }
Esempio n. 8
0
  bool CDMSUT::TradeCleanup(PTradeCleanupTxnInput pTxnInput) {

    ei_x_buff x;

    ei_x_new_with_version(&x);
    ei_x_encode_tuple_header(&x, 2);
    {
      ei_x_encode_atom(&x, "ok");
      ei_x_encode_tuple_header(&x, 2);
      {
        ei_x_encode_atom(&x, APP ".BH.TC");
        m_Encoder.encode(&x, *pTxnInput);
      }
    }

    int result = driver_output(m_ErlDrvPort, x.buff, x.index);

#ifdef _TRACE
    cout << "[TC] ! " << *pTxnInput << ", result=" << result << '\r' << endl;
#endif

    ei_x_free(&x);

    return result;
  }
Esempio n. 9
0
/*
* Now returns non-negative number for success, negative for failure.
*/
int ei_rpc_to(ei_cnode *ec, int fd, char *mod, char *fun,
	      const char *buf, int len)
{

    ei_x_buff x;
    erlang_pid *self = ei_self(ec);
    self->num = fd;

    /* encode header */
    ei_x_new_with_version(&x);
    ei_x_encode_tuple_header(&x, 2);  /* A */
    
    self->num = fd;
    ei_x_encode_pid(&x, self);	      /* A 1 */
    
    ei_x_encode_tuple_header(&x, 5);  /* B A 2 */
    ei_x_encode_atom(&x, "call");     /* B 1 */
    ei_x_encode_atom(&x, mod);	      /* B 2 */
    ei_x_encode_atom(&x, fun);	      /* B 3 */
    ei_x_append_buf(&x, buf, len);    /* B 4 */
    ei_x_encode_atom(&x, "user");     /* B 5 */

    /* ei_x_encode_atom(&x,"user"); */
    ei_send_reg_encoded(fd, self, "rex", x.buff, x.index);
    ei_x_free(&x);
	
    return 0;
} /* rpc_to */
Esempio n. 10
0
static int
current_tree_finished(struct exmpp_xml_ctx *ctx)
{
	ei_x_buff *trees;

	trees = ctx->complete_trees;
	if (trees == NULL) {
		/* Allocate the complete trees list. */
		trees = driver_alloc(sizeof(*trees));
		if (trees == NULL)
			return (-1);
		ei_x_new_with_version(trees);
		ctx->complete_trees = trees;
	}

	/* Append the current tree to the complete trees list. */
	ei_x_encode_list_header(trees, 1);
	ei_x_append(trees, ctx->current_tree);
	ctx->complete_trees_ready = 1;

	/* Reset the current tree. */
	reset_current_tree(ctx);

	return (0);
}
Esempio n. 11
0
    void
epcap_response(u_char *user, const struct pcap_pkthdr *hdr, const u_char *pkt)
{
    EPCAP_STATE *ep = (EPCAP_STATE *)user;
    ei_x_buff msg = {0};

    IS_FALSE(ei_x_new_with_version(&msg));

    /* {packet, DatalinkType, Time, ActualLength, Packet} */
    IS_FALSE(ei_x_encode_tuple_header(&msg, 5));
    IS_FALSE(ei_x_encode_atom(&msg, "packet"));

    /* DataLinkType */
    IS_FALSE(ei_x_encode_long(&msg, ep->datalink));

    /* {MegaSec, Sec, MicroSec} */
    IS_FALSE(ei_x_encode_tuple_header(&msg, 3));
    IS_FALSE(ei_x_encode_long(&msg, abs(hdr->ts.tv_sec / 1000000)));
    IS_FALSE(ei_x_encode_long(&msg, hdr->ts.tv_sec % 1000000));
    IS_FALSE(ei_x_encode_long(&msg, hdr->ts.tv_usec));

    /* ActualLength} */
    IS_FALSE(ei_x_encode_long(&msg, hdr->len));

    /* Packet */
    IS_FALSE(ei_x_encode_binary(&msg, pkt, hdr->caplen));

    /* } */

    epcap_send_free(&msg);
}
Esempio n. 12
0
void reply_atom(char *a) {
  ei_x_buff x;
  ei_x_new_with_version(&x);
  ei_x_encode_atom(&x, a);
  write_x(&x);
  ei_x_free(&x);
}
Esempio n. 13
0
static void cmd_ei_send_funs(char* buf, int len)
{
    int index = 0, n;
    long fd;
    erlang_pid pid;
    ei_x_buff x;
    erlang_fun fun1, fun2;

    if (ei_decode_long(buf, &index, &fd) < 0)
	fail("expected long");
    if (ei_decode_pid(buf, &index, &pid) < 0)
	fail("expected pid (node)");
    if (ei_decode_tuple_header(buf, &index, &n) < 0)
	fail("expected tuple");
    if (n != 2)
	fail("expected tuple");
    if (ei_decode_fun(buf, &index, &fun1) < 0)
	fail("expected Fun1");
    if (ei_decode_fun(buf, &index, &fun2) < 0)
	fail("expected Fun2");
    if (ei_x_new_with_version(&x) < 0)
	fail("ei_x_new_with_version");
    if (ei_x_encode_tuple_header(&x, 2) < 0)
	fail("encode tuple header");
    if (ei_x_encode_fun(&x, &fun1) < 0)
	fail("encode fun1");
    if (ei_x_encode_fun(&x, &fun2) < 0)
	fail("encode fun2");
    free_fun(&fun1);
    free_fun(&fun2);
    send_errno_result(ei_send(fd, &pid, x.buff, x.index));
    ei_x_free(&x);
}
Esempio n. 14
0
static DWORD WINAPI
#else
static void*
#endif
    einode_thread(void* num)
{
    int n = (int)num;
    ei_cnode ec;
    char myname[100], destname[100];
    int r, fd;

    sprintf(myname, "ei%d", n);
    sprintf(destname, "mth%d", n);
    printf("thread %d (%s %s) connecting\n", n, myname, destname);
    r = ei_connect_init(&ec, myname, cookie, 0);
    fd = ei_connect(&ec, (char*)desthost);
    if (r == 0 && fd >= 0) {
	ei_x_buff x;
	ei_x_new_with_version(&x);
	ei_x_encode_string(&x, myname);
	ei_reg_send(&ec, fd, destname, x.buff, x.index);
	ei_x_free(&x);
	//SleepEx(100);
	shutdown(fd, SD_SEND);
	closesocket(fd);
    } else {
	printf("coudn't connect fd %d r %d\n", fd, r); //	DebugBreak();
    }
    printf("done thread %d\n", n);
    return 0;
}
Esempio n. 15
0
void handle_winch(int sig){
  ei_x_buff eixb;
  ei_x_new_with_version(&eixb);
  tuple(&eixb, 2);
  atom(&eixb, "sigwinch", 8);
  atom(&eixb, "sigwinch", 8);
  driver_output(stpt->drv_port, eixb.buff, eixb.index);
}
Esempio n. 16
0
static void send_hash(ErlDrvPort port, unsigned long hash) {
  ei_x_buff x;
  ei_x_new_with_version(&x);
  ei_x_encode_ulong(&x, hash);
  driver_output(port, x.buff, x.index);
  // printf("sent hash %d\n", hash);
  ei_x_free(&x);
}
Esempio n. 17
0
static void do_getch(ErlDrvData drvstate, ErlDrvEvent event) {
  state *st = (state *)drvstate;
  ei_x_buff eixb;
  int keycode;
  ei_x_new_with_version(&eixb);
  keycode = getch();
  integer(&eixb, keycode);
  driver_output(st->drv_port, eixb.buff, eixb.index);
}
Esempio n. 18
0
static inline void init(State* p, int options) {
  p->li_stack = p->li_sp = 0;
  p->li_stack_size = 0;

  
  ei_x_new_with_version(&p->ei_buf);
  p->skip_list_header_for_value = -1;
  p->options = options;
}
Esempio n. 19
0
/*-----------------------------------------------------------------
 * MAIN
 *----------------------------------------------------------------*/
int main(int argc, char *argv[])
{
    byte*     buf;
    int       size = BUF_SIZE;

    if (argc > 1) {
	test(argc, argv);
	return 0;
    }

    fprintf(stderr, "gssapi started\r\n");

    if ((buf = malloc(size)) == NULL)
	return -1;
    
    while ( (buf = read_cmd(buf, &size)) ) {
	int res = 0;
	int index = 0;
	int version, arity;
	char command[MAXATOMLEN];
	ei_x_buff result;
	port_func func;

	/* Ensure that we are receiving the binary term by reading and 
	 * stripping the version byte */
	EI(ei_decode_version(buf, &index, &version));
    
	/* Our marshalling spec is that we are expecting a tuple {Command, Arg1} */
	EI(ei_decode_tuple_header(buf, &index, &arity));
    
	EI(arity != 2);
    
	EI(ei_decode_atom(buf, &index, command));

	/* Prepare the output buffer that will hold {ok, Result} or {error, Reason} */
	EI(ei_x_new_with_version(&result) || ei_x_encode_tuple_header(&result, 2));
    
/* 	fprintf(stderr, "command: %s\r\n", command); */
	func = lookup_func(command);

	if (func) {
	    res = func(buf, index, &result);
	} else {
	    EI(ei_x_encode_atom(&result, "error") || ei_x_encode_atom(&result, "unsupported_command"));
	}

	write_cmd(&result);

	ei_x_free(&result);
    }

/* error: */
    fprintf(stderr, "No more command, exiting\r\n");

    return 0;
}
Esempio n. 20
0
void Client::sendMessage(QByteArray procName, QVariant value)
{
    ei_x_buff x;
    ei_x_new_with_version(&x);

    encode(value, &x);
    ei_reg_send(m_ec, m_fd, procName.data(), x.buff, x.index);

    ei_x_free(&x);
}
Esempio n. 21
0
File: rec.c Progetto: oliv3/phaspa
static void
ok() {
    ei_x_buff result;

    check(ei_x_new_with_version(&result));
    check(ei_x_encode_atom(&result, "ok"));

    write_cmd(&result);
    ei_x_free(&result);
}
Esempio n. 22
0
static void send_errno_result(int value)
{
    ei_x_buff x;
    ei_x_new_with_version(&x);
    ei_x_encode_tuple_header(&x, 2);
    ei_x_encode_long(&x, value);
    ei_x_encode_long(&x, erl_errno);
    send_bin_term(&x);
    ei_x_free(&x);
}
Esempio n. 23
0
// =============================================================================
// Utility functions
// =============================================================================
void init_state(state *st, char *args, int argslen) {
  st->index = 0;
  st->version = 0;
  st->args = args;
  st->argslen = argslen;
  ei_decode_version(st->args, &(st->index), &(st->version));
  assert(st->version != 0);
  assert(st->index != 0);
  ei_x_new_with_version(&(st->eixb));
}
Esempio n. 24
0
static ei_x_buff make_error(const char* text){

	ei_x_buff x;
	ei_x_new_with_version(&x);
	ei_x_encode_tuple_header(&x,2);
	ei_x_encode_atom(&x,"error");
	ei_x_encode_string(&x,text);

	return x;
}
Esempio n. 25
0
File: epcap.c Progetto: kvakvs/epcap
void epcap_ctrl(const char *ctrl_evt)
{
    ei_x_buff msg;

    IS_FALSE(ei_x_new_with_version(&msg));
    IS_FALSE(ei_x_encode_tuple_header(&msg, 2));
    IS_FALSE(ei_x_encode_atom(&msg, "epcap"));
    IS_FALSE(ei_x_encode_atom(&msg, ctrl_evt));

    epcap_send_free(&msg);
}
Esempio n. 26
0
void Client::sendPid(QByteArray procName)
{
    ei_x_buff x;
    ei_x_new_with_version(&x);

    ei_x_encode_pid(&x, &(m_ec->self));

    ei_reg_send(m_ec, m_fd, procName.data(), x.buff, x.index);

    ei_x_free(&x);
}
Esempio n. 27
0
static void reply(erlang_msg *msg, ei_x_buff *recv_x_buf) {
  int i = 0;
  int version;
  ei_x_buff xbuf;
  
  ei_decode_version(recv_x_buf->buff, &i, &version);
  ei_x_new_with_version(&xbuf);
  make_reply_list(&xbuf, recv_x_buf->buff, &i);
  gn_send(&xbuf);
  ei_x_free(&xbuf);
}
Esempio n. 28
0
static void has(bloom_drv_t *driver, char *buf, int len) {
  int result;
  ei_x_buff x;
  result = bloom_has(driver->bloom, buf, len);
  
  ei_x_new_with_version(&x);
  ei_x_encode_boolean(&x, result);
  
  driver_output(driver->port, x.buff, x.index);
  ei_x_free(&x);
}
Esempio n. 29
0
static void key_size(bloom_drv_t *driver) {
  long result;
  ei_x_buff x;
  result = bloom_key_size(driver->bloom);
  
  ei_x_new_with_version(&x);
  ei_x_encode_long(&x, result);
  
  driver_output(driver->port, x.buff, x.index);
  ei_x_free(&x);
}
Esempio n. 30
-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);
}