Ejemplo n.º 1
0
void clear_all_message(play_para_t *para)
{
    player_cmd_t *cmd;
    while ((cmd = get_message(para)) != NULL) {
        message_free(cmd);
    }
}
Ejemplo n.º 2
0
int send_message_update(play_para_t *para, player_cmd_t *cmd)
{
    int i, j;
    player_cmd_t *oldcmd;
    int updated = 0;

    message_pool_t *pool = &para->message_pool;
    //log_print("[send_message:%d]num=%d in_idx=%d out_idx=%d\n",__LINE__,pool->message_num,pool->message_in_index,pool->message_out_index);
    pthread_mutex_lock(&pool->msg_mutex);
    j = pool->message_out_index;
    for (i = 0; i < pool->message_num; i++) {
        oldcmd = pool->message_list[j];
        if (oldcmd && (oldcmd->ctrl_cmd == cmd->ctrl_cmd)) { /*same cmd*/
            *oldcmd = *cmd; /*update old one*/
            log_print("found old message update old one.\n");
            updated = 1;
            break;
        }
    }
    pthread_mutex_unlock(&pool->msg_mutex);
    if (!updated) {
        return send_message(para, cmd);
    } else {
        message_free(cmd);
    }
    return 0;
}
Ejemplo n.º 3
0
int key_response_start(void * sub_proc,void * para)
{
	int ret;
	int retval;
	void * recv_msg;
	void * send_msg;
	void * context;
	int i;
	const char * type;

	printf("begin key response start!\n");

	for(i=0;i<3000*1000;i++)
	{
		usleep(time_val.tv_usec);
		ret=sec_subject_recvmsg(sub_proc,&recv_msg);
		if(ret<0)
			continue;
		if(recv_msg==NULL)
			continue;

 		type=message_get_recordtype(recv_msg);
		if(type==NULL)
		{
			message_free(recv_msg);
			continue;
		}
		if(strncmp(type,"KREC",4)==0)
		{
			proc_key_response(sub_proc,recv_msg);
		}
	}

	return 0;
};
Ejemplo n.º 4
0
void friend_free(FRIEND *f)
{
    uint16_t j = 0;
    while(j != f->edit_history_length) {
        free(f->edit_history[j]);
        j++;
    }
    free(f->edit_history);

    free(f->name);
    free(f->status_message);
    free(f->typed);

    MSG_IDX i = 0;
    while(i < f->msg.n) {
        MESSAGE *msg = f->msg.data[i];
        message_free(msg);
        i++;
    }

    free(f->msg.data);

    if(f->call_state_self) {
        // postmessage_audio(AUDIO_END, f->number, 0, NULL);
        /* TODO end a video call too!
        if(f->calling == CALL_OK_VIDEO) {
            postmessage_video(VIDEO_CALL_END, f->number, 0, NULL);
        }*/
    }

    memset(f, 0, sizeof(FRIEND));//
}
Ejemplo n.º 5
0
static void debug_control_thread(node *n, endpoint *endpt, void *arg)
{
  debug_control *dbc = (debug_control*)arg;
  message *msg;
  int done = 0;
  int indebug = 0;

  while (!done) {
    msg = endpoint_receive(endpt,indebug ? -1 : DEBUG_DELAY);
    if (NULL == msg) {
      assert(!indebug);
      endpoint_send(endpt,dbc->epid,MSG_DEBUG_START,&endpt->epid,sizeof(endpointid));
      indebug = 1;
    }
    else {
      switch (msg->tag) {
      case MSG_DEBUG_DONE:
        assert(indebug);
        indebug = 0;
        break;
      case MSG_KILL:
        fatal("Node shutdown during chord test");
        break;
      default:
        fatal("debug_control received invalid message: %d",msg->tag);
        break;
      }
      message_free(msg);
    }
  }

  free(dbc);
}
/**
 * Responder thread main body.
 * Collects responses from the opensrf network and relays them to the 
 * websocket caller.
 */
