static int _ipip_iface_send(net_iface_t * self, net_addr_t next_hop, net_msg_t * msg) { ipip_data_t * ctx= (ipip_data_t *) self->user_data; net_addr_t src_addr= ctx->src_addr; net_msg_t * outer_msg; ___ipip_debug("send msg=%m\n", msg); if (ctx->oif != NULL) { // Default IP encap source address = outgoing interface's address. if (src_addr == NET_ADDR_ANY) src_addr= ctx->oif->addr; //TO BE WRITTEN: return node_ip_output(); ... return EUNSUPPORTED; } else { outer_msg= message_create(src_addr, self->dest.end_point, NET_PROTOCOL_IPIP, 255, msg, _ipip_msg_destroy); if (msg->opts != NULL) { outer_msg->opts= ip_options_copy(msg->opts); outer_msg->opts->flags&= ~IP_OPT_ALT_DEST; } ip_opt_hook_msg_encap(self->owner, outer_msg, msg); return node_send(self->owner, outer_msg, NULL, NULL); } }
//create and then send a message int send_create_message(BIO *bio, enum message_c_ctrl ctrl, char *data1, char *data2, int data3, int data4) { struct message_client *m = message_create(ctrl, strdup(data1), strdup(data2), data3, data4); int result = send_c_message(bio, m); xdr_free((xdrproc_t) xdr_message_client, (char *)m); return result; }
void message_post_packet_in(uint8_t *data, size_t length) { message_t *message = message_create(MESSAGE_PACKET_IN); message->message.packet_out.data = data; message->message.packet_out.length = length; message_post(message); message_destroy(message); }
void game_object_append_message(game_object *obj, game_object *sender, message_callback_func callback) { struct message *mes = message_create(sender, obj, callback); message_list_SLL_APPEND(&obj->message_list, mes); }
void message_post_config_string(char *name, char *value) { message_t *message = message_create(MESSAGE_CONFIG); message->message.config.name = name; message->message.config.type = CONFIG_STRING; message->message.config.value.string_value = value; message_post(message); message_destroy(message); }
void message_post_config_int(char *name, int value) { message_t *message = message_create(MESSAGE_CONFIG); message->message.config.name = name; message->message.config.type = CONFIG_INT; message->message.config.value.int_value = value; message_post(message); message_destroy(message); }
void message_post_data_in(uint16_t session_id, uint8_t *data, size_t length) { message_t *message = message_create(MESSAGE_DATA_IN); message->message.data_in.session_id = session_id; message->message.data_in.data = data; message->message.data_in.length = length; message_post(message); message_destroy(message); }
static void sms_restore_tx_queue(struct ofono_sms *sms) { GQueue *backupq; struct txq_backup_entry *backup_entry; DBG(""); backupq = sms_tx_queue_load(sms->imsi); if (backupq == NULL) return; while ((backup_entry = g_queue_pop_head(backupq))) { struct message *m; struct tx_queue_entry *txq_entry; backup_entry->flags |= OFONO_SMS_SUBMIT_FLAG_REUSE_UUID; txq_entry = tx_queue_entry_new(backup_entry->msg_list, backup_entry->flags); if (txq_entry == NULL) goto loop_out; txq_entry->flags &= ~OFONO_SMS_SUBMIT_FLAG_REUSE_UUID; memcpy(&txq_entry->uuid.uuid, &backup_entry->uuid, SMS_MSGID_LEN); m = message_create(&txq_entry->uuid, sms->atom); if (m == NULL) { tx_queue_entry_destroy(txq_entry); goto loop_out; } if (message_dbus_register(m) == FALSE) { tx_queue_entry_destroy(txq_entry); goto loop_out; } message_set_data(m, txq_entry); g_hash_table_insert(sms->messages, &txq_entry->uuid, m); txq_entry->id = sms->tx_counter++; g_queue_push_tail(sms->txq, txq_entry); loop_out: g_slist_foreach(backup_entry->msg_list, (GFunc)g_free, NULL); g_slist_free(backup_entry->msg_list); g_free(backup_entry); } if (g_queue_get_length(sms->txq) > 0) sms->tx_source = g_timeout_add(0, tx_next, sms); g_queue_free(backupq); }
int tbus_send_signal(tbus_connection_t *connection, uint32 dest, uint32 method_id, void *data, void *para, tbusDataFree dfree, uint32 flag) { tbus_connection_t *d_connect; struct tbus_message *mess; thread_bus_t *tbus; int ret; if (unlikely(!connection)) { pppoe_log(LOG_WARNING, "input connection is NULL\n"); ret = PPPOEERR_EINVAL; goto error; } tbus = connection->tbus; if (unlikely(dest >= tbus->connection_num || dest == connection->id)) { pppoe_log(LOG_WARNING, "input dest %d is error\n", dest); ret = PPPOEERR_EINVAL; goto error; } mess = message_create(method_id, data, para, dfree); if (unlikely(!mess)) { pppoe_log(LOG_WARNING, "malloc message fail\n"); ret = PPPOEERR_ENOMEM; goto error; } mess->dest = dest; mess->source = connection->id; mess->flag |= flag; d_connect = connnection_get(tbus, dest); if (!d_connect) { pppoe_log(LOG_WARNING, "dest connection %u is not exist\n", dest); ret = PPPOEERR_ENOEXIST; goto error1; } message_queue_add(&d_connect->queue, mess); connection_put(d_connect); return PPPOEERR_SUCCESS; error1: PPPOE_FREE(mess); error: if (dfree) { dfree(data); } return ret; }
/* * Kills slave processes. */ static void kill_slaves(void) { int i; /* Loop index. */ struct message *msg; /* Message. */ msg = message_create(DIE); /* Kill slave processes. */ for (i = 0; i < nclusters; i++) message_send(outfd[i], msg); message_destroy(msg); }
static GLOBAL_FUNC(cmd_message) { struct globalMessage *message = NULL; const char *recipient = NULL; assert(argc >= 3); message = message_create(user, argc - 1, argv + 1); if(!message) return 0; recipient = messageType(message); global_notice(user, "GMSG_MESSAGE_ADDED", recipient, message->id); return 1; }
END_TEST START_TEST(test_message_encode) { message * msg; char * res; uint32_t len; msg = message_create_echo(MESSAGE_TYPE_REQUEST, "hey"); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 7); ck_assert_int_eq(memcmp(res, "\x93\x00\x01\xa3hey", len), 0); msg = message_decode("\x93\x00\x01\xa3hey", 7); ck_assert(msg != NULL); ck_assert_str_eq(msg->data.echo, "hey"); msg = message_create_echo(MESSAGE_TYPE_RESPONSE, "hey"); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 7); ck_assert_int_eq(memcmp(res, "\x93\x01\x01\xa3hey", len), 0); msg = message_decode("\x93\x01\x01\xa3hey", 7); ck_assert(msg != NULL); ck_assert_str_eq(msg->data.echo, "hey"); msg = message_create_identity(MESSAGE_TYPE_REQUEST, NULL, 0); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 4); ck_assert_int_eq(memcmp(res, "\x93\x00\x00\xc0", len), 0); msg = message_create_identity(MESSAGE_TYPE_RESPONSE, "localhost", 10000); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 17); ck_assert_int_eq(memcmp(res, "\x93\x01\x00\x92\xa9localhost\xcd'\x10", len), 0); msg = message_decode("\x93\x01\x00\x92\xa9localhost\xcd'\x10", 17); ck_assert(msg != NULL); /* ck_assert_int_eq(msg->data.identity.port , 10000); */ /* ck_assert_str_eq(msg->data.identity.name, "localhost"); */ msg = message_create(MESSAGE_TYPE_REQUEST, MESSAGE_ACTION_DISCOVER); ck_assert_int_eq(message_encode(msg, &res, &len), 0); ck_assert_int_eq(len, 4); ck_assert_int_eq(memcmp(res, "\x93\x00\x02\xc0", len), 0); msg = message_decode("\x93\x00\x02\xc0", 4); ck_assert(msg != NULL); ck_assert_int_eq(msg->type, MESSAGE_TYPE_REQUEST); ck_assert_int_eq(msg->action, MESSAGE_ACTION_DISCOVER); }
MESSAGE meta2_remote_build_request(GError **err, GByteArray *id, char *name) { MESSAGE msg=NULL; message_create(&msg, err); if (!msg) return NULL; if (id) message_set_ID (msg, id->data, id->len, err); if (name) message_set_NAME (msg, name, strlen(name), err); return msg; }
/* * set the given vbox-tone with full path (without appending) * the tone is played and after eof, a message is received */ void EndpointAppPBX::set_tone_efi(const char *tone) { struct lcr_msg *message; if (tone == NULL) tone = ""; if (!ea_endpoint->ep_portlist) { PERROR("EPOINT(%d) no portlist\n", ea_endpoint->ep_serial); } message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_VBOX_TONE); SCPY(message->param.tone.dir, (char *)"tones_efi"); SCPY(message->param.tone.name, tone); message_put(message); PDEBUG(DEBUG_EPOINT, "EPOINT(%d) terminal %s set tone '%s'\n", ea_endpoint->ep_serial, e_ext.number, tone); }
/* send play message to all members to play join/release jingle */ void JoinPBX::play_jingle(int in) { struct join_relation *relation; struct lcr_msg *message; relation = j_relation; if (!relation) return; if (!relation->next) return; while(relation) { message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE); SCPY(message->param.tone.name, (char *)((in)?"joined":"left")); message_put(message); relation = relation->next; } }
int proc_send_vm_info(void * sub_proc,void * message) { MESSAGE_HEAD * message_head; struct vm_info * vm; int retval; int ret; int count=0; int i; char local_uuid[DIGEST_SIZE*2+1]; char proc_name[DIGEST_SIZE*2+1]; 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; printf("begin vm send image info process!\n"); void * send_msg; message_head=get_message_head(message); if(message_head==NULL) return -EINVAL; // monitor send a new vm message // memset(vm,0,sizeof(struct vm_policy)); vm = NULL; send_msg=message_create("VM_I",message); if(send_msg==NULL) return -EINVAL; GetFirstPolicy(&vm,"VM_I"); while( vm != NULL) { message_add_record(send_msg,vm); GetNextPolicy(&vm,"VM_I"); } sec_subject_sendmsg(sub_proc,send_msg); return; }
static GError * _client_manage_reply_data(struct gridd_client_s *client) { gsize s = 0; MESSAGE reply = NULL; GError *err = NULL; s = client->reply->len; message_create(&reply, NULL); if (!message_unmarshall(reply, client->reply->data, &s, &err)) { g_prefix_error(&err, "Decoding error: "); (void) message_destroy(reply, NULL); return err; } err = _client_manage_reply(client, reply); (void) message_destroy(reply, NULL); return err; }
BOOL CALLBACK AnnDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { t_message *message; switch (Message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: { int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT1)); if (len > 0) { char* buf; buf = (char*)GlobalAlloc(GPTR, len + 1); GetDlgItemText(hwnd, IDC_EDIT1, buf, len + 1); if ((message = message_create(message_type_error, NULL, buf))) { message_send_all(message); message_destroy(message); } GlobalFree((HANDLE)buf); SetDlgItemText(hwnd, IDC_EDIT1, ""); } else { MessageBox(hwnd, "You didn't enter anything!", "Warning", MB_OK); } break; } } break; case WM_CLOSE: EndDialog(hwnd, IDOK); break; default: return FALSE; } return TRUE; }
int main(void) { const char * config_filename= "./router_policy.cfg"; int i,recordnum; int ret; void * record; void * message; void * recv_message; void * msg_head; int retval; struct connect_login * login_info; logic_baselib_init(); register_record_type("LOGC",&connect_login_desc,NULL); message=message_create("LOGC",NULL); for(i=0;i<3;i++) { login_info=malloc(sizeof(struct connect_login)); login_info->user=dup_str(name[i],0); login_info->passwd=dup_str(passwd[i],0); memset(login_info->nonce,'0',DIGEST_SIZE); message_add_record(message,login_info); } router_policy_init(); ret=router_read_cfg(config_filename); if(ret<0) return -EINVAL; void * msg_policy; ret=router_policy_getfirst(&msg_policy); if(ret<0) { printf("get msg policy failed!\n"); return -EINVAL; } printf("get msg policy succeed!\n"); ret=router_policy_match_message(msg_policy,message,NULL); return 0; }
int32_t _send( struct session * self, char * buf, uint32_t nbytes ) { int32_t rc = 0; if ( self->status&SESSION_EXITING ) { // 等待关闭的连接 return -1; } // 判断session是否繁忙 if ( !(self->status&SESSION_WRITING) && session_sendqueue_count(self) == 0 ) { // 直接发送 rc = channel_send( self, buf, nbytes ); if ( rc == nbytes ) { // 全部发送出去 return rc; } // 为什么发送错误没有直接终止会话呢? // 该接口有可能在ioservice_t中调用, 直接终止会话后, 会引发后续对会话的操作崩溃 } // 创建message, 添加到发送队列中 struct message * message = message_create(); if ( message == NULL ) { return -2; } message_add_buffer( message, buf+rc, nbytes-rc ); message_add_receiver( message, self->id ); QUEUE_PUSH(sendqueue)(&self->sendqueue, &message); session_add_event( self, EV_WRITE ); return rc; }
int32_t iolayer_broadcast( iolayer_t self, sid_t * ids, uint32_t count, const char * buf, uint32_t nbytes ) { uint8_t i = 0; int32_t rc = 0; pthread_t threadid = pthread_self(); struct iolayer * layer = (struct iolayer *)self; for ( i = 0; i < layer->nthreads; ++i ) { struct message * msg = message_create(); if ( unlikely(msg == NULL) ) { continue; } message_add_receivers( msg, ids, count ); message_add_buffer( msg, (char *)buf, nbytes ); if ( threadid == iothreads_get_id( layer->group, i ) ) { // 本线程内直接广播 _broadcast_direct( layer, i, _get_manager(layer, i), msg ); } else { // 跨线程提交广播任务 int32_t result = iothreads_post( layer->group, i, eIOTaskType_Broadcast, msg, 0 ); if ( unlikely(result != 0) ) { message_destroy( msg ); continue; } } rc += count; } return rc; }
int local_pubkey_request(void * sub_proc,char * user) { struct node_key_list * pub_keylist; int ret; int count; char uuidname[DIGEST_SIZE*2+16]; char proc_uuid[DIGEST_SIZE*2+1]; BYTE digest[DIGEST_SIZE]; void * sendmsg; ret=GetFirstPolicy(&pub_keylist,"NKLD"); if(ret<0) return -EINVAL; while(pub_keylist!=NULL) { if(strncmp(pub_keylist->username,user,DIGEST_SIZE)==0) { printf("user %s's pubkey is already getten!\n",user); return 0; } ret=GetNextPolicy(&pub_keylist,"NKLD"); if(ret<0) return -EINVAL; } struct key_request_cmd * key_req; key_req=malloc(sizeof(struct key_request_cmd)); if(key_req==NULL) return -ENOMEM; memset(key_req,0,sizeof(struct key_request_cmd)); strncpy(key_req->user_name,user,DIGEST_SIZE); sendmsg=message_create("KREC",NULL); message_add_record(sendmsg,key_req); sec_subject_sendmsg(sub_proc,sendmsg); }
/* * setup to exactly one endpoint * if it fails, the calling endpoint is released. * if other outgoing endpoints already exists, they are release as well. * note: if this functions fails, it will destroy its own join object! */ int JoinPBX::out_setup(unsigned int epoint_id, int message_type, union parameter *param, char *newnumber, char *newkeypad) { struct join_relation *relation; struct lcr_msg *message; class Endpoint *epoint; PDEBUG(DEBUG_JOIN, "no endpoint found, so we will create an endpoint and send the setup message we have.\n"); /* create a new relation */ if (!(relation=add_relation())) FATAL("No memory for relation.\n"); relation->type = RELATION_TYPE_SETUP; relation->channel_state = 0; /* audio is assumed on a new join */ relation->tx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */ relation->rx_state = NOTIFY_STATE_ACTIVE; /* new joins always assumed to be active */ /* create a new endpoint */ epoint = new Endpoint(0, j_serial); if (!epoint) FATAL("No memory for Endpoint instance\n"); epoint->ep_app = new_endpointapp(epoint, 1, EAPP_TYPE_PBX); // outgoing relation->epoint_id = epoint->ep_serial; /* send setup message to new endpoint */ //printf("JOLLY DEBUG: %d\n",join_countrelations(j_serial)); //i if (options.deb & DEBUG_JOIN) // joinpbx_debug(join, "Join::message_epoint"); message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(union parameter)); if (newnumber) SCPY(message->param.setup.dialinginfo.id, newnumber); else message->param.setup.dialinginfo.id[0] = '\0'; if (newkeypad) SCPY(message->param.setup.dialinginfo.keypad, newkeypad); else message->param.setup.dialinginfo.keypad[0] = '\0'; PDEBUG(DEBUG_JOIN, "setup message sent to ep %d with number='%s' keypad='%s'.\n", relation->epoint_id, message->param.setup.dialinginfo.id, message->param.setup.dialinginfo.keypad); message_put(message); return(0); }
void JoinRemote::message_remote(int message_type, union parameter *param) { struct lcr_msg *message; PDEBUG(DEBUG_JOIN, "Message %d of endpoint %d from remote to LCR (ref=%d)\n", message_type, j_epoint_id, j_remote_ref); /* create relation if no relation exists */ if (!j_epoint_id) { class Endpoint *epoint; if (!(epoint = new Endpoint(0, j_serial))) FATAL("No memory for Endpoint instance\n"); j_epoint_id = epoint->ep_serial; PDEBUG(DEBUG_JOIN, "Created endpoint %d\n", j_epoint_id); epoint->ep_app = new_endpointapp(epoint, 1, EAPP_TYPE_PBX); // outgoing } #ifdef WITH_MISDN /* set serial on bchannel message * also ref is given, so we send message with ref */ if (message_type == MESSAGE_BCHANNEL) { message_bchannel_from_remote(this, param->bchannel.type, param->bchannel.handle); return; } #endif /* cannot just forward, because param is not of container "struct lcr_msg" */ message = message_create(j_serial, j_epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(message->param)); message_put(message); if (message_type == MESSAGE_RELEASE) { delete this; return; } }
int main(int argc, char** argv) { int result; (void)argc, argv; amqpalloc_set_memory_tracing_enabled(true); if (platform_init() != 0) { result = -1; } else { XIO_HANDLE sasl_io; CONNECTION_HANDLE connection; SESSION_HANDLE session; LINK_HANDLE link; MESSAGE_SENDER_HANDLE message_sender; MESSAGE_HANDLE message; size_t last_memory_used = 0; /* create SASL PLAIN handler */ SASL_PLAIN_CONFIG sasl_plain_config = { EH_KEY_NAME, EH_KEY, NULL }; SASL_MECHANISM_HANDLE sasl_mechanism_handle = saslmechanism_create(saslplain_get_interface(), &sasl_plain_config); XIO_HANDLE tls_io; /* create the TLS IO */ TLSIO_CONFIG tls_io_config = { EH_HOST, 5671 }; const IO_INTERFACE_DESCRIPTION* tlsio_interface = platform_get_default_tlsio(); tls_io = xio_create(tlsio_interface, &tls_io_config); /* create the SASL client IO using the TLS IO */ SASLCLIENTIO_CONFIG sasl_io_config; sasl_io_config.underlying_io = tls_io; sasl_io_config.sasl_mechanism = sasl_mechanism_handle; sasl_io = xio_create(saslclientio_get_interface_description(), &sasl_io_config); /* create the connection, session and link */ connection = connection_create(sasl_io, EH_HOST, "some", NULL, NULL); session = session_create(connection, NULL, NULL); session_set_incoming_window(session, 2147483647); session_set_outgoing_window(session, 65536); AMQP_VALUE source = messaging_create_source("ingress"); AMQP_VALUE target = messaging_create_target("amqps://" EH_HOST "/" EH_NAME); link = link_create(session, "sender-link", role_sender, source, target); link_set_snd_settle_mode(link, sender_settle_mode_unsettled); (void)link_set_max_message_size(link, 65536); amqpvalue_destroy(source); amqpvalue_destroy(target); message = message_create(); unsigned char hello[] = { 'H', 'e', 'l', 'l', 'o' }; BINARY_DATA binary_data; binary_data.bytes = hello; binary_data.length = sizeof(hello); message_add_body_amqp_data(message, binary_data); /* create a message sender */ message_sender = messagesender_create(link, NULL, NULL); if (messagesender_open(message_sender) == 0) { uint32_t i; #if _WIN32 unsigned long startTime = (unsigned long)GetTickCount64(); #endif for (i = 0; i < msg_count; i++) { (void)messagesender_send(message_sender, message, on_message_send_complete, message); } message_destroy(message); while (true) { size_t current_memory_used; size_t maximum_memory_used; connection_dowork(connection); current_memory_used = amqpalloc_get_current_memory_used(); maximum_memory_used = amqpalloc_get_maximum_memory_used(); if (current_memory_used != last_memory_used) { (void)printf("Current memory usage:%lu (max:%lu)\r\n", (unsigned long)current_memory_used, (unsigned long)maximum_memory_used); last_memory_used = current_memory_used; } if (sent_messages == msg_count) { break; } } #if _WIN32 unsigned long endTime = (unsigned long)GetTickCount64(); (void)printf("Send %zu messages in %lu ms: %.02f msgs/sec\r\n", msg_count, (endTime - startTime), (float)msg_count / ((float)(endTime - startTime) / 1000)); #endif } messagesender_destroy(message_sender); link_destroy(link); session_destroy(session); connection_destroy(connection); xio_destroy(sasl_io); xio_destroy(tls_io); saslmechanism_destroy(sasl_mechanism_handle); platform_deinit(); (void)printf("Max memory usage:%lu\r\n", (unsigned long)amqpalloc_get_maximum_memory_used()); (void)printf("Current memory usage:%lu\r\n", (unsigned long)amqpalloc_get_current_memory_used()); result = 0; } #ifdef _CRTDBG_MAP_ALLOC _CrtDumpMemoryLeaks(); #endif return result; }
int __ofono_sms_txq_submit(struct ofono_sms *sms, GSList *list, unsigned int flags, struct ofono_uuid *uuid, ofono_sms_txq_queued_cb_t cb, void *data) { struct message *m = NULL; struct tx_queue_entry *entry; entry = tx_queue_entry_new(list, flags); if (entry == NULL) return -ENOMEM; if (flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) { m = message_create(&entry->uuid, sms->atom); if (m == NULL) goto err; if (message_dbus_register(m) == FALSE) goto err; message_set_data(m, entry); g_hash_table_insert(sms->messages, &entry->uuid, m); } if (list->next != NULL) { if (sms->ref == 65536) sms->ref = 1; else sms->ref = sms->ref + 1; } entry->id = sms->tx_counter++; g_queue_push_tail(sms->txq, entry); if (sms->registered && g_queue_get_length(sms->txq) == 1) sms->tx_source = g_timeout_add(0, tx_next, sms); if (uuid) memcpy(uuid, &entry->uuid, sizeof(*uuid)); if (flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) { const char *uuid_str; unsigned char i; uuid_str = ofono_uuid_to_str(&entry->uuid); for (i = 0; i < entry->num_pdus; i++) { struct pending_pdu *pdu; pdu = &entry->pdus[i]; sms_tx_backup_store(sms->imsi, entry->id, entry->flags, uuid_str, i, pdu->pdu, pdu->pdu_len, pdu->tpdu_len); } } if (cb) cb(sms, &entry->uuid, data); if (m && (flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS)) message_emit_added(m, OFONO_MESSAGE_MANAGER_INTERFACE); return 0; err: tx_queue_entry_destroy(entry); return -EINVAL; }
int tbus_send_method_call_with_reply(tbus_connection_t *connection, uint32 dest, uint32 method_id, void *data, void *para, tbusDataFree dfree, uint32 flag, uint32 timeout) { tbus_connection_t *d_connect; struct tbus_message *mess; thread_bus_t *tbus; int ret; if (unlikely(!connection)) { pppoe_log(LOG_WARNING, "input connection is NULL\n"); ret = PPPOEERR_EINVAL; goto error; } tbus = connection->tbus; if (unlikely(dest >= tbus->connection_num || dest == connection->id)) { pppoe_log(LOG_WARNING, "input dest %d is error\n", dest); ret = PPPOEERR_EINVAL; goto error; } mess = message_create(method_id, data, para, dfree); if (unlikely(!mess)) { pppoe_log(LOG_WARNING, "malloc message fail\n"); ret = PPPOEERR_ENOMEM; goto error; } mess->dest = dest; mess->source = connection->id; mess->flag |= (flag | TBUS_FLAG_REPLY); d_connect = connnection_get(tbus, dest); if (!d_connect) { pppoe_log(LOG_WARNING, "dest connection %u is not exist\n", dest); ret = PPPOEERR_ENOEXIST; goto error1; } message_queue_add(&d_connect->queue, mess); ret = message_queue_reply_wait(&connection->queue, mess, timeout); if (ret) { pppoe_log(LOG_WARNING, "get reply failed, ret %d\n", ret); } else { ret = mess->errcode; if (mess->free) { mess->free(mess->data); } PPPOE_FREE(mess); } connection_put(d_connect); return ret; error1: PPPOE_FREE(mess); error: if (dfree) { dfree(data); } return ret; }
int proc_tcm_makeidentity(void * sub_proc,void * recv_msg) { int ret=0; int fd; BYTE local_uuid[DIGEST_SIZE]; BYTE Buf[DIGEST_SIZE*32]; BYTE NameBuf[DIGEST_SIZE*4]; UINT32 result; RECORD(TCM_PIK_DESC,USERINFO) * pik_userinfo; RECORD(MESSAGE,SIZED_BINDATA) req_blob; RECORD(VTCM_IN_KEY,TCM_BIN_KEY) tcm_pik; RECORD(VTCM_IN_KEY,TCM_BIN_PUBKEY) tcm_pikpub; RECORD(TCM_KEY_MANAGE,PRIVATE_KEY) tcm_pik_info; void * new_msg; int key_len; void * tcm_key_template; UINT32 smkHandle; UINT32 ownerHandle; UINT32 keyHandle; UINT32 keyAuthHandle; char uuid[DIGEST_SIZE*2+1]; DB_RECORD * db_record; printf("begin pik makeidentity!\n"); // get pik_userinfo from message ret=message_get_record(recv_msg,&pik_userinfo,0); if(ret<0) return -EINVAL; if(pik_userinfo==NULL) return -EINVAL; // get this node's machine uuid ret=proc_share_data_getvalue("uuid",pik_userinfo->node_uuid); if(ret<0) return ret; // get this node's hostname ret=gethostname(pik_userinfo->node_name,DIGEST_SIZE); if(ret!=0) Memset(pik_userinfo->node_name,0,DIGEST_SIZE); // build tcm session ret=TCM_APCreate(TCM_ET_OWNER, NULL, "ooo", &ownerHandle); printf("ownerHandle is : %x\n",ownerHandle); if(ret<0) { print_cubeerr("TCM_APCreate failed!\n"); return -EINVAL; } ret=TCM_APCreate(TCM_ET_SMK, NULL, "sss", &smkHandle); printf("smkHandle is : %x\n",smkHandle); if(ret<0) { printf("TCM_APCreate failed!\n"); return -EINVAL; } int userinfolen; BYTE * req; int reqlen; // get userinfo blob tcm_key_template=memdb_get_template(TYPE_PAIR(TCM_PIK_DESC,USERINFO)); if(tcm_key_template==NULL) return -EINVAL; userinfolen=struct_2_blob(pik_userinfo,Buf,tcm_key_template); if(userinfolen<0) return userinfolen; db_record=memdb_store(pik_userinfo,TYPE_PAIR(TCM_PIK_DESC,USERINFO),NULL); if(db_record==NULL) return -EINVAL; // do makeidentity ret = TCM_MakeIdentity(ownerHandle, smkHandle, userinfolen,Buf,"kkk", &tcm_pik, &req, &reqlen); if(ret<0) { print_cubeerr("TCM_MakeIdentity failed!\n"); return -EINVAL; } // build an expand message record for req data req_blob.size=reqlen; req_blob.bindata=req; // terminate session ret=TCM_APTerminate(ownerHandle); if(ret<0) { print_cubeerr("TCM_APTerminate failed!\n"); return -EINVAL; } ret=TCM_APTerminate(smkHandle); if(ret<0) { print_cubeerr("TCM_APTerminate failed!\n"); return -EINVAL; } // generate TCM pik info ,left pubkey_uuid for fill tcm_key_template=memdb_get_template(TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_KEY)); if(tcm_key_template==NULL) return -EINVAL; key_len=struct_2_blob(&tcm_pik,Buf,tcm_key_template); if(key_len<0) return key_len; Memset(&tcm_pik_info,0,sizeof(tcm_pik_info)); calculate_context_sm3(Buf,key_len,tcm_pik_info.uuid); Memcpy(tcm_pik_info.vtcm_uuid,local_uuid,DIGEST_SIZE); tcm_pik_info.issmkwrapped=1; tcm_pik_info.key_usage=TCM_KEY_IDENTITY; tcm_pik_info.key_flags=TCM_ISVOLATILE|TCM_PCRIGNOREDONREAD; // store pik file digest_to_uuid(tcm_pik_info.uuid,uuid); uuid[DIGEST_SIZE*2]=0; printf("get pik's uuid is %s!\n",uuid); Strcpy(NameBuf,"tcmkey/"); Strcat(NameBuf,uuid); fd=open(NameBuf,O_CREAT|O_WRONLY,0666); if(fd<0) return fd; write(fd,Buf,key_len); close(fd); // Get pikpub from pik // ret=TCM_ExGetPubkeyFromTcmkey(&tcm_pikpub,&tcm_pik); if(ret!=0) { print_cubeerr("Get Pubpik failed!\n"); return -EINVAL; } tcm_key_template=memdb_get_template(TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_PUBKEY)); if(tcm_key_template==NULL) return -EINVAL; key_len=struct_2_blob(&tcm_pikpub,Buf,tcm_key_template); if(key_len<0) return key_len; calculate_context_sm3(Buf,key_len,tcm_pik_info.pubkey_uuid); db_record=memdb_store(&tcm_pik_info,TYPE_PAIR(TCM_KEY_MANAGE,PRIVATE_KEY),NULL); // build a message and send it new_msg=message_create(TYPE_PAIR(TCM_PIK_DESC,USERINFO),recv_msg); if(new_msg==NULL) return -EINVAL; ret=message_add_record(new_msg,pik_userinfo); if(ret<0) return ret; ret=message_add_expand_data(new_msg,TYPE_PAIR(MESSAGE,SIZED_BINDATA),&req_blob); if(ret<0) return -EINVAL; ret=message_add_expand_data(new_msg,TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_PUBKEY),&tcm_pikpub); if(ret<0) return -EINVAL; ret=ex_module_sendmsg(sub_proc,new_msg); return ret; }
int proc_tcm_activateidentity(void * sub_proc,void * recv_msg) { int ret=0; int fd; BYTE Buf[DIGEST_SIZE*32]; BYTE NameBuf[DIGEST_SIZE*4]; BYTE KeyBuf[DIGEST_SIZE*4]; BYTE digest[DIGEST_SIZE]; UINT32 result; DB_RECORD * db_record; RECORD(TCM_PIK_DESC,USERINFO) * pik_userinfo; RECORD(TCM_PIK_DESC,CADATA) * pik_cadata; RECORD(TCM_PIK_DESC,PIKCERT) * pik_cert; RECORD(VTCM_IN_KEY,TCM_BIN_KEY) tcm_pik; RECORD(VTCM_IN_KEY,TCM_BIN_PUBKEY) tcm_pikpub; RECORD(TCM_KEY_MANAGE,PRIVATE_KEY) * tcm_pik_info; TCM_SYMMETRIC_KEY symmkey; void * new_msg; int key_len; void * tcm_key_template; UINT32 smkHandle; UINT32 ownerHandle; UINT32 keyHandle; UINT32 keyAuthHandle; char uuid[DIGEST_SIZE*2+1]; printf("begin pik activateidentity!\n"); // get pik cadata from message ret=message_get_record(recv_msg,&pik_cadata,0); if(ret<0) return -EINVAL; if(pik_cadata==NULL) return -EINVAL; // find pikinfo record db_record=memdb_find_first(TYPE_PAIR(TCM_KEY_MANAGE,PRIVATE_KEY),"pubkey_uuid",pik_cadata->pikpub_uuid); if(db_record==NULL) { print_cubeerr("can't find pik record!\n"); return -EINVAL; } tcm_pik_info=db_record->record; // get pik file name digest_to_uuid(tcm_pik_info->uuid,uuid); uuid[DIGEST_SIZE*2]=0; printf("get pik's uuid is %s!\n",uuid); Strcpy(NameBuf,"tcmkey/"); Strcat(NameBuf,uuid); ret=TCM_ExLoadTcmKey(&tcm_pik,NameBuf); if(ret!=0) { print_cubeerr("Load TCMKey from file failed!\n"); return ret; } // Load pik to TCM ret=TCM_APCreate(TCM_ET_SMK, NULL, "sss", &smkHandle); printf("smkHandle is : %x\n",smkHandle); if(ret<0) { printf("TCM_APCreate failed!\n"); return -EINVAL; } ret=TCM_LoadKey(smkHandle,NameBuf,&keyHandle); if(ret!=0) { print_cubeerr("TCM_LoadKey failed!\n"); return ret; } ret=TCM_APTerminate(smkHandle); if(ret!=0) { printf("TCM_APTerminate failed!\n"); return ret; } // do the activateidentity ret=TCM_APCreate(TCM_ET_OWNER, NULL, "ooo", &ownerHandle); printf("ownerHandle is : %x\n",ownerHandle); if(ret<0) { print_cubeerr("TCM_APCreate failed!\n"); return -EINVAL; } ret=TCM_APCreate(TCM_ET_KEYHANDLE,keyHandle, "kkk", &keyAuthHandle); printf("pikHandle is : %x\n",keyAuthHandle); if(ret!=0) { printf("TCM_APCreate failed!\n"); return -EINVAL; } ret=TCM_ActivateIdentity(keyHandle,keyAuthHandle,ownerHandle, pik_cadata->symmkey_len,pik_cadata->symmkey,&symmkey,"ooo","kkk"); if(ret!=0) { printf("TCM_ActivateIdentity failed!\n"); return -EINVAL; } ret=TCM_APTerminate(ownerHandle); if(ret<0) { printf("TCM_APTerminate failed!\n"); return -EINVAL; } ret=TCM_APTerminate(keyAuthHandle); if(ret<0) { printf("TCM_APTerminate failed!\n"); return -EINVAL; } ret=TCM_EvictKey(keyHandle); if(ret<0) { printf("TCM_APTerminate failed!\n"); return -EINVAL; } // decrypt cert blob int blobsize; BYTE * cert; int certsize; ret=TCM_ExSymmkeyDecrypt(&symmkey,pik_cadata->cert,pik_cadata->certlen,&cert,&certsize); if(ret!=0) { printf("decrypt cert blob file error!\n"); return -EINVAL; } int offset; for(offset=0;cert[offset]==0;offset++) { if((offset>=16)|| (offset>=certsize)) { print_cubeerr("cert data failed!\n"); return -EINVAL; } } // build pik cert, it is organized by userinfo, pubkey and ca_conts // pik_cert=Talloc0(sizeof(*pik_cert)); if(pik_cert==NULL) return -ENOMEM; tcm_key_template=memdb_get_template(TYPE_PAIR(TCM_PIK_DESC,VERIFYDATA)); if(tcm_key_template==NULL) return -EINVAL; ret=blob_2_struct(cert+offset,&pik_cert->verifydata,tcm_key_template); if(ret<0) return -EINVAL; db_record=memdb_find(pik_cadata->userinfo_uuid,TYPE_PAIR(TCM_PIK_DESC,USERINFO)); if(db_record==NULL) { print_cubeerr("can't find user info data!\n"); return -EINVAL; } pik_userinfo=db_record->record; tcm_key_template=memdb_get_template(TYPE_PAIR(TCM_PIK_DESC,USERINFO)); if(tcm_key_template==NULL) return -EINVAL; ret=struct_clone(pik_userinfo,&pik_cert->userinfo,tcm_key_template); if(ret<0) return -EINVAL; ret=TCM_ExGetPubkeyFromTcmkey(&tcm_pikpub,&tcm_pik); if(ret!=0) { print_cubeerr("Get Pubpik failed!\n"); return -EINVAL; } tcm_key_template=memdb_get_template(TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_PUBKEY)); if(tcm_key_template==NULL) return -EINVAL; ret=struct_clone(&tcm_pikpub,&pik_cert->pikpub,tcm_key_template); if(ret<0) return -EINVAL; // build a message and send it new_msg=message_create(TYPE_PAIR(TCM_PIK_DESC,PIKCERT),recv_msg); if(new_msg==NULL) return -EINVAL; ret=message_add_record(new_msg,pik_cert); if(ret<0) return ret; ret=ex_module_sendmsg(sub_proc,new_msg); return ret; }
/* epoint sends a message to a join * */ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union parameter *param) { class Join *cl; struct join_relation *relation, *reltemp; int num; int new_state; struct lcr_msg *message; // int size, writesize, oldpointer; char *number, *numbers; if (!epoint_id) { PERROR("software error, epoint == NULL\n"); return; } // if (options.deb & DEBUG_JOIN) { // PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial); // joinpbx_debug(join,"Join::message_epoint"); // } if (options.deb & DEBUG_JOIN) { if (message_type) { cl = join_first; while(cl) { if (cl->j_type == JOIN_TYPE_PBX) joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}"); cl = cl->next; } } } /* check relation */ relation = j_relation; while(relation) { if (relation->epoint_id == epoint_id) break; relation = relation->next; } if (!relation) { PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id); return; } /* count relations */ num=joinpbx_countrelations(j_serial); /* process party line */ if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) { j_partyline = param->setup.partyline; j_partyline_jingle = param->setup.partyline_jingle; } if (j_partyline) { switch(message_type) { case MESSAGE_SETUP: PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n"); relation->type = RELATION_TYPE_CONNECT; message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT); SPRINT(message->param.connectinfo.id, "%d", j_partyline); message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN; message_put(message); trigger_work(&j_updatebridge); if (j_partyline_jingle) play_jingle(1); break; case MESSAGE_AUDIOPATH: PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath); if (relation->channel_state != param->audiopath) { relation->channel_state = param->audiopath; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new channel state}"); } break; /* track notify */ case MESSAGE_NOTIFY: switch(param->notifyinfo.notify) { case INFO_NOTIFY_USER_SUSPENDED: case INFO_NOTIFY_USER_RESUMED: case INFO_NOTIFY_REMOTE_HOLD: case INFO_NOTIFY_REMOTE_RETRIEVAL: case INFO_NOTIFY_CONFERENCE_ESTABLISHED: case INFO_NOTIFY_CONFERENCE_DISCONNECTED: new_state = track_notify(relation->rx_state, param->notifyinfo.notify); if (new_state != relation->rx_state) { relation->rx_state = new_state; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new rx state}"); } break; } break; case MESSAGE_DISCONNECT: PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n"); message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE); message->param.disconnectinfo.cause = CAUSE_NORMAL; message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); // fall through case MESSAGE_RELEASE: PDEBUG(DEBUG_JOIN, "releasing from join\n"); release(relation, 0, 0); if (j_partyline_jingle) play_jingle(0); break; default: PDEBUG(DEBUG_JOIN, "ignoring message, because join in partyline mode.\n"); } return; } /* process messages */ switch(message_type) { /* process audio path message */ case MESSAGE_AUDIOPATH: PDEBUG(DEBUG_JOIN, "join received channel message: audiopath=%d, current relation's channel_state=%d\n", param->audiopath, relation->channel_state); if (relation->channel_state != param->audiopath) { relation->channel_state = param->audiopath; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new channel state}"); } return; /* track notify */ case MESSAGE_NOTIFY: switch(param->notifyinfo.notify) { case INFO_NOTIFY_USER_SUSPENDED: case INFO_NOTIFY_USER_RESUMED: case INFO_NOTIFY_REMOTE_HOLD: case INFO_NOTIFY_REMOTE_RETRIEVAL: case INFO_NOTIFY_CONFERENCE_ESTABLISHED: case INFO_NOTIFY_CONFERENCE_DISCONNECTED: new_state = track_notify(relation->rx_state, param->notifyinfo.notify); if (new_state != relation->rx_state) { relation->rx_state = new_state; trigger_work(&j_updatebridge); if (options.deb & DEBUG_JOIN) joinpbx_debug(this, "Join::message_epoint{after setting new rx state}"); } break; default: /* send notification to all other endpoints */ reltemp = j_relation; while(reltemp) { if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id) { message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY); memcpy(&message->param, param, sizeof(union parameter)); message_put(message); } reltemp = reltemp->next; } } return; /* relations sends a connect */ case MESSAGE_CONNECT: /* outgoing setup type becomes connected */ if (relation->type == RELATION_TYPE_SETUP) relation->type = RELATION_TYPE_CONNECT; /* release other relations in setup state */ release_again: reltemp = j_relation; while(reltemp) { //printf("connect, checking relation %d\n", reltemp->epoint_id); if (reltemp->type == RELATION_TYPE_SETUP) { //printf("relation %d is of type setup, releasing\n", reltemp->epoint_id); /* send release to endpoint */ message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE); message->param.disconnectinfo.cause = CAUSE_NONSELECTED; message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; message_put(message); if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) // dummy cause, should not be used, since calling and connected endpoint still exist afterwards. return; // must return, because join IS destroyed goto release_again; } if (reltemp->type == RELATION_TYPE_CALLING) reltemp->type = RELATION_TYPE_CONNECT; reltemp = reltemp->next; } break; // continue with our message /* release is sent by endpoint */ case MESSAGE_RELEASE: switch(relation->type) { case RELATION_TYPE_SETUP: /* by called */ /* collect cause and send collected cause */ collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location); if (j_multicause) release(relation, j_multilocation, j_multicause); else release(relation, LOCATION_PRIVATE_LOCAL, CAUSE_UNSPECIFIED); break; case RELATION_TYPE_CALLING: /* by calling */ /* remove us, if we don't have a called releation yet */ if (!j_relation->next) { release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL); return; // must return, because join IS destroyed } /* in a conf, we don't kill the other members */ if (num > 2 && !joinpbx_onecalling_othersetup(j_relation)) { release(relation, 0, 0); return; } /* remove all relations that are of called type */ release_again2: reltemp = j_relation; while(reltemp) { if (reltemp->type == RELATION_TYPE_SETUP) { /* send release to endpoint */ message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(union parameter)); message_put(message); if (release(reltemp, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL)) return; // must return, because join IS destroyed goto release_again2; } reltemp = reltemp->next; } PERROR("we are still here, this should not happen\n"); break; default: /* by connected */ /* send current cause */ release(relation, param->disconnectinfo.location, param->disconnectinfo.cause); } return; // must return, because join may be destroyed } /* check number of relations */ if (num > 2 && !joinpbx_onecalling_othersetup(j_relation) && message_type != MESSAGE_CONNECT) { PDEBUG(DEBUG_JOIN, "we are in a conference, so we ignore the messages, except MESSAGE_CONNECT.\n"); return; } /* if join has no other relation, we process the setup message */ if (num == 1) { switch(message_type) { case MESSAGE_SETUP: if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION) { /* in case of keypad */ numbers = param->setup.dialinginfo.keypad; if (numbers[0]) { while((number = strsep(&numbers, ","))) { if (out_setup(epoint_id, message_type, param, NULL, number)) return; // join destroyed } /* after keypad finish dialing */ break; } /* dialed number */ numbers = param->setup.dialinginfo.id; while((number = strsep(&numbers, ","))) { if (out_setup(epoint_id, message_type, param, number, NULL)) return; // join destroyed } break; } if (out_setup(epoint_id, message_type, param, param->setup.dialinginfo.id, param->setup.dialinginfo.keypad)) return; // join destroyed break; default: PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n"); } } else { /* sending message to other relation(s) */ relation = j_relation; while(relation) { if (relation->epoint_id != epoint_id) { PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id); message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type); memcpy(&message->param, param, sizeof(union parameter)); message_put(message); PDEBUG(DEBUG_JOIN, "message sent.\n"); } relation = relation->next; } } }