Example #1
0
END_TEST

START_TEST(test_ws_success_2)
{
	__waiting_error = WS_CLOSING_FRAME;

    parse_message(__parser_info, __buf, MESSAGE);
    parse_message(__parser_info, __buf, MESSAGE);
    parse_message(__parser_info, __buf, MESSAGE);

    __waiting_call_count = 3;
    __waiting_call_info =  ERROR_CALL | MESSAGE_CALL;
}
void parse_message(const TextObjectMsg& msg,
                   std::shared_ptr<FrameObject>* fo) {
  CHECK_NOTNULL(fo);

  TextObject* text = new TextObject;
  text->type = FrameObject::Type::Text;

  ReadPoseSE3(msg.t_po(), &text->t_po);
  parse_message(msg.scale(), &text->scale);
  parse_message(msg.color(), &text->color);
  text->text = msg.text();
  fo->reset(text);
}
Example #3
0
int udp_listen(int portno)
{
	   int sockfd, newsockfd, clilen;
     gchar buffer[256];
     struct sockaddr_in serv_addr;
		 int n;
     sockfd = socket(AF_INET, SOCK_DGRAM, 0);
     if (sockfd < 0) 
        error("ERROR opening socket");
     bzero((gchar *) &serv_addr, sizeof(serv_addr));
     serv_addr.sin_family = AF_INET;
     serv_addr.sin_addr.s_addr = INADDR_ANY;
     serv_addr.sin_port = htons(portno);
     if (bind(sockfd, (struct sockaddr *) &serv_addr,
              sizeof(serv_addr)) < 0) 
              error("ERROR on binding");
     listen(sockfd,5);
     while (1) {
     		bzero(buffer,256);
     		n = recv(sockfd, buffer, 255, 0);
     		if (n < 0) error("ERROR reading from socket");
     		if (!parse_message(buffer)) break;
     }
     return 0; 
}
Example #4
0
bool		split_buffer(t_all *all, t_client *client)
{
  t_parser	parser;

  printf("Analyse : %s\n", all->buf.buf);
  parser.line = NULL;
  parser.pos = 0;
  if (parse_message(&parser, &(all->buf.buf[all->buf.init_idx])) == true)
    {
      if (DEBUG == true)
	{
	  printf("\nresultat :\n");
	  if (parser.prefix != NULL)
	    printf("préfixe :%s\n", parser.prefix);
	  if (parser.command != NULL)
	    printf("command :%s\n", parser.command);
	  if (parser.params != NULL)
	    printf("param :%s\n", parser.params);
	}
      treatment(&parser, all, client);
    }
  else
    {
      write_msg(&parser, all, client);
      printf("failed\n");
    }
  return (true);
}
Example #5
0
//Parse a message on stream index's rxfifo.
net_error_e busman_parsemessage(busman_t* man,uint8_t index){
	
	net_error_e err;
	//Temp location for data:
	uint8_t msgdata[32];
	msg_info_t info;

	//We expect the same back:
	err = parse_message(man->streams[index]->rxfifo,msgdata,32,&info);
	if (err != NET_ERR_NONE){
		//Failed.
		return err;
	}else{
		//What should we do with the message?
		uint8_t cmd = (info.cmd & MASK_CMD);
		//Went ok.
		debprintf(CLR_GREEN,0,"Parse OK: addr %u cmd: %u\n",info.address,cmd);
		
		
		//Does a commandhadler exist?
		uint8_t handler_index;
		if (busman_gethandler(man,cmd,&handler_index)){
			return man->cmd_handler[handler_index](man,man->streams[index],msgdata,&info);
		}else{
			return busman_handlemessage(man,man->streams[index],msgdata,&info);
		}
		
	}
	return NET_ERR_UNDEFINED;

}
Example #6
0
void vrpn_Oculus::on_data_received(std::size_t bytes,
  vrpn_uint8 *buffer)
{
  /* For debugging
     printf("Got %d bytes:\n", static_cast<int>(bytes));
     for (size_t i = 0; i < bytes; i++) {
     printf("%02X ", buffer[i]);
     }
     printf("\n");
     */

  // Set the timestamp for all reports
  vrpn_gettimeofday(&d_timestamp, NULL);

  // Make sure the message length and type is what we expect.
  // We get 64-byte responses on Windows and 62-byte responses on the mac.
  if ( (bytes != 62) && (bytes != 64) ) {
    fprintf(stderr, "vrpn_Oculus::on_data_received(): Unexpected message length %d, ignoring\n",
        static_cast<int>(bytes));
    return;
  }

  switch(buffer[0]) {
    case 1:
      parse_message_type_1(bytes, buffer);
      break;
    default:
      // Delegate message type to child
      if (!parse_message(bytes, buffer)) {
        fprintf(stderr, "vrpn_Oculus::on_data_received(): Unexpected message type %d, ignoring\n",
            buffer[0]);
      }
      break;
  }
}
Example #7
0
static void debug_parse(char *string, const char *error)
{
	if (*string && strchr("~@&", *string))
	{
		char *text = string + 1;
		const char *end;

		if (*text == '"')
		{
			end = parse_string(text, '\n');
			dc_output(1, text, -1);
		}
		else
		{
			dc_output(1, string, -1);
			end = NULL;
		}

		if (error)
			dc_error("%s, ignoring to EOLN", error);
		else if (!end)
			dc_error("\" expected");
		else if (g_str_has_prefix(string, "~^(Scope)#07"))
			on_inspect_signal(string + 12);
	}
 	else if (!strcmp(string, "(gdb) "))  /* gdb.info says "(gdb)" */
 	{
		dc_output(3, "(gdb) ", 6);
		wait_prompt = wait_result;
	}
	else
	{
		char *message;

		for (message = string; isdigit(*message); message++);

		if (error || option_library_messages || !g_str_has_prefix(message, "=library-"))
			dc_output_nl(1, string, -1);

		if (*message == '^')
		{
			iff (wait_result, "extra result")
				wait_result--;
		}

		if (*string == '0' && message > string + 1)
		{
			memmove(string, string + 1, message - string - 1);
			message[-1] = '\0';
		}
		else
			string = NULL;  /* no token */

		if (error)
			dc_error("%s, ignoring to EOLN", error);
		else
			parse_message(message, string);
	}
}
Example #8
0
END_TEST

