⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsc_smpp.c

📁 gnu的专业网关smpp协议支持源代码。
💻 C
📖 第 1 页 / 共 4 页
字号:
	         last_enquire_sent = date_universal_now();         pending_submits = -1;         len = 0;         for (;;) {             timeout = last_enquire_sent + smpp->enquire_link_interval                        - date_universal_now();             /* unbind */            if (smpp->quitting) {                send_unbind(smpp, conn);                while ((ret = read_pdu(smpp, conn, &len, &pdu)) == 1) {                    dump_pdu("Got PDU:", smpp->conn->id, pdu);                    handle_pdu(smpp, conn, pdu, &pending_submits);                    smpp_pdu_destroy(pdu);                }                debug("bb.sms.smpp", 0, "SMPP[%s]: %s: break and shutting down",                      octstr_get_cstr(smpp->conn->id), __PRETTY_FUNCTION__);            }            if (smpp->quitting || conn_wait(conn, timeout) == -1)                 break;              send_enquire_link(smpp, conn, &last_enquire_sent); 	                 while ((ret = read_pdu(smpp, conn, &len, &pdu)) == 1) {                 /* Deal with the PDU we just got */                 dump_pdu("Got PDU:", smpp->conn->id, pdu);                 handle_pdu(smpp, conn, pdu, &pending_submits);                 smpp_pdu_destroy(pdu);                  /* Make sure we send enquire_link even if we read a lot */                 send_enquire_link(smpp, conn, &last_enquire_sent);                  /* Make sure we send even if we read a lot */                 if (transmitter &&                    (!smpp->throttling_err_time ||                     ((time(NULL) - smpp->throttling_err_time) > SMPP_THROTTLING_SLEEP_TIME                         && !(smpp->throttling_err_time = 0)))                    )                    send_messages(smpp, conn, &pending_submits);             } 	                 if (ret == -1) {                 error(0, "SMPP[%s]: I/O error or other error. Re-connecting.",                      octstr_get_cstr(smpp->conn->id));                 break;             } 	                 if (transmitter &&                (!smpp->throttling_err_time ||                 ((time(NULL) - smpp->throttling_err_time) > SMPP_THROTTLING_SLEEP_TIME                     && !(smpp->throttling_err_time = 0)))                )                send_messages(smpp, conn, &pending_submits);         } 	         conn_destroy(conn);         conn = NULL;     }     conn_destroy(conn); }       /***********************************************************************  * Functions called by smscconn.c via the SMSCConn function pointers.  */    static long queued_cb(SMSCConn *conn) {     SMPP *smpp;      smpp = conn->data;    conn->load = (smpp ? (conn->status != SMSCCONN_DEAD ?                   list_len(smpp->msgs_to_send) : 0) : 0);    return conn->load; }   static int send_msg_cb(SMSCConn *conn, Msg *msg) {     SMPP *smpp;          smpp = conn->data;     list_produce(smpp->msgs_to_send, msg_duplicate(msg));     gwthread_wakeup(smpp->transmitter);     return 0; }   static int shutdown_cb(SMSCConn *conn, int finish_sending) {     SMPP *smpp;      debug("bb.smpp", 0, "Shutting down SMSCConn %s (%s)",           octstr_get_cstr(conn->name),           finish_sending ? "slow" : "instant");      conn->why_killed = SMSCCONN_KILLED_SHUTDOWN;      /* XXX implement finish_sending */      smpp = conn->data;     smpp->quitting = 1;     gwthread_wakeup(smpp->transmitter);     gwthread_wakeup(smpp->receiver);     gwthread_join(smpp->transmitter);     gwthread_join(smpp->receiver);     smpp_destroy(smpp);          debug("bb.smpp", 0, "SMSCConn %s shut down.",            octstr_get_cstr(conn->name));     conn->status = SMSCCONN_DEAD;     bb_smscconn_killed();     return 0; }   /***********************************************************************  * Public interface. This version is suitable for the Kannel bearerbox  * SMSCConn interface.  */   int smsc_smpp_create(SMSCConn *conn, CfgGroup *grp) {     Octstr *host;     long port;     long receive_port;     Octstr *username;     Octstr *password;     Octstr *system_id;     Octstr *system_type;     Octstr *address_range;     long source_addr_ton;     long source_addr_npi;     long dest_addr_ton;     long dest_addr_npi;     Octstr *our_host;     Octstr *my_number;     SMPP *smpp;     int ok;     int transceiver_mode;     Octstr *smsc_id;     int alt_dcs;    long enquire_link_interval;    long max_pending_submits;    long reconnect_delay;    long version;    long priority;    long smpp_msg_id_type;    int autodetect_addr;     my_number = NULL;     transceiver_mode = 0;    alt_dcs = 0;    autodetect_addr = 0;     host = cfg_get(grp, octstr_imm("host"));     if (cfg_get_integer(&port, grp, octstr_imm("port")) == -1)         port = 0;     if (cfg_get_integer(&receive_port, grp, octstr_imm("receive-port")) == -1)         receive_port = 0;     cfg_get_bool(&transceiver_mode, grp, octstr_imm("transceiver-mode"));     cfg_get_bool(&alt_dcs, grp, octstr_imm("alt-dcs"));     username = cfg_get(grp, octstr_imm("smsc-username"));     password = cfg_get(grp, octstr_imm("smsc-password"));     system_type = cfg_get(grp, octstr_imm("system-type"));     address_range = cfg_get(grp, octstr_imm("address-range"));     our_host = cfg_get(grp, octstr_imm("our-host"));     my_number = cfg_get(grp, octstr_imm("my-number"));          system_id = cfg_get(grp, octstr_imm("system-id"));     if (system_id != NULL) {         warning(0, "SMPP: obsolete system-id variable is set, " 	    	   "use smsc-username instead.");         if (username == NULL) {             warning(0, "SMPP: smsc-username not set, using system-id instead");             username = system_id;         } else             octstr_destroy(system_id);     }     /*      * check if timing values have been configured, otherwise     * use the predefined default values.     */    if (cfg_get_integer(&enquire_link_interval, grp,                         octstr_imm("enquire-link-interval")) == -1)        enquire_link_interval = SMPP_ENQUIRE_LINK_INTERVAL;    if (cfg_get_integer(&max_pending_submits, grp,                         octstr_imm("max-pending-submits")) == -1)        max_pending_submits = SMPP_MAX_PENDING_SUBMITS;    if (cfg_get_integer(&reconnect_delay, grp,                         octstr_imm("reconnect-delay")) == -1)        reconnect_delay = SMPP_RECONNECT_DELAY;     /* Check that config is OK */     ok = 1;     if (host == NULL) {         error(0,"SMPP: Configuration file doesn't specify host");         ok = 0;     }         if (username == NULL) { 	    error(0, "SMPP: Configuration file doesn't specify username."); 	    ok = 0;     }     if (password == NULL) { 	    error(0, "SMPP: Configuration file doesn't specify password."); 	    ok = 0;     }     if (system_type == NULL) { 	    error(0, "SMPP: Configuration file doesn't specify system-type."); 	    ok = 0;     }     if (!ok)         return -1;      /* if the ton and npi values are forced, set them, else set them to -1 */     if (cfg_get_integer(&source_addr_ton, grp,                         octstr_imm("source-addr-ton")) == -1)         source_addr_ton = -1;     if (cfg_get_integer(&source_addr_npi, grp,                         octstr_imm("source-addr-npi")) == -1)         source_addr_npi = -1;     if (cfg_get_integer(&dest_addr_ton, grp,                         octstr_imm("dest-addr-ton")) == -1)         dest_addr_ton = -1;     if (cfg_get_integer(&dest_addr_npi, grp,                         octstr_imm("dest-addr-npi")) == -1)         dest_addr_npi = -1;     /* if source addr autodetection should be used set this to 1 */    cfg_get_bool(&autodetect_addr, grp, octstr_imm("source-addr-autodetect"));     /* check for any specified interface version */    if (cfg_get_integer(&version, grp, octstr_imm("interface-version")) == -1)        version = SMPP_DEFAULT_VERSION;    else        /* convert decimal to BCD */        version = ((version / 10) << 4) + (version % 10);    /* check for any specified priority value in range [0-5] */    if (cfg_get_integer(&priority, grp, octstr_imm("priority")) == -1)        priority = SMPP_DEFAULT_PRIORITY;    /* set the msg_id type variable for this SMSC */    if (cfg_get_integer(&smpp_msg_id_type, grp, octstr_imm("msg-id-type")) == -1) {        /*          * defaults to C string "as-is" style          */        smpp_msg_id_type = -1;     } else {        if (smpp_msg_id_type < 0 || smpp_msg_id_type > 3)            panic(0,"SMPP: Invlid value for msg-id-type directive in configuraton");     }    smpp = smpp_create(conn, host, port, receive_port, system_type,      	    	       username, password, address_range, our_host,                        source_addr_ton, source_addr_npi, dest_addr_ton,                         dest_addr_npi, alt_dcs, enquire_link_interval,                        max_pending_submits, reconnect_delay,                        version, priority, my_number, smpp_msg_id_type,                       autodetect_addr);      conn->data = smpp;     conn->name = octstr_format("SMPP:%S:%d/%d:%S:%S",      	    	    	       host, port,                                (receive_port ? receive_port : port),                                 username, system_type);      smsc_id = cfg_get(grp, octstr_imm("smsc-id"));     if (smsc_id == NULL) {         conn->id = octstr_duplicate(conn->name);     }     octstr_destroy(host);     octstr_destroy(username);     octstr_destroy(password);     octstr_destroy(system_type);     octstr_destroy(address_range);     octstr_destroy(our_host);     octstr_destroy(my_number);     octstr_destroy(smsc_id);     conn->status = SMSCCONN_CONNECTING;            /*      * I/O threads are only started if the corresponding ports      * have been configured with positive numbers. Use 0 to       * disable the creation of the corresponding thread.      */     if (port != 0)         smpp->transmitter = gwthread_create(io_thread, io_arg_create(smpp,                                             (transceiver_mode ? 2 : 1)));     if (receive_port != 0)         smpp->receiver = gwthread_create(io_thread, io_arg_create(smpp, 0));          if ((port != 0 && smpp->transmitter == -1) ||          (receive_port != 0 && smpp->receiver == -1)) {         error(0, "SMPP[%s]: Couldn't start I/O threads.",              octstr_get_cstr(smpp->conn->id));         smpp->quitting = 1;         if (smpp->transmitter != -1) {             gwthread_wakeup(smpp->transmitter);             gwthread_join(smpp->transmitter);         }         if (smpp->receiver != -1) {             gwthread_wakeup(smpp->receiver);             gwthread_join(smpp->receiver);         }     	smpp_destroy(conn->data);         return -1;     }      conn->shutdown = shutdown_cb;     conn->queued = queued_cb;     conn->send_msg = send_msg_cb;      return 0; } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -