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

📄 test.c

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

#include <stdio.h>
#include <ctype.h>
#include <string.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;
    int  i;
    int ch;
    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");

    while ((ch = getchar()) != 'q') {
        if (ch == 's') {
            CMPPSubmit( hcmpp,
                        CMPPGetSeqID(),
                        9,
                        "0000000000",
                        "",
                        "",
                        "01",
                        "000000",
                        0,
                        "",
                        "686802",
                        1,
                        "13601322347",
                        15,
                        70,
                        "你好,这是北京掌上网最新短信平台测试消息!掌上网祝愿您周末快乐。柯恒忠",
                        0);
        } else if (ch == 'f') {
            FILE * fp = NULL;
            char mpno[128], buf[1024];
            fp = fopen("test.txt", "r+");
            if (!fp) continue;
            while(!feof(fp)) {
                memset(mpno, 0, sizeof(mpno));
                memset(buf, 0, sizeof(buf));
                fgets(mpno, sizeof(mpno)-1, fp);
                if (strlen(mpno) == 0) break;
                if (!isdigit((int)mpno[0])) {
                    continue;
                }
                for(i=strlen(mpno)-1; i>=0; i--) {
                    if (mpno[i] == '\n' || mpno[i]==' ' || mpno[i]=='\t')
                        mpno[i] = '\0';
                    else
                        break;
                }
                fgets(buf, sizeof(buf)-1, fp);
                for(i=strlen(buf)-1; i>=0; i--) {
                    if (buf[i] == '\n' || buf[i]==' ' || buf[i]=='\t')
                        buf[i] = '\0';
                    else
                        break;
                }
                CMPPSubmit( hcmpp,
                            CMPPGetSeqID(),
                            9,
                            "0000000000",
                            "",
                            "",
                            "01",
                            "000000",
                            0,
                            "",
                            "6868",
                            1,
                            mpno,
                            15,
                            strlen(buf),
                            buf,
                            0);   
            }        
            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 + -