START_TEST(test_ws_error_2)
{
    parse_message(__parser_info, __buf, MESSAGE);

    __waiting_error = WS_CLOSING_FRAME;
    parse_closing_frame(__parser_info, __buf);

    event_dispatch();

    __waiting_error = WS_PARSE_ERROR;
    parse_message(__parser_info, __buf, MESSAGE);

    __waiting_call_count = 3;

    __waiting_call_info =  ERROR_CALL | MESSAGE_CALL;
}
Example #9
0
int
dev_getdata(void)
{

    struct buffer *bp = Pty.inbuff;
    int retc;
    int size;
    unsigned char type;

    size = Pty.iosize;

    if (Hold == TRUE) {
	Hold = FALSE;
	retc = 1;
	Databuf[0] = Holdbuf[0];
    }
    else {
	if ((retc = read(P_mfd, Databuf, size)) == -1) {
	    if (errno == EAGAIN) {
		retc = 0;
	    }
	    else {
		sysmessage(MSG_ERR,
			   "Can't read from master pty: %s\n",
			   strerror(errno));
# ifdef TSR_MEASURE
		devnreads++;
# endif
		return (retc);
	    }
	}
    }

    if (Debug > 2) {
	sysmessage(MSG_DEBUG, " DATA: %d bytes: ", retc);
    }
    if (Debug > 2) {
	int i;
	char debbuf[128];
	char oct[8];

	sprintf(debbuf, "DAT: ");
	for (i = 0; i < retc && i < 8; i++) {
	    sprintf(oct, "%02X ", (unsigned char) Databuf[i]);
	    strcat(debbuf, oct);
	}
	sysmessage(MSG_DEBUG, "%s\n", debbuf);
    }

    type = Databuf[0];

    parse_message(type, Databuf, retc);

    return (0);
}
Example #10
0
END_TEST

START_TEST(test_ws_error_1)
{
    parse_message(__parser_info, __buf, MESSAGE);

    parse_part(__parser_info, __buf, "cdcd");

    __waiting_call_count = 2;
    __waiting_call_info = ERROR_CALL | MESSAGE_CALL;
}
void parse_message(const CubeObjectMsg& msg,
                   std::shared_ptr<FrameObject>* fo) {
  CHECK_NOTNULL(fo);

  CubeObject* cube = new CubeObject;
  cube->type = FrameObject::Type::Cube;

  ReadPoseSE3(msg.t_po(), &cube->t_po);
  parse_message(msg.scale(), &cube->scale);
  fo->reset(cube);
}
Example #12
0
bool resolver::make_request(const char* name, size_t namelen, rr_type type, bool in_cache)
{
	msg msg;
	msg.h = (header*) msg.data;

	fill_header(msg.h, QUERY_STANDARD);

	size_t size;
	if (!fill_question(name, namelen, type, msg.data + sizeof(header), size)) {
		return false;
	}

	size += sizeof(header);

	if (!in_cache) {
		if (!add_to_cache(name, namelen, type)) {
			return false;
		}
	}

	int sd;
	if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		perror("socket");
		return false;
	}

	struct sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = 0x0102a8c0;
	addr.sin_port = htons(DNS_SERVER_PORT);

	memset(&addr.sin_zero, 0, sizeof(addr.sin_zero));

	ssize_t ret;
	if ((ret = sendto(sd, msg.data, size, 0, (const struct sockaddr*) &addr, sizeof(struct sockaddr))) != (ssize_t) size) {
		perror("sendto");
		close(sd);
		return false;
	}

	socklen_t addrlen = sizeof(struct sockaddr);
	if ((ret = recvfrom(sd, msg.data, sizeof(msg.data), 0, (struct sockaddr*) &addr, &addrlen)) < 0) {
		perror("sendto");
		close(sd);
		return false;
	}

	close(sd);

	msg.end = msg.data + ret;

	return parse_message(msg);
}
void parse_message(const FrameObjectMsg& msg,
                   std::shared_ptr<FrameObject>* fo) {
  CHECK_NOTNULL(fo);

  switch (msg.type()) {
    case FrameObjectMsg::Cube:
      parse_message(msg.GetExtension(CubeObjectMsg::object), fo);
      break;
    case FrameObjectMsg::Teapot:
      parse_message(msg.GetExtension(TeapotObjectMsg::object), fo);
      break;
    case FrameObjectMsg::Text:
      parse_message(msg.GetExtension(TextObjectMsg::object), fo);
      break;
    default:
      LOG(FATAL) << "Unkown FrameObject type being serialized";
  }

  std::copy(msg.uuid().begin(), msg.uuid().end(),
            rslam::uuid::uuid_begin((*fo)->id));
}
Example #14
0
File: save.c Project: OPSF/uClinux
/*
 * Process REGISTER request and save it's contacts
 */
static inline int save_real(struct sip_msg* _m, udomain_t* _t, char* _s, int doreply)
{
	contact_t* c;
	int st;
	str aor, ua;

	rerrno = R_FINE;

	if (parse_message(_m) < 0) {
		goto error;
	}

	if (check_contacts(_m, &st) > 0) {
		goto error;
	}
	
	get_act_time();
	c = get_first_contact(_m);

	if (extract_aor(&get_to(_m)->uri, &aor) < 0) {
		LOG(L_ERR, "save(): Error while extracting Address Of Record\n");
		goto error;
	}

	ua.len = 0;
	if (parse_headers(_m, HDR_USERAGENT, 0) != -1 && _m->user_agent &&
	    _m->user_agent->body.len > 0) {
		ua.len = _m->user_agent->body.len;
		ua.s = _m->user_agent->body.s;
	}
	if (ua.len == 0) {
		ua.len = UA_DUMMY_LEN;
		ua.s = UA_DUMMY_STR;
	}

	if (c == 0) {
		if (st) {
			if (star(_t, &aor) < 0) goto error;
		} else {
			if (no_contacts(_t, &aor) < 0) goto error;
		}
	} else {
		if (contacts(_m, c, _t, &aor, &ua) < 0) goto error;
	}

	if (doreply && (send_reply(_m) < 0)) return -1;
	else return 1;
	
 error:
	if (doreply) send_reply(_m);
	return 0;
}
Example #15
0
void *service_single_client(void *args) {
	
	workerArgs *wa;
	int socket;
	chirc_server *ourserver;
    char *clientname;
    list_t userchans;
    person client;
    client.nick[0] = '\0';
    client.user[0] = '\0';
    client.fullname[0] = '\0';
    client.mode[0] = '\0';
    pthread_mutex_init(&(client.c_lock), NULL);
    
    //unpack arguments
	wa = (workerArgs*) args;
	socket = wa->socket;
	ourserver = wa->server;
    
    //set up client struct
    list_init(&userchans);
    if(list_attributes_seeker(&userchans, fun_seek) == -1){
        perror("list fail");
        exit(-1);
    }
    if(list_attributes_comparator(&userchans, fun_compare) == -1){
        perror("list fail");
        exit(-1);
    }
    clientname = wa->clientname;
    client.clientSocket = socket;
    client.address = clientname;
    client.my_chans = &userchans;
    client.tid = pthread_self();
    
    free(wa);

    //add client to list
    pthread_mutex_lock(&lock);
    list_append(ourserver->userlist, &client);
    pthread_mutex_unlock(&lock);

	pthread_detach(pthread_self());

    //actually get messages
	parse_message(socket, ourserver);
	
	pthread_mutex_destroy(&(client.c_lock));

	close(socket);
	pthread_exit(NULL);
}
Example #16
0
//size_t    msg_recv( msg_t   msg ) // Return type has changed in new version
void    msg_recv( msg_t   msg )
{
   size_t msg_size;
   
   OLED_puts(0, 41, 0xff, font6x9, "Message");
   msg_size = parse_message(msg);
   total_msg_count++;
   event_emit(LOW_PRIORITY, DISPLAY_EVT, 2);
   msg_destroy(msg);
      
//   return msg_size;
//   return (sizeof(struct msginfo) + minfo.body_size);
}
Example #17
0
static int
compare_message(const void *_a, const void *_b)
{
    AIM_ASSERT(comparator != NULL);

    of_object_storage_t obj_a_storage;
    of_object_t *obj_a = parse_message(*(uint8_t * const *)_a, &obj_a_storage);

    of_object_storage_t obj_b_storage;
    of_object_t *obj_b = parse_message(*(uint8_t * const *)_b, &obj_b_storage);

    if (obj_a == NULL || obj_b == NULL) {
        return 0;
    }

    if (obj_a->object_id == OF_BARRIER_REQUEST) {
        /* Barriers go to the end of the bundle */
        return 1;
    }

    return comparator(obj_a, obj_b);
}
Example #18
0
int
main()
{
	MSGREC mrec;


	while (read(0, &mrec, sizeof(mrec)) == sizeof(mrec))
	{
		parse_message(&mrec, gbuf);
		printf("%s\n", gbuf);
	}

	return 0;
}
static void* socket_loop(void* arg)
{
    int msgsock, rval, ret, socket;
    char buf[1024];
    int len;
    char lsb, msb;
    ServiceContext *context = get_service_context();
    (void) arg;

    if ((ret = internal_init()) < 0) {
        LOGE("Error initializing socket");
        return NULL;
    } else
        socket = ret;

    LOGD("%s, socket=%d", __FUNCTION__, socket);

    while(1) {
        msgsock = accept(socket, 0, 0);
        context->socket = msgsock;
        LOGD("%s, msgsock=%d", __FUNCTION__, msgsock);

        if (msgsock == -1) {
            LOGE("socket accept: %s, exiting service loop", strerror(errno) );
            close(socket);
            return NULL;
        } else {
            do {
                memset(buf, 0, 1024);
                len = lsb = msb = 0;
                if ((rval = read(msgsock, &msb, 1)) < 0)
                        LOGE("reading stream length: %s", strerror(errno));
                if ((rval = read(msgsock, &lsb, 1)) < 0)
                        LOGE("reading stream length: %s", strerror(errno));

                len |= msb;
                len = len << 8;
                len |= lsb;
                if ((rval = read(msgsock, buf, len)) < 0)
                    LOGE("reading stream message: %s", strerror(errno) );
                else if (rval > 0)
                    parse_message(buf);
            } while (rval > 0);
        }
        close(msgsock);
    }

    LOGD("%s exiting", __FUNCTION__);
    return NULL;
}
Example #20
0
/* Parses a whole file of messages. */
void 
parse_messages(FILE *input, char *keyword, bool sort)
{
    struct list *l = list_init();
    char *text = (char *) malloc(500);
          
    while (fgets(text, 500, input) != NULL) {
        parse_message(text, l, keyword);
    }
    if (sort) 
        list_sort(l);
    list_print(l);
    list_free(l);    
}
Example #21
0
bool parse_and_pop( gpb::MessageLite &result )
{
    std::string &data(queue_->messages( ).front( ));

    /// check hash
    bool checked = check_message( data );
    if( checked ) {
        /// parse
        checked = parse_message( data, result );
    }

    /// in all cases we pop message
    queue_->messages( ).pop_front( );
    return checked;
}
static void
handle_incoming_data()
{
  PRINTF("Incoming packet size: %u \n", (u16_t)uip_datalen());
  if (init_buffer(COAP_DATA_BUFF_SIZE)) {
    if (uip_newdata()) {
      coap_packet_t* response = (coap_packet_t*)allocate_buffer(sizeof(coap_packet_t));
      parse_message(response, uip_appdata, uip_datalen());
      if (response) {
        response_handler(response);
      }
    }
    delete_buffer();
  }
}
Example #23
0
	void *connection_plusieurs(void *list_args)
		{
		
		char buffer[10241];
		char buff[3000];
		int num =0;
		thread_args *my_list_args = (thread_args*)list_args;
		tuser *L=NULL;
        user *c=NULL;
		while(1){
			num= recv(my_list_args->client_fd, buffer, 10240,0);
			if (num == -1) {
				perror("recv");
				exit(1);
			}  
			else if (num == 0) {
				printf("Connection closed\n");
				return 0;
			}
			else{
							
			recv(my_list_args->client_fd,buffer, sizeof(buffer),50000);
			
			irc_msg *message=NULL;
			message=(irc_msg*)malloc(sizeof(irc_msg));
			parse_message(buffer,message);
			affiche_parsed_message ( message);
			
			if ( user_connexion(my_list_args->lu,L,c,message->param[0],message->trailing,message->command) == 0 )
			{
            
				strcpy(buff,"SORRY THIS NICKNAME EXIST");
           	
            
			}
			else
			{ 	//user ok , and send welcome numeric
			
				strcpy(buff,"001\n");
			}


			send(my_list_args->client_fd,(char *)buff, sizeof(buff), 0);
			}
		}
		return 0;
	}