void* APR_THREAD_FUNC osrf_responder_thread_main(apr_thread_t *thread, void *data) {

    transport_message *tmsg;
    while (1) {

        if (apr_thread_mutex_unlock(trans->mutex) != APR_SUCCESS) {
            osrfLogError(OSRF_LOG_MARK, "WS error un-locking thread mutex");
            return NULL;
        }

        // wait for a response
        tmsg = client_recv(osrf_handle, -1);

        if (!tmsg) continue; // interrupt

        if (trans->client_connected) {

            if (apr_thread_mutex_lock(trans->mutex) != APR_SUCCESS) {
                osrfLogError(OSRF_LOG_MARK, "WS error locking thread mutex");
                return NULL;
            }

            osrfLogForceXid(tmsg->osrf_xid);
            osrf_responder_thread_main_body(tmsg);
            last_activity_time = time(NULL);
        }

        message_free(tmsg);                                                         
    }

    return NULL;
}
Ejemplo n.º 7
0
void send_debug(unsigned char type, const char *format, ...) {

	// make a run over the vararg parameter to determine the size
	va_list args;
	va_start(args, format);
	unsigned int size = vsnprintf(NULL, 0, format, args) + 1;
	va_end(args);

    // properly align the char array to sizeof(int)
    // under the assumption, that sizeof(int) % sizeof(char) = 0
    #define cpi (sizeof(int) / sizeof(char))
    size += (cpi - (size % cpi)) % cpi;

    // FIXME check, that the resulting size is smaller than the maxsize of the protocol!?
//    if(size > )

    // allocate memory and store the formatted string
    char *c = malloc(sizeof(char) * size);
    va_start(args, format);
    vsnprintf(c, size, format, args);
    va_end(args);

	// encode and send a message (using sizeof(int) as size)
	struct Message *m = encode_debug(type, size / cpi);
	message_payload(m, (int*)c, size / cpi);
	medium_send(m);

	// free allocated memory
	message_free(m);
	free(c);
}
Ejemplo n.º 8
0
static void handle_msg_id_ble_rpc_callin(struct message *msg, void *priv)
{
	struct ble_rpc_callin *rpc = container_of(msg, struct ble_rpc_callin, msg);
	/* handle incoming message */
	rpc_deserialize(rpc->p_data, rpc->len);
	bfree(rpc->p_data);
	message_free(msg);
}
Ejemplo n.º 9
0
void connection_free(connection* conn)
{
    if (conn->conn_fd != -1) {
        close(conn->conn_fd);
    }
    if (conn->current_msg != NULL) {
        message_free(conn->current_msg);
    }
    free(conn);
}
Ejemplo n.º 10
0
/** Appends a messages from self or firend to the message list;
 * will realloc or trim messages as needed;
 *
 * also handels auto scrolling selections with messages
 *
 * accepts: MESSAGES *pointer, MESSAGE *pointer, MSG_DATA *pointer
 */
