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

📄 testmo.c

📁 Unix/Linux下的cmpp实现源程序
💻 C
字号:

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "cmppif.h"

        
#include "kevopsall.ext"
        
        
#define INSTALL_DIR "/home/ke"
#define LOCK_FILE "./caserver.lck"


int main (int argc, char ** argv)
{
    CMPPHandle hcmpp = NULL;
    FILE * fp = NULL;
    int ret;

    unsigned int  seq_id;
    unsigned char msg_id[8];
    unsigned char dest_mobile[21];
    unsigned char service_id[10];
    unsigned char msg_fmt;
    unsigned char src_mobile[21];
    unsigned char status_report;
    unsigned char msg_len;
    unsigned char msg[300];

    struct tm * curtime;
    time_t      calendt;

    int           lock_fd        = -1;
    int           runasdaemon    = 0;
    char        * plockfile      = NULL,
                * pinstalldir    = NULL;
             
    
    initConfTable("cmpp.conf");
    
    runasdaemon = getConfBool("CmppSystem", "RunAsDaemon");
    if (runasdaemon) {
        plockfile = getConfString("CmppSystem", "LockFile");
        pinstalldir = getConfString("CmppSystem", "InstallDir");
        if (!plockfile || strlen(plockfile) < 1)
            plockfile = LOCK_FILE;
        if (!pinstalldir || strlen(pinstalldir) < 1)
            pinstalldir = INSTALL_DIR;
    
        lock_fd = daemonize (plockfile, pinstalldir);
    }

    printf("CMPPInit begin.\n");
    hcmpp = CMPPInit(getConfString("ISMG", "host"),
                     (unsigned int)getConfInt("ISMG", "port"),
                     getConfString("General", "SP_Id"),
                     getConfString("General", "SharedSecret"),
                     getConfInt("CMPP Connection", "MTConnection Num"),
                     getConfInt("CMPP Connection", "MOConnection Num"),
                     (unsigned char)getConfInt("General", "MTMajor_Version"),
                     (unsigned char)getConfInt("General", "MTMinor_Version"),
                     (unsigned char)getConfInt("General", "MOMajor_Version"),
                     (unsigned char)getConfInt("General", "MOMinor_Version"),
                     getConfInt("Flow Control", "Sliding Window"), 1
                     );
    printf("CMPPInit end.\n");

    fp = fopen("testmo.txt", "a+");

    while (1) {
        ret = CMPPDeliver(hcmpp, &seq_id, msg_id, dest_mobile,
                       service_id, &msg_fmt, src_mobile,
                       &status_report, &msg_len, msg);  
        if (ret == -10) break;
        if (ret < 0) continue;

        time(&calendt);
        curtime = localtime(&calendt);

        printf("\n--------------MO Message No: %d-------------\n", seq_id);
        printf("    msg_id: %02x%02x%02x%02x%02x%02x%02x%02x\n", 
                msg_id[7], msg_id[6], msg_id[5], msg_id[4], 
                msg_id[3], msg_id[2], msg_id[1], msg_id[0]);
        printf("    dest_mobile: %s\n", dest_mobile);
        printf("    service_id: %s\n", service_id);
        printf("    msg_fmt: %d\n", (int)msg_fmt);
        printf("    src_mobile: %s\n", src_mobile);
        printf("    status_report: %s\n", status_report?"yes":"no");
        printf("    msg_len: %d\n", (int)msg_len);
        printf("    msg_content: %s\n", msg);
        printf("------------%d-%02d-%02d %02d:%02d:%02d------------\n\n",
                curtime->tm_year+1900, curtime->tm_mon+1, curtime->tm_mday,
                curtime->tm_hour, curtime->tm_min, curtime->tm_sec);

        fprintf(fp,"\n--------------MO Message No: %d-------------\n", seq_id);
        fprintf(fp,"    msg_id: %02x%02x%02x%02x%02x%02x%02x%02x\n", 
                msg_id[7], msg_id[6], msg_id[5], msg_id[4], 
                msg_id[3], msg_id[2], msg_id[1], msg_id[0]);
        fprintf(fp,"    dest_mobile: %s\n", dest_mobile);
        fprintf(fp,"    service_id: %s\n", service_id);
        fprintf(fp,"    msg_fmt: %d\n", (int)msg_fmt);
        fprintf(fp,"    src_mobile: %s\n", src_mobile);
        fprintf(fp,"    status_report: %s\n", status_report?"yes":"no");
        fprintf(fp,"    msg_len: %d\n", (int)msg_len);
        fprintf(fp,"    msg_content: %s\n",  msg);
        fprintf(fp, "------------%d-%02d-%02d %02d:%02d:%02d------------\n\n",
                curtime->tm_year+1900, curtime->tm_mon+1, curtime->tm_mday,
                curtime->tm_hour, curtime->tm_min, curtime->tm_sec);
    }

    fclose(fp);

    printf("CMPPClose begin.\n");
    CMPPCleanup(hcmpp);
    printf("CMPPClose end.\n");
    
    if(lock_fd >= 0) close(lock_fd);
    destructConfTable();

    CMPPSysCleanup ();

    return 0;
}


⌨️ 快捷键说明

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