void receiveCommands() {
    if(Serial.available()) {
        while(Serial.available() > 0){
            char c = Serial.read();
            input += c;
            if(c == ')' || c =='>'){
                parse_message(input);
                input = "";
            } else if(c == 'u') {
                motorStepUp();
                input = "";
            } else if(c == 'd') {
                motorStepDown();
                input = "";
            }
        }
    }
}
Example #25
0
int main(int argc, char **argv)
{

	setvbuf(stdin, NULL, _IONBF, 0);
	setvbuf(stdout, NULL, _IONBF, 0);
	
	if (argc == 2 && !strcmp(argv[1], "--emoncms"))
		output_fmt = emoncms_fmt;
	else output_fmt = hm_fmt;
	
	char buf[4096];
	while (!feof(stdin)) {
		if (!fgets(&buf[0], 4095, stdin))
			sleep(1);
		parse_message(&buf[0]);
	}


}
Example #26
0
int
parse_all_client_messages(void)
{
	Client *c;

	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	for (c = clients_getfirst(); c != NULL; c = clients_getnext()) {
		char *str;

		/* And parse all its messages...*/
		/*debug(RPT_DEBUG, "parse: Getting messages...");*/
		for (str = client_get_message(c); str != NULL; str = client_get_message(c)) {
			parse_message(str, c);
			free(str);
		}
	}
	return 0;
}
Example #27
0
// Initializes the algorithm.
void algorithm_init() {
	// Read command line options
	algorithm.configuration.binary = commandline_option_provided("-b", "--binary");
	algorithm.configuration.verbosity = commandline_option_value_int("-v", "--verbosity", 1);

	// Check if the user provided enough arguments
	if (commandline_argument_count() < 1) {
		help();
		exit(1);
	}

	// Get hostname and port (first argument)
	algorithm.configuration.port = commandline_option_value_int("-p", "--port", 3000);
	strncpy(algorithm.configuration.hostname, commandline_argument(0, 0), 1023);
	parse_hostname_port();

	// Parse the message
	parse_message();
}
Example #28
0
static void handle_message(char *msg) {
    printf("message received: %s\n", msg);

    struct message_t *message;
    char *title;
    char *icon;

    message = parse_message(msg);

    switch (message->event_type) {
        case Ring:
            asprintf(&title, "Call: %s", message->data);
            icon = "call-start";
            break;

        case SMS:
            asprintf(&title, "SMS: %s", message->data);
            icon = "stock_mail-unread";
            break;
        case MMS:
            asprintf(&title, "MMS: %s", message->data);
            icon = "stock_mail-unread";
            break;
        case Battery:
            asprintf(&title, "Battery: %s", message->data);
            icon = "battery-good"; // TODO: various levels and charge-state
            break;
        case Ping:
            title = "Ping";
            icon = "emblem-important";
            break;

        default:
            return;
    }

    notify_init("android-receiver");
    NotifyNotification *n = notify_notification_new(title, message->event_contents, icon);
    notify_notification_show(n, NULL);
    g_object_unref(G_OBJECT(n));
    notify_uninit();
}
Example #29
0
int main(int ac, char **av)
{
  t_message msg;
  int ok;
  char **p;

  msg.prefix = NULL;
  msg.command = 0;
  msg.params = NULL;
  if (ac == 2)
    ok = parse_message(&msg, av[1]);
  printf("-- Parsing %s --\n", (!ok ? "OK" : "KO"));
  printf("prefix: %s\n", msg.prefix);
  printf("command: %d\n", msg.command);
  printf("params:\n");
  for (p = msg.params; *p; p++)
    printf("\t%s\n", *p);
  printf("Recomposing command string:\n");
  printf("%s\n", get_string_from_message(&msg));
  return (0);
}
Example #30
0
static ind_soc_task_status_t
bundle_task(void *cookie)
{
    struct bundle_task_state *state = cookie;

    connection_t *cxn = ind_cxn_id_to_connection(state->cxn_id);

    while (state->offset < state->count) {
        if (cxn) {
            of_object_storage_t obj_storage;
            of_object_t *obj = parse_message(state->msgs[state->offset], &obj_storage);
            ind_cxn_process_message(cxn, obj);
        } else {
            /* Connection went away. Drop remaining messages. */
        }

        aim_free(state->msgs[state->offset]);
        state->msgs[state->offset] = NULL;
        state->offset++;

        if (ind_soc_should_yield()) {
            return IND_SOC_TASK_CONTINUE;
        }
    }

    if (cxn) {
        indigo_cxn_send_controller_message(cxn->cxn_id, state->reply);
    } else {
        of_object_delete(state->reply);
    }

    aim_free(state->msgs);
    aim_free(state);

    if (cxn) {
        ind_cxn_resume(cxn);
    }

    return IND_SOC_TASK_FINISHED;
}