void message_add(MESSAGES *m, MESSAGE *msg, MSG_DATA *p)
{
    time_t rawtime;
    struct tm *ti;
    time(&rawtime);
    ti = localtime(&rawtime);

    // Set the time this message was recived by utox
    msg->time = ti->tm_hour * 60 + ti->tm_min;

    if(p->n < MAX_BACKLOG_MESSAGES) {
        p->data = realloc(p->data, (p->n + 1) * sizeof(void*));
        p->data[p->n++] = msg;
    } else {
        p->height -= ((MESSAGE*)p->data[0])->height;
        message_free(p->data[0]);
        memmove(p->data, p->data + 1, (MAX_BACKLOG_MESSAGES - 1) * sizeof(void*));
        p->data[MAX_BACKLOG_MESSAGES - 1] = msg;

        // Scroll selection up so that it stays over the same messages.
        if (p->istart != MSG_IDX_MAX) {
            if(0 < p->istart) {
                p->istart--;
            } else {
                p->start = 0;
            }
        }
        if (p->iend != MSG_IDX_MAX) {
            if(0 < p->iend) {
                p->iend--;
            } else {
                p->end = 0;
            }
        }
        if (p == m->data) {
            if (m->idown != MSG_IDX_MAX) {
                if(0 < m->idown) {
                    m->idown--;
                } else {
                    m->down = 0;
                }
            }
            if (m->iover != MSG_IDX_MAX) {
                if(0 < m->iover) {
                    m->iover--;
                } else {
                    m->over = 0;
                }
            }
        }
    }

    message_setheight(m, msg, p);
}
Ejemplo n.º 11
0
Archivo: server.c Proyecto: rtoy/cmucl
void MyWarningHandler(String errmsg)
{
    message_t reply = message_new(next_serial++);
    message_add_packet(reply);

    fprintf(stderr,"Warning: %s\n",errmsg);
    fflush(stderr);
    message_put_dblword(reply,WARNING_REPLY);
    message_write_string(reply,errmsg,string_tag);
    message_send(client_socket,reply);
    message_free(reply);
}
Ejemplo n.º 12
0
void friend_free(FRIEND *f)
{
    uint16_t j = 0;
    while(j != f->edit_history_length) {
        free(f->edit_history[j]);
        j++;
    }
    free(f->edit_history);

    free(f->name);
    free(f->status_message);
    free(f->typed);

    MSG_IDX i = 0;
    while(i < f->msg.n) {
        MESSAGE *msg = f->msg.data[i];
        if((msg->flags & (~1)) == 4) {
            //MSG_IMG *img = (void*)msg;
            //todo: free image
        }
        if((msg->flags & (~1)) == 6) {
            MSG_FILE *file = (void*)msg;
            free(file->path);
            FILE_T *ft = &f->incoming[file->filenumber];
            if(ft->data) {
                if(ft->inline_png) {
                    free(ft->data);
                } else {
                    fclose(ft->data);
                    free(ft->path);
                }
            }

            if(msg->flags & 1) {
                ft->status = FT_NONE;
            }
        }
        message_free(msg);
        i++;
    }

    free(f->msg.data);

    if(f->calling) {
        toxaudio_postmessage(AUDIO_CALL_END, f->callid, 0, NULL);
        if(f->calling == CALL_OK_VIDEO) {
            toxvideo_postmessage(VIDEO_CALL_END, f->callid, 0, NULL);
        }
    }

    memset(f, 0, sizeof(FRIEND));//
}
Ejemplo n.º 13
0
/**
 * Sends an acknowledgment to the client-side driver.
 * This should happen automatically after an in-going data package.
 * @param pid Port, for which data is acknowledged.
 * @param count Number of values that is acknowledged
 */
