Ejemplo n.º 1
0
Archivo: sms.c Proyecto: AndriusA/ofono
static void sms_tx_queue_remove_entry(struct ofono_sms *sms, GList *entry_list,
					enum message_state tx_state)
{
	struct tx_queue_entry *entry = entry_list->data;
	struct ofono_modem *modem = __ofono_atom_get_modem(sms->atom);

	g_queue_delete_link(sms->txq, entry_list);

	DBG("%p", entry);

	if (entry->cb)
		entry->cb(tx_state == MESSAGE_STATE_SENT, entry->data);

	if (entry->flags & OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY) {
		enum ofono_history_sms_status hs;

		switch(tx_state) {
		case MESSAGE_STATE_SENT:
			hs = OFONO_HISTORY_SMS_STATUS_SUBMITTED;
			break;
		case MESSAGE_STATE_FAILED:
			hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_FAILED;
			break;
		case MESSAGE_STATE_CANCELLED:
			hs = OFONO_HISTORY_SMS_STATUS_SUBMIT_CANCELLED;
			break;
		default:
			ofono_error("Unexpected sms state %d", tx_state);
			goto done;
		}

		__ofono_history_sms_send_status(modem, &entry->uuid,
								time(NULL), hs);
	}

	if (entry->flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) {
		struct message *m;

		sms_tx_backup_free(sms->imsi, entry->id, entry->flags,
					ofono_uuid_to_str(&entry->uuid));

		m = g_hash_table_lookup(sms->messages, &entry->uuid);

		if (m != NULL) {
			message_set_state(m, tx_state);
			g_hash_table_remove(sms->messages, &entry->uuid);
			message_emit_removed(m,
					OFONO_MESSAGE_MANAGER_INTERFACE);
			message_dbus_unregister(m);
		}
	}

done:
	tx_queue_entry_destroy(entry);
}
Ejemplo n.º 2
0
int router_dup_activemsg_info (void * message)
{
	int ret;
	struct message_box * msg_box=message;
	MSG_HEAD * msg_head;
	MSG_HEAD * new_msg_head;
	if(message==NULL)
		return -EINVAL;

	void * active_msg=message_get_activemsg(message);
	if(active_msg==NULL)
		return 0;
	if(active_msg==message)
	{
		msg_head=message_get_head(message);
	//	msg_head->ljump++;
		return 0;
	}
	
	msg_head=message_get_head(active_msg);
	new_msg_head=message_get_head(message);
	message_set_flow(msg_box,msg_head->flow);
	message_set_state(msg_box,msg_head->state);
//	message_set_flag(msg_box,msg_head->flag);
	message_set_route(msg_box,msg_head->route);
	new_msg_head->ljump=msg_head->ljump;	
	new_msg_head->rjump=msg_head->rjump;	

	MSG_EXPAND * old_expand;
	MSG_EXPAND * new_expand;
	void * flow_expand;
	ret=message_get_define_expand(active_msg,&old_expand,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE);
	if(old_expand!=NULL) 
	{
		new_expand=Calloc0(sizeof(MSG_EXPAND));
		if(new_expand==NULL)
			return -ENOMEM;
		Memcpy(new_expand,old_expand,sizeof(MSG_EXPAND_HEAD));
		void * struct_template =memdb_get_template(DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE);
		new_expand->expand = clone_struct(old_expand->expand,struct_template);
		message_add_expand(message,new_expand);
	}
	ret=message_get_define_expand(active_msg,&old_expand,DTYPE_MSG_EXPAND,SUBTYPE_ASPECT_POINT);
	if(old_expand!=NULL) 

	{
		new_expand=Calloc0(sizeof(MSG_EXPAND));
		if(new_expand==NULL)
			return -ENOMEM;
		Memcpy(new_expand,old_expand,sizeof(MSG_EXPAND_HEAD));
		void * struct_template =memdb_get_template(DTYPE_MSG_EXPAND,SUBTYPE_ASPECT_POINT);
		new_expand->expand = clone_struct(old_expand->expand,struct_template);
		message_add_expand(message,new_expand);
	}
	ret=message_get_define_expand(active_msg,&old_expand,DTYPE_MSG_EXPAND,SUBTYPE_ROUTE_RECORD);
	if(old_expand!=NULL) 
	{
		new_expand=Calloc0(sizeof(MSG_EXPAND));
		if(new_expand==NULL)
			return -ENOMEM;
		Memcpy(new_expand,old_expand,sizeof(MSG_EXPAND_HEAD));
		void * struct_template =memdb_get_template(DTYPE_MSG_EXPAND,SUBTYPE_ROUTE_RECORD);
		new_expand->expand = clone_struct(old_expand->expand,struct_template);
		message_add_expand(message,new_expand);
	}
	message_set_policy(message,message_get_policy(active_msg));

	return 1;
}
Ejemplo n.º 3
0
int json_port_start(void * sub_proc,void * para)
{
    int ret;
    int retval;
    void * message_box;
    void * context;
    struct tcloud_connector_hub * port_hub;
    struct tcloud_connector * port_conn;
    struct tcloud_connector * recv_conn;
    struct tcloud_connector * channel_conn;
    int i;
    struct timeval conn_val;
    conn_val.tv_usec=time_val.tv_usec;

    char local_uuid[DIGEST_SIZE*2+1];
    char proc_name[DIGEST_SIZE*2+1];
    char buffer[4096];
    memset(buffer,0,4096);
    int stroffset;
	
    printf("begin json server process!\n");
    ret=proc_share_data_getvalue("uuid",local_uuid);
    if(ret<0)
        return ret;
    ret=proc_share_data_getvalue("proc_name",proc_name);

    if(ret<0)
	return ret;
    struct json_server_context * server_context;

    ret=sec_subject_getcontext(sub_proc,&context);
    server_context=sec_object_getpointer(context);

    port_hub=server_context->json_port_hub;

    port_conn=hub_get_connector(server_context->json_port_hub,"json_server");
    if(port_conn==NULL)
        return -EINVAL;

    channel_conn=NULL;
    for(i=0;i<500*1000;i++)
    {
        ret=port_hub->hub_ops->select(port_hub,&conn_val);
        usleep(conn_val.tv_usec);
	conn_val.tv_usec=time_val.tv_usec;
        if(ret>0)
        {

        	do{

           	 	recv_conn=port_hub->hub_ops->getactiveread(port_hub);
        		if(recv_conn==NULL)
                		break;
          		if(connector_get_type(recv_conn)==CONN_SERVER)
            		{

           		     channel_conn=recv_conn->conn_ops->accept(recv_conn);
         		     if(channel_conn==NULL)
                	     {
              			      printf("error: json_server connector accept error %x!\n",channel_conn);
               			      continue;
               		     }
              		     printf("create a new channel %x!\n",channel_conn);

           		     // build a server syn message with service name,uuid and proc_name
           		     channel_conn->conn_ops->write(channel_conn,
                             	  server_context->json_message,
                              	  server_context->message_len);

               		    port_hub->hub_ops->add_connector(port_hub,channel_conn,NULL);
            		}
	  		else if(connector_get_type(recv_conn)==CONN_CHANNEL)
	    		{
				char * buffer=malloc(65535);
		 		int offset=0;
		  		do {
		 			ret=recv_conn->conn_ops->read(recv_conn,buffer+offset,4096);
		   	 		if(ret<0)
				 		break;
			  		offset+=ret;
		    		}while(ret==4096);
	    	 		void * message;
	    	  		ret=json_2_message(buffer,&message);
		   		if(ret>=0)
		    		{
					if(message_get_state(message)==0)
						message_set_state(message,MSG_FLOW_INIT);
					set_message_head(message,"sender_uuid",local_uuid);
	    	    			sec_subject_sendmsg(sub_proc,message);	
		    		}
	    		}
		}while(1);
	}
	// send message to the remote
	while(sec_subject_recvmsg(sub_proc,&message_box)>=0)
	{
		if(message_box==NULL)
			break;
    		stroffset=message_2_json(message_box,buffer);
		if(channel_conn!=NULL)
		{
                	channel_conn->conn_ops->write(channel_conn,
                               buffer,stroffset);
			printf("json port send %d data !",stroffset);
		}	
	}

    }
    return 0;
}
Ejemplo n.º 4
0
int router_set_next_jump(void * message)
{
	int ret;
    	MSG_HEAD * msg_head;	
   	DISPATCH_POLICY * msg_policy;
	ROUTE_RULE * rule;
	char * target;
	int i;

    	if(message==NULL)
        	return -EINVAL;
    	msg_head=message_get_head(message);
		
	msg_policy=message_get_policy(message);
	if(msg_policy==NULL)
		return 0;	

	ret=dispatch_policy_getfirstrouterule(msg_policy,&rule);
	if(rule==NULL)
		return 0;
	for(i=1;i<msg_head->ljump;i++)
	{
		ret=dispatch_policy_getnextrouterule(msg_policy,&rule);		
		if(rule==NULL)
			return 0;
	}

	Memset(msg_head->receiver_uuid,0,DIGEST_SIZE);

	switch(rule->target_type)
	{
		case ROUTE_TARGET_LOCAL:
		case ROUTE_TARGET_PORT:
			ret=rule_get_target(rule,message,&target);
			if(ret<0)
				return ret;		
			Strncpy(msg_head->receiver_uuid,target,DIGEST_SIZE);
			msg_head->flag |=MSG_FLAG_LOCAL;
			Free(target);
			//message_set_state(message,MSG_FLOW_LOCAL);
			break;
		case ROUTE_TARGET_NAME:
		case ROUTE_TARGET_RECORD:
		case ROUTE_TARGET_EXPAND:
			ret=rule_get_target(rule,message,&target);
			if(ret<0)
				return ret;		
			if(Isstrinuuid(target))
			{
//				msg_head->receiver_uuid[0]='@';
				Strncpy(msg_head->receiver_uuid,target,DIGEST_SIZE/4*3);
			}
			else
			{
				Memcpy(msg_head->receiver_uuid,target,DIGEST_SIZE);
			}	
			Free(target);
			message_set_state(message,MSG_FLOW_DELIVER);
			msg_head->flag&=~MSG_FLAG_LOCAL;
//			msg_head->rjump++;
			break;
		case ROUTE_TARGET_CONN:
			ret=rule_get_target(rule,message,&target);
			if(ret<0)
				return ret;		
			Strncpy(msg_head->receiver_uuid,target,DIGEST_SIZE-1);
			Free(target);
			message_set_state(message,MSG_FLOW_DELIVER);
			msg_head->flag&=~MSG_FLAG_LOCAL;
//			msg_head->rjump++;
			break;
		default:
			return -EINVAL;
	}
	return 1;	
}