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

📄 smsc.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================  * The Kannel Software License, Version 1.0  *  * Copyright (c) 2001-2004 Kannel Group   * Copyright (c) 1998-2001 WapIT Ltd.    * All rights reserved.  *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met:  *  * 1. Redistributions of source code must retain the above copyright  *    notice, this list of conditions and the following disclaimer.  *  * 2. Redistributions in binary form must reproduce the above copyright  *    notice, this list of conditions and the following disclaimer in  *    the documentation and/or other materials provided with the  *    distribution.  *  * 3. The end-user documentation included with the redistribution,  *    if any, must include the following acknowledgment:  *       "This product includes software developed by the  *        Kannel Group (http://www.kannel.org/)."  *    Alternately, this acknowledgment may appear in the software itself,  *    if and wherever such third-party acknowledgments normally appear.  *  * 4. The names "Kannel" and "Kannel Group" must not be used to  *    endorse or promote products derived from this software without  *    prior written permission. For written permission, please   *    contact org@kannel.org.  *  * 5. Products derived from this software may not be called "Kannel",  *    nor may "Kannel" appear in their name, without prior written  *    permission of the Kannel Group.  *  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,   * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE   * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  * ====================================================================  *  * This software consists of voluntary contributions made by many  * individuals on behalf of the Kannel Group.  For more information on   * the Kannel Group, please see <http://www.kannel.org/>.  *  * Portions of this software are based upon software originally written at   * WapIT Ltd., Helsinki, Finland for the Kannel project.   */ /* * smsc.c - implement interface to SMS centers as defined by smsc.h * * Lars Wirzenius and Kalle Marjola for WapIT Ltd. *//* NOTE: private functions (only for smsc_* use) are named smscenter_*, * public functions (used by gateway) are named smsc_* */#include <errno.h>#include <signal.h>#include <stdarg.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>#include <sys/time.h>#include "gwlib/gwlib.h"#include "smsc.h"#include "smsc_p.h"#include "msg.h"/* * Maximum number of characters for read_into_buffer to read at a time. */#define MAX_READ_INTO_BUFFER	(1024)static void smscenter_lock(SMSCenter *smsc);static void smscenter_unlock(SMSCenter *smsc);/*-------------------------------------------------------------------- * TODO: WAP WDP functions! *//*-------------------------------------------------------------------- * smscenter functions */SMSCenter *smscenter_construct(void){    SMSCenter *smsc;    static int next_id = 1;    smsc = gw_malloc(sizeof(SMSCenter));    smsc->killed = 0;    smsc->type = SMSC_TYPE_DELETED;    smsc->preferred_prefix = NULL;    smsc->allowed_prefix = NULL;    smsc->denied_prefix = NULL;    smsc->alt_charset = 0;    smsc->keepalive = 0;    smsc->mutex = mutex_create();    sprintf(smsc->name, "Unknown SMSC");    smsc->id = next_id++;    /* FAKE */    smsc->hostname = NULL;    smsc->port = -1;    smsc->socket = -1;    /* CIMD */    smsc->cimd_hostname = NULL;    smsc->cimd_port = -1;    smsc->cimd_username = NULL;    smsc->cimd_password = NULL;    /* EMI_X25 */    smsc->emi_phonenum = NULL;    smsc->emi_serialdevice = NULL;    smsc->emi_username = NULL;    smsc->emi_password = NULL;    /* SEMA SMS2000 */    smsc->sema_smscnua = NULL;    smsc->sema_homenua = NULL;    smsc->sema_serialdevice = NULL;    smsc->sema_fd = -1;    /* SEMA SMS2000 OIS X.25 */    smsc->ois_alive = 0;    smsc->ois_alive2 = 0;    smsc->ois_received_mo = NULL;    smsc->ois_ack_debt = 0;    smsc->ois_flags = 0;    smsc->ois_listening_socket = -1;    smsc->ois_socket = -1;    smsc->ois_buflen = 0;    smsc->ois_bufsize = 0;    smsc->ois_buffer = 0;    /* add new SMSCes here */    /* Memory */    smsc->buflen = 0;    smsc->bufsize = 10*1024;    smsc->buffer = gw_malloc(smsc->bufsize);    memset(smsc->buffer, 0, smsc->bufsize);    return smsc;}void smscenter_destruct(SMSCenter *smsc){    if (smsc == NULL)        return;    /* FAKE */    gw_free(smsc->hostname);    /* CIMD */    gw_free(smsc->cimd_hostname);    gw_free(smsc->cimd_username);    gw_free(smsc->cimd_password);    /* EMI_X25 */    gw_free(smsc->emi_phonenum);    gw_free(smsc->emi_serialdevice);    gw_free(smsc->emi_username);    gw_free(smsc->emi_password);    /* SEMA */    gw_free(smsc->sema_smscnua);    gw_free(smsc->sema_homenua);    gw_free(smsc->sema_serialdevice);    /* OIS */    ois_delete_queue(smsc);    gw_free(smsc->ois_buffer);    /* add new SMSCes here */    /* Other fields */    mutex_destroy(smsc->mutex);    /* Memory */    gw_free(smsc->buffer);    gw_free(smsc);}int smscenter_submit_msg(SMSCenter *smsc, Msg *msg){    smscenter_lock(smsc);    switch (smsc->type) {    case SMSC_TYPE_CIMD:        if (cimd_submit_msg(smsc, msg) == -1)            goto error;        break;    case SMSC_TYPE_EMI_X25:        if (emi_submit_msg(smsc, msg) == -1)            goto error;        break;    case SMSC_TYPE_SEMA_X28:        if (sema_submit_msg(smsc, msg) == -1)            goto error;        break;    case SMSC_TYPE_OIS:        if (ois_submit_msg(smsc, msg) == -1)            goto error;        break;        /* add new SMSCes here */    default:        goto error;    }    smscenter_unlock(smsc);    return 0;error:    smscenter_unlock(smsc);    return -1;}int smscenter_receive_msg(SMSCenter *smsc, Msg **msg){    int ret;    smscenter_lock(smsc);    switch (smsc->type) {    case SMSC_TYPE_CIMD:        ret = cimd_receive_msg(smsc, msg);        if (ret == -1)            goto error;        break;    case SMSC_TYPE_EMI_X25:        ret = emi_receive_msg(smsc, msg);        if (ret == -1)            goto error;        break;    case SMSC_TYPE_OIS:        ret = ois_receive_msg(smsc, msg);        if (ret == -1)            goto error;        break;    case SMSC_TYPE_SEMA_X28:        ret = sema_receive_msg(smsc, msg);        if (ret == -1)            goto error;        break;    default:        goto error;    }    smscenter_unlock(smsc);    /* If the SMSC didn't set the timestamp, set it here. */    if (ret == 1 && msg_type(*msg) == sms && (*msg)->sms.time == 0)        time(&(*msg)->sms.time);    return ret;error:    smscenter_unlock(smsc);    return -1;}int smscenter_pending_smsmessage(SMSCenter *smsc){    int ret;    smscenter_lock(smsc);    switch (smsc->type) {    case SMSC_TYPE_CIMD:        ret = cimd_pending_smsmessage(smsc);        if (ret == -1)            goto error;        break;    case SMSC_TYPE_EMI_X25:        ret = emi_pending_smsmessage(smsc);        if (ret == -1)            goto error;        break;    case SMSC_TYPE_SEMA_X28:        ret = sema_pending_smsmessage(smsc);        if (ret == -1)            goto error;        break;    case SMSC_TYPE_OIS:        ret = ois_pending_smsmessage(smsc);        if (ret == -1)            goto error;        break;    default:        goto error;    }    smscenter_unlock(smsc);    return ret;error:    error(0, "smscenter_pending_smsmessage is failing");    smscenter_unlock(smsc);    return -1;}

⌨️ 快捷键说明

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