static void send_ack(unsigned char pid, unsigned int count) {
    // send several acknowledges, if the protocol cannot fit a full ack
    // this should not be the case with the current protocol impl, since data and ack messages have equal maxsize.
    while(count > PROTO_ACK_SIZE) {
        send_ack(pid, PROTO_ACK_SIZE);
        count -= PROTO_ACK_SIZE;
    }

    struct Message *m = encode_ack(pid, count);
	print_message(m);
	medium_send(m);
	message_free(m);
}
Ejemplo n.º 14
0
void network_announce_ourselves(struct uloop_timeout *timer)
{
  // TODO: Generate announce message.
  message_t msg;
  message_init(&msg);
  network_send_message(&msg);
  message_free(&msg);

  // Reschedule timer if no peer selected.
  if (net_status.peer == NULL) {
    uloop_timeout_set(timer, KORUZA_ANNOUNCE_INTERVAL);
  }
}
Ejemplo n.º 15
0
void
message_list_free (message_list_ty *mlp, int keep_messages)
{
  size_t j;

  if (keep_messages == 0)
    for (j = 0; j < mlp->nitems; ++j)
      message_free (mlp->item[j]);
  if (mlp->item)
    free (mlp->item);
  if (mlp->use_hashtable)
    hash_destroy (&mlp->htable);
  free (mlp);
}
Ejemplo n.º 16
0
void *message_travel(void *arg)
{
	struct message_t *msg;
	while(1) {
		sleep(argument.msgitv);
		if(head == NULL) continue;
		while((msg = message_delete())) {
			msg_proc((void *)msg->data, msg->len, msg->proto);
			message_free(msg);
		}
		sys_debug("Message travel pthreads (next %d second later)\n", 
			argument.msgitv);
	}
	return NULL;
}
Ejemplo n.º 17
0
void check_preload_message(table_t *tbl, int which, int done, uint64_t size) {
  message_t *msg = message_tryget();

  assert(msg != NULL);
  assert(msg->kind == msg_preload);

  msg_load_t *msg_load = msg->data;

  assert(msg_load->tbl == tbl);
  assert(msg_load->which == which);
  assert(msg_load->done == done);
  assert(msg_load->size == size);

  message_free(msg);
}
Ejemplo n.º 18
0
Archivo: server.c Proyecto: rtoy/cmucl
void MyErrorHandler(String errmsg)
{
    message_t reply = message_new(next_serial++);
    message_add_packet(reply);

    fprintf(stderr,"Error: %s\n",errmsg);
    fflush(stderr);
    message_put_dblword(reply,ERROR_REPLY);
    message_write_string(reply,errmsg,string_tag);
    message_send(client_socket,reply);
    message_free(reply);

    longjmp(env,1);
    exit(-1);
}
Ejemplo n.º 19
0
static void
my_message_callback(struct mosquitto *mosq, void *userdata,
		    const struct mosquitto_message *message)
{
	if (message->payloadlen)
	{
		llog(LOG_INFO, "Received message %s : %s\n", message->topic,
		     message->payload);
		Subscription *subscription = subscription_get(&SUBSCRIPTIONS,
							      message->topic);
		if (subscription)
		{
			llog(LOG_INFO, "Notify %d lws clients for topic %s\n",
			     subscription->count_subscribed, message->topic);

			Message msg;
			message_new(&msg, PUBLISH, message->topic, message->payload);
			message_serialize_response(&msg);

			// create libwebsockets message from MQTT payload
			unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + msg.size
					  + LWS_SEND_BUFFER_POST_PADDING];
			unsigned char *lws_message = &buf[LWS_SEND_BUFFER_PRE_PADDING];
			int lws_message_length = sprintf((char* )lws_message, "%s",
							 msg.serialized);

			// dispatch message to all subscribers
			for (int i = 0; i < subscription->count_subscribed; i++)
			{
				struct libwebsocket *wsi = subscription->subscribers[i];
				int bytes_written = libwebsocket_write(wsi, lws_message,
								       lws_message_length, LWS_WRITE_TEXT);
				if (bytes_written < lws_message_length)
				{
					llog(LOG_ERR,
					     "ERROR only %d bytes written (message length is %d)\n",
					     bytes_written, lws_message_length);
				}
			}
			message_free(&msg);
		}
		else
			llog(LOG_ERR, "No lws clients are subscribed to topic %s\n",
			     message->topic);
	}
	else
		printf("%s (null)\n", message->topic);
}
Ejemplo n.º 20
0
void RXmTextGetSelectionPosition(message_t message)
{
  Widget w;
  Boolean result;
  XmTextPosition left,right;
  message_t reply=prepare_reply(message);

  toolkit_read_value(message,&w,XtRWidget);
  result=XmTextGetSelectionPosition(w,&left,&right);

  message_write_boolean(reply,result,boolean_tag);
  message_write_int(reply,left,int_tag);
  message_write_int(reply,right,int_tag);
  message_send(client_socket,reply);
  message_free(reply);
  must_confirm=False;
}
Ejemplo n.º 21
0
Archivo: server.c Proyecto: rtoy/cmucl
void greet_client(int socket) {
    short byte;
    int result;
    char *dpy_name,*app_class,*app_name;
    message_t first;

    /* Read byte-swap thing */
    result = read(socket,&byte,2);
    if( !result )  fatal_error("greet_client:  Unable to read initial data.");
    else if( result == 1 ) {
        result = read(socket, ((char *) &byte)+1,1);
        fatal_error("greet_client:  Unable to read initial data.");
    }

    swap_bytes = (byte!=1);
    if( global_will_trace ) {
        printf("swap_bytes is: %d (from %d)\n",swap_bytes,byte);
        fflush(stdout);
    }

    /* Read initial packet */
    first = message_read(socket);
    if( !first )
        fatal_error("greet_client:  No greeting packet sent.");

    toolkit_read_value(first,&dpy_name,XtRString);
    toolkit_read_value(first,&app_name,XtRString);
    toolkit_read_value(first,&app_class,XtRString);

    global_app_class = XtNewString(app_class);
    global_app_name  = XtNewString(app_name);

    if( global_will_trace ) {
        printf("Opening display on '%s' for app '%s' class '%s'\n",dpy_name,
               app_name,app_class);
        fflush(stdout);
    };
    display = XtOpenDisplay(app_context, dpy_name,
                            app_name, app_class,
                            NULL, 0,
                            &global_argc, global_argv);
    if( !display )
        fatal_error("greet_client:  Unable to open display.");

    message_free(first);
}
Ejemplo n.º 22
0
int proc_aikclient_start(void * sub_proc,void * para)
{
	int ret;
	int retval;
	void * recv_msg;
	void * send_msg;
	void * context;
	int i;
	const char * type;

	char local_uuid[DIGEST_SIZE*2+1];
	char proc_name[DIGEST_SIZE*2+1];
	
	ret=proc_share_data_getvalue("uuid",local_uuid);
	ret=proc_share_data_getvalue("proc_name",proc_name);

	printf("begin aik process start!\n");

	for(i=0;i<300*1000;i++)
	{
		usleep(time_val.tv_usec);
		ret=sec_subject_recvmsg(sub_proc,&recv_msg);
		if(ret<0)
			continue;
		if(recv_msg==NULL)
			continue;

 		type=message_get_recordtype(recv_msg);
		if(type==NULL)
		{
			message_free(recv_msg);
			continue;
		}
		if(strncmp(type,"SYNI",4)==0)
		{
			proc_aik_request(sub_proc,recv_msg);
		}
		else if(strncmp(type,"FILD",4)==0)
		{
			proc_aik_activate(sub_proc,recv_msg);
		}
	}

	return 0;
};
Ejemplo n.º 23
0
void friend_free(FRIEND *f)
{
    uint16_t j = 0;
    while(j != f->edit_history_length) {
        free(f->edit_history[j]);
        j++;
    }
    free(f->edit_history);

    free(f->name);
    free(f->status_message);
    free(f->typed);

    MSG_IDX i = 0;
    while(i < f->msg.n) {
        MESSAGE *msg = f->msg.data[i];
        switch(msg->msg_type) {
        case MSG_TYPE_IMAGE: {
            //MSG_IMG *img = (void*)msg;
            //todo: free image
            break;
        }
        case MSG_TYPE_FILE: {
            // TODO KILL THIS SECTION
            MSG_FILE *file = (void*)msg;
            free(file->path);
            break;
        }
        }
        message_free(msg);
        i++;
    }

    free(f->msg.data);

    if(f->calling) {
        toxaudio_postmessage(AUDIO_CALL_END, f->callid, 0, NULL);
        if(f->calling == CALL_OK_VIDEO) {
            toxvideo_postmessage(VIDEO_CALL_END, f->callid, 0, NULL);
        }
    }

    memset(f, 0, sizeof(FRIEND));//
}
Ejemplo n.º 24
0
Archivo: server.c Proyecto: rtoy/cmucl
void get_input(caddr_t closure, int *socket, XtInputId *id)
{
    message_t message;

    if( global_will_trace ) {
        printf("get_input:  Receiving incoming packet.\n");
        fflush(stdout);
    }
    message = message_read(*socket);

    process_request(message,*socket);

    if( global_will_trace ) {
        printf("get_input:  Successfully digested packet.  Now freeing.\n");
        fflush(stdout);
    }

    message_free(message);
}
Ejemplo n.º 25
0
void RXmTextPosToXY(message_t message)
{
  Widget w;
  XmTextPosition pos;
  Boolean result;
  Position x,y;
  message_t reply=prepare_reply(message);

  toolkit_read_value(message,&w,XtRWidget);
  toolkit_read_value(message,&pos,XtRInt);
  result=XmTextPosToXY(w,pos,&x,&y);

  message_write_boolean(reply,result,boolean_tag);
  message_write_int(reply,x,int_tag);
  message_write_int(reply,y,int_tag);
  message_send(client_socket,reply);
  message_free(reply);
  must_confirm=False;
}
/**
	@brief Free a transport_client's resources, but without disconnecting.
	@param client Pointer to the transport_client to be freed.
	@return 1 if successful, or 0 if not.  The only error condition is if @a client is NULL.

	A child process may call this in order to free the resources associated with the parent's
	transport_client, but without disconnecting from Jabber, since disconnecting would
	disconnect the parent as well.
 */
