📄 smscconn.c
字号:
* we must unlock here, because module manipulate their state * and will try to lock this mutex.Otherwise we have deadlock! */ mutex_unlock(conn->flow_mutex); conn->shutdown(conn, finish_sending); } else { conn->why_killed = SMSCCONN_KILLED_SHUTDOWN; mutex_unlock(conn->flow_mutex); } return;}int smscconn_destroy(SMSCConn *conn){ if (conn == NULL) return 0; if (conn->status != SMSCCONN_DEAD) return -1; mutex_lock(conn->flow_mutex); counter_destroy(conn->received); counter_destroy(conn->sent); counter_destroy(conn->failed); octstr_destroy(conn->name); octstr_destroy(conn->id); list_destroy(conn->allowed_smsc_id, octstr_destroy_item); list_destroy(conn->denied_smsc_id, octstr_destroy_item); list_destroy(conn->preferred_smsc_id, octstr_destroy_item); octstr_destroy(conn->denied_prefix); octstr_destroy(conn->allowed_prefix); octstr_destroy(conn->preferred_prefix); octstr_destroy(conn->unified_prefix); octstr_destroy(conn->our_host); octstr_destroy(conn->log_file); if (conn->denied_smsc_id_regex != NULL) gw_regex_destroy(conn->denied_smsc_id_regex); if (conn->allowed_smsc_id_regex != NULL) gw_regex_destroy(conn->allowed_smsc_id_regex); if (conn->preferred_prefix_regex != NULL) gw_regex_destroy(conn->preferred_prefix_regex); if (conn->denied_prefix_regex != NULL) gw_regex_destroy(conn->denied_prefix_regex); if (conn->allowed_prefix_regex != NULL) gw_regex_destroy(conn->allowed_prefix_regex); octstr_destroy(conn->reroute_to_smsc); dict_destroy(conn->reroute_by_receiver); mutex_unlock(conn->flow_mutex); mutex_destroy(conn->flow_mutex); gw_free(conn); return 0;}int smscconn_stop(SMSCConn *conn){ gw_assert(conn != NULL); mutex_lock(conn->flow_mutex); if (conn->status == SMSCCONN_DEAD || conn->is_stopped != 0 || conn->why_killed != SMSCCONN_ALIVE) { mutex_unlock(conn->flow_mutex); return -1; } conn->is_stopped = 1; mutex_unlock(conn->flow_mutex); if (conn->stop_conn) conn->stop_conn(conn); return 0;}void smscconn_start(SMSCConn *conn){ gw_assert(conn != NULL); mutex_lock(conn->flow_mutex); if (conn->status == SMSCCONN_DEAD || conn->is_stopped == 0) { mutex_unlock(conn->flow_mutex); return; } conn->is_stopped = 0; mutex_unlock(conn->flow_mutex); if (conn->start_conn) conn->start_conn(conn);}const Octstr *smscconn_name(SMSCConn *conn){ gw_assert(conn != NULL); return conn->name;}const Octstr *smscconn_id(SMSCConn *conn){ gw_assert(conn != NULL); return conn->id;}int smscconn_usable(SMSCConn *conn, Msg *msg){ gw_assert(conn != NULL); gw_assert(msg != NULL && msg_type(msg) == sms); if (conn->status == SMSCCONN_DEAD || conn->why_killed != SMSCCONN_ALIVE) return -1; /* if allowed-smsc-id set, then only allow this SMSC if message * smsc-id matches any of its allowed SMSCes */ if (conn->allowed_smsc_id && (msg->sms.smsc_id == NULL || list_search(conn->allowed_smsc_id, msg->sms.smsc_id, octstr_item_match) == NULL)) { return -1; } /* ..if no allowed-smsc-id set but denied-smsc-id and message smsc-id * is set, deny message if smsc-ids match */ else if (conn->denied_smsc_id && msg->sms.smsc_id != NULL && list_search(conn->denied_smsc_id, msg->sms.smsc_id, octstr_item_match) != NULL) { return -1; } if (conn->allowed_smsc_id_regex) { if (msg->sms.smsc_id == NULL) return -1; if (gw_regex_matches(conn->allowed_smsc_id_regex, msg->sms.smsc_id) == NO_MATCH) return -1; } else if (conn->denied_smsc_id_regex && msg->sms.smsc_id != NULL) { if (gw_regex_matches(conn->denied_smsc_id_regex, msg->sms.smsc_id) == MATCH) return -1; } /* Have allowed */ if (conn->allowed_prefix && ! conn->denied_prefix && (does_prefix_match(conn->allowed_prefix, msg->sms.receiver) != 1)) return -1; if (conn->allowed_prefix_regex && ! conn->denied_prefix_regex) { if (gw_regex_matches(conn->allowed_prefix_regex, msg->sms.receiver) == NO_MATCH) return -1; } /* Have denied */ if (conn->denied_prefix && ! conn->allowed_prefix && (does_prefix_match(conn->denied_prefix, msg->sms.receiver) == 1)) return -1; if (conn->denied_prefix_regex && ! conn->allowed_prefix_regex) { if (gw_regex_matches(conn->denied_prefix_regex, msg->sms.receiver) == MATCH) return -1; } /* Have allowed and denied */ if (conn->denied_prefix && conn->allowed_prefix && (does_prefix_match(conn->allowed_prefix, msg->sms.receiver) != 1) && (does_prefix_match(conn->denied_prefix, msg->sms.receiver) == 1) ) return -1; if (conn->allowed_prefix_regex && conn->denied_prefix_regex) { if ((gw_regex_matches(conn->allowed_prefix_regex, msg->sms.receiver) == NO_MATCH) && (gw_regex_matches(conn->denied_prefix_regex, msg->sms.receiver) == MATCH)) return -1; } /* then see if it is preferred one */ if (conn->preferred_smsc_id && msg->sms.smsc_id != NULL && list_search(conn->preferred_smsc_id, msg->sms.smsc_id, octstr_item_match) != NULL) { return 1; } if (conn->preferred_prefix) if (does_prefix_match(conn->preferred_prefix, msg->sms.receiver) == 1) return 1; if (conn->preferred_prefix_regex) { if (gw_regex_matches(conn->preferred_prefix_regex, msg->sms.receiver) == MATCH) return 1; } return 0;}int smscconn_send(SMSCConn *conn, Msg *msg){ int ret = -1; List *parts = NULL; gw_assert(conn != NULL); mutex_lock(conn->flow_mutex); if (conn->status == SMSCCONN_DEAD || conn->why_killed != SMSCCONN_ALIVE) { mutex_unlock(conn->flow_mutex); return -1; } /* if this a retry of splitted message, don't unify prefix and don't try to split */ if (msg->sms.split_parts == NULL) { /* normalize the destination number for this smsc */ char *uf = conn->unified_prefix ? octstr_get_cstr(conn->unified_prefix) : NULL; normalize_number(uf, &(msg->sms.receiver)); /* split msg */ parts = sms_split(msg, NULL, NULL, NULL, NULL, 1, counter_increase(split_msg_counter) & 0xff, 0xff, MAX_SMS_OCTETS); if (list_len(parts) == 1) { /* don't create split_parts of sms fit into one */ list_destroy(parts, msg_destroy_item); parts = NULL; } } if (parts == NULL) ret = conn->send_msg(conn, msg); else { long i, parts_len = list_len(parts); struct split_parts *split = gw_malloc(sizeof(*split)); /* must duplicate, because smsc2_route will destroy this msg */ split->orig = msg_duplicate(msg); split->parts_left = counter_create(); split->status = SMSCCONN_SUCCESS; counter_set(split->parts_left, parts_len); debug("bb.sms.splits", 0, "new split_parts created %p", split); for (i = 0; i < parts_len; i++) { msg = list_get(parts, i); msg->sms.split_parts = split; ret = conn->send_msg(conn, msg); if (ret < 0) { if (i == 0) { counter_destroy(split->parts_left); list_destroy(parts, msg_destroy_item); gw_free(split); mutex_unlock(conn->flow_mutex); return ret; } /* * Some parts were sent. So handle this within * bb_smscconn_XXX(). */ split->status = SMSCCONN_FAILED_REJECTED; while (++i < parts_len) { msg_destroy(list_get(parts, i)); counter_decrease(split->parts_left); } warning(0, "Could not send all parts of a split message"); break; } } list_destroy(parts, NULL); } mutex_unlock(conn->flow_mutex); return ret;}int smscconn_status(SMSCConn *conn){ gw_assert(conn != NULL); return conn->status;}int smscconn_info(SMSCConn *conn, StatusInfo *infotable){ if (conn == NULL || infotable == NULL) return -1; mutex_lock(conn->flow_mutex); infotable->status = conn->status; infotable->killed = conn->why_killed; infotable->is_stopped = conn->is_stopped; infotable->online = time(NULL) - conn->connect_time; infotable->sent = counter_value(conn->sent); infotable->received = counter_value(conn->received); infotable->failed = counter_value(conn->failed); if (conn->queued) infotable->queued = conn->queued(conn); else infotable->queued = -1; infotable->load = conn->load; mutex_unlock(conn->flow_mutex); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -