static void bearerbox_to_smsbox(void *arg) { Msg *msg, *msg_escaped; Boxc *conn = arg; while (sqlbox_status == SQL_RUNNING && conn->alive) { msg = read_from_box(conn->bearerbox_connection, conn); if (msg == NULL) { /* tell sqlbox to die */ conn->alive = 0; debug("sqlbox", 0, "bearerbox_to_smsbox: connection to bearerbox died."); break; } if (msg_type(msg) == admin) { if (msg->admin.command == cmd_shutdown || msg->admin.command == cmd_restart) { /* tell sqlbox to die */ conn->alive = 0; debug("sqlbox", 0, "bearerbox_to_smsbox: Bearerbox told us to shutdown."); break; } } if (msg_type(msg) == heartbeat) { // todo debug("sqlbox", 0, "bearerbox_to_smsbox: catch an heartbeat - we are alive"); msg_destroy(msg); continue; } if (!conn->alive) { msg_destroy(msg); break; } if (msg_type(msg) == sms) { msg_escaped = msg_duplicate(msg); if (msg->sms.sms_type != report_mo) { if (save_mo) { gw_sql_save_msg(msg_escaped, octstr_imm("MO")); } } else { if (save_dlr) { gw_sql_save_msg(msg_escaped, octstr_imm("DLR")); } } msg_destroy(msg_escaped); } send_msg(conn->smsbox_connection, conn, msg); msg_destroy(msg); } /* the client closes the connection, after that die in receiver */ conn->alive = 0; }
static void bearerbox_to_sql(void *arg) { Boxc *conn = (Boxc *)arg; Msg *msg, *mack; while (sqlbox_status == SQL_RUNNING && conn->alive) { msg = read_from_box(conn->bearerbox_connection, conn); if (msg == NULL) { /* garbage/connection lost */ /* tell sqlbox to die */ conn->alive = 0; sqlbox_status = SQL_SHUTDOWN; debug("sqlbox", 0, "bearerbox_to_sql: connection to bearerbox died."); break; } if (msg_type(msg) == heartbeat) { // todo debug("sqlbox", 0, "bearerbox_to_sql: catch an heartbeat - we are alive"); msg_destroy(msg); continue; } /* if this is an identification message from an smsbox instance */ if (msg_type(msg) == admin && msg->admin.command == cmd_shutdown) { /* tell sqlbox to die */ conn->alive = 0; sqlbox_status = SQL_SHUTDOWN; debug("sqlbox", 0, "bearerbox_to_sql: Bearerbox told us to shutdown."); break; } if (msg_type(msg) == sms) { if (msg->sms.sms_type != report_mo) { if (save_mo) { gw_sql_save_msg(msg, octstr_imm("MO")); } } else { if (save_dlr) { gw_sql_save_msg(msg, octstr_imm("DLR")); } } /* create ack message */ mack = msg_create(ack); mack->ack.nack = ack_success; mack->ack.time = msg->sms.time; uuid_copy(mack->ack.id, msg->sms.id); send_msg(conn->bearerbox_connection, conn, mack); msg_destroy(mack); } msg_destroy(msg); } }
static void smsbox_to_bearerbox(void *arg) { Boxc *conn = arg; Msg *msg, *msg_escaped; /* remove messages from socket until it is closed */ while (sqlbox_status == SQL_RUNNING && conn->alive) { //list_consume(suspended); /* block here if suspended */ msg = read_from_box(conn->smsbox_connection, conn); if (msg == NULL) { /* garbage/connection lost */ conn->alive = 0; break; } if (msg_type(msg) == sms) { debug("sqlbox", 0, "smsbox_to_bearerbox: sms received"); if (save_mt) { msg_escaped = msg_duplicate(msg); /* convert validity & deferred to minutes */ if (msg_escaped->sms.validity != SMS_PARAM_UNDEFINED) msg_escaped->sms.validity = (msg_escaped->sms.validity - time(NULL))/60; if (msg_escaped->sms.deferred != SMS_PARAM_UNDEFINED) msg_escaped->sms.deferred = (msg_escaped->sms.deferred - time(NULL))/60; gw_sql_save_msg(msg_escaped, octstr_imm("MT")); msg_destroy(msg_escaped); } } send_msg(conn->bearerbox_connection, conn, msg); /* if this is an identification message from an smsbox instance */ if (msg_type(msg) == admin && msg->admin.command == cmd_identify) { /* * any smsbox sends this command even if boxc_id is NULL, * but we will only consider real identified boxes */ if (msg->admin.boxc_id != NULL) { /* and add the boxc_id into conn for boxc_status() output */ conn->boxc_id = msg->admin.boxc_id; msg->admin.boxc_id = NULL; debug("sqlbox", 0, "smsbox_to_bearerbox: got boxc_id <%s> from <%s>", octstr_get_cstr(conn->boxc_id), octstr_get_cstr(conn->client_ip)); } } msg_destroy(msg); } conn->alive = 0; }
static void boxc_receiver(void *arg) { Boxc *conn = arg; Msg *msg, *mack; /* remove messages from socket until it is closed */ while (bb_status != BB_DEAD && conn->alive) { gwlist_consume(suspended); /* block here if suspended */ msg = read_from_box(conn); if (msg == NULL) { /* garbage/connection lost */ conn->alive = 0; break; } /* we don't accept new messages in shutdown phase */ if ((bb_status == BB_SHUTDOWN || bb_status == BB_DEAD) && msg_type(msg) == sms) { mack = msg_create(ack); uuid_copy(mack->ack.id, msg->sms.id); mack->ack.time = msg->sms.time; mack->ack.nack = ack_failed_tmp; msg_destroy(msg); send_msg(conn, mack); msg_destroy(mack); continue; } if (msg_type(msg) == sms && conn->is_wap == 0) { debug("bb.boxc", 0, "boxc_receiver: sms received"); /* deliver message to queue */ deliver_sms_to_queue(msg, conn); if (conn->routable == 0) { conn->routable = 1; /* wakeup the dequeue thread */ gwthread_wakeup(sms_dequeue_thread); } } else if (msg_type(msg) == wdp_datagram && conn->is_wap) { debug("bb.boxc", 0, "boxc_receiver: got wdp from wapbox"); /* XXX we should block these in SHUTDOWN phase too, but we need ack/nack msgs implemented first. */ gwlist_produce(conn->outgoing, msg); } else if (msg_type(msg) == sms && conn->is_wap) { debug("bb.boxc", 0, "boxc_receiver: got sms from wapbox"); /* should be a WAP push message, so tried it the same way */ deliver_sms_to_queue(msg, conn); if (conn->routable == 0) { conn->routable = 1; /* wakeup the dequeue thread */ gwthread_wakeup(sms_dequeue_thread); } } else { if (msg_type(msg) == heartbeat) { if (msg->heartbeat.load != conn->load) debug("bb.boxc", 0, "boxc_receiver: heartbeat with " "load value %ld received", msg->heartbeat.load); conn->load = msg->heartbeat.load; } else if (msg_type(msg) == ack) { if (msg->ack.nack == ack_failed_tmp) { Msg *orig; boxc_sent_pop(conn, msg, &orig); if (orig != NULL) /* retry this message */ gwlist_append(conn->retry, orig); } else { boxc_sent_pop(conn, msg, NULL); store_save(msg); } debug("bb.boxc", 0, "boxc_receiver: got ack"); } /* if this is an identification message from an smsbox instance */ else if (msg_type(msg) == admin && msg->admin.command == cmd_identify) { /* * any smsbox sends this command even if boxc_id is NULL, * but we will only consider real identified boxes */ if (msg->admin.boxc_id != NULL) { /* and add the boxc_id into conn for boxc_status() output */ if (conn->boxc_id != NULL) { dict_remove(smsbox_by_id, msg->admin.boxc_id); octstr_destroy(conn->boxc_id); } conn->boxc_id = msg->admin.boxc_id; msg->admin.boxc_id = NULL; /* add this identified smsbox to the dictionary */ /* XXX check for equal boxc_id in Dict, otherwise we overwrite it */ dict_put(smsbox_by_id, conn->boxc_id, conn); debug("bb.boxc", 0, "boxc_receiver: got boxc_id <%s> from <%s>", octstr_get_cstr(conn->boxc_id), octstr_get_cstr(conn->client_ip)); } conn->routable = 1; /* wakeup the dequeue thread */ gwthread_wakeup(sms_dequeue_thread); } else warning(0, "boxc_receiver: unknown msg received from <%s>, " "ignored", octstr_get_cstr(conn->client_ip)); msg_destroy(msg); } } }