int client_discard( transport_client* client ) {
	if(client == NULL)
		return 0;
	
	transport_message* current = client->msg_q_head;
	transport_message* next;

	/* deallocate the list of messages */
	while( current != NULL ) {
		next = current->next;
		message_free( current );
		current = next;
	}

	free(client->host);
	free(client->xmpp_id);
	free( client );
	return 1;
}
Ejemplo n.º 27
0
      /* A message list has duplicates, although it was allocated with the
         assertion that it wouldn't have duplicates.  It is a bug.  */
      abort ();
}


#if 0 /* unused */
void
message_list_delete_nth (message_list_ty *mlp, size_t n)
{
  size_t j;

  if (n >= mlp->nitems)
    return;
  message_free (mlp->item[n]);
  for (j = n + 1; j < mlp->nitems; ++j)
    mlp->item[j - 1] = mlp->item[j];
  mlp->nitems--;

  if (mlp->use_hashtable)
    {
      /* Our simple-minded hash tables don't support removal.  */
      hash_destroy (&mlp->htable);
      mlp->use_hashtable = false;
    }
}
Ejemplo n.º 28
0
void message_clear(MESSAGES *m, MSG_DATA *p)
{
    MSG_IDX i;

    for(i = 0; i < p->n; i++)
    {
        message_free((MESSAGE*)p->data[i]);
    }

    free(p->data);
    p->data = NULL;
    p->n = 0;

    p->istart = p->iend = p->start = p->end = 0;

    p->height = 0;
    if(m->data == p) {
        m->panel.content_scroll->content_height = p->height;
    }
}
Ejemplo n.º 29
0
Archivo: rqd.c Proyecto: hyper/rqd
//-----------------------------------------------------------------------------
// All the messages should have been processed or cancelled at this point.
static void cleanup_msglist(system_data_t *sysdata)
{
	assert(sysdata);
	assert(sysdata->msg_list);
	assert(sysdata->msg_max > 0);
	assert(sysdata->msg_used == 0);

	while (sysdata->msg_max > 0) {
		sysdata->msg_max --;
		assert(sysdata->msg_list[sysdata->msg_max]);
		assert(sysdata->msg_list[sysdata->msg_max]->id == sysdata->msg_max);
		message_free(sysdata->msg_list[sysdata->msg_max]);
		free(sysdata->msg_list[sysdata->msg_max]);
		sysdata->msg_list[sysdata->msg_max] = NULL;
	}
	
	free(sysdata->msg_list);
	sysdata->msg_list = NULL;
	sysdata->msg_next = -1;
	assert(sysdata->msg_max == 0);
}
Ejemplo n.º 30
0
static chordnode start_one_chord(node *n, endpoint *endpt, endpointid initial, endpointid managerid)
{
  int done = 0;
  chordnode cn;
  start_chord_msg scm;

  memset(&cn,0,sizeof(chordnode));

  scm.initial = initial;
  scm.caller = endpt->epid;
  scm.stabilize_delay = STABILIZE_DELAY;
  endpoint_send(endpt,managerid,MSG_START_CHORD,&scm,sizeof(start_chord_msg));

  while (!done) {
    message *msg = endpoint_receive(endpt,20000);
    if (!msg) {
      fatal("Timeout waiting for CHORD_STARTED message");
    }
    switch (msg->tag) {
    case MSG_CHORD_STARTED: {
      chord_started_msg *m = (chord_started_msg*)msg->data;
      assert(sizeof(chord_started_msg) == msg->size);
      endpoint_link(endpt,m->cn.epid);
      cn = m->cn;
      done = 1;
      break;
    }
    case MSG_KILL:
      fatal("Node shutdown during chord test");
      break;
    default:
      fatal("start_one_chord received invalid message: %d",msg->tag);
      break;
    }
    message_free(msg);
  }

  return cn;
}