Main.cpp 4.7 KB
Newer Older
报告_前方高能's avatar
报告_前方高能 已提交
1 2 3
/*****************************************************************************
Copyright (c) netsecsp 2012-2032, All rights reserved.

报告_前方高能's avatar
报告_前方高能 已提交
4
Developer: Shengqian Yang, from China, E-mail: netsecsp@hotmail.com, last updated 05/01/2022
报告_前方高能's avatar
报告_前方高能 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
http://ahttp.sf.net

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.

* 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.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS 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 COPYRIGHT OWNER OR
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.
*****************************************************************************/
#include "stdafx.h"
#include <conio.h>

#define AAPIDLL_USING

#include "Service.h"

#ifdef AAPIDLL_USING
#include <frame/asm/ITypedef_i.c>
#include <frame/asm/IAsynFrame_i.c>
#include <frame/asm/IAsynFileSystem_i.c>
#include <frame/asm/IAsynNetwork_i.c>
#include <frame/asm/INet_i.c>
#include <frame/asm/ISsl_i.c>
#endif

#ifdef AAPIDLL_USING
#ifdef _DEBUG
#pragma comment(lib, "asynsdk_mini-MDd.lib")
#else
#pragma comment(lib, "asynsdk_mini-MD.lib")
#endif
#pragma comment(lib,"asyncore_dll.lib")
#else
#pragma comment(lib,"asynframe_lib.lib")
#endif
报告_前方高能's avatar
报告_前方高能 已提交
58
STDAPI_(extern HRESULT) Initialize( /*[in ]*/IAsynMessageEvents *param1, /*[in ]*/IUnknown *param2 );
报告_前方高能's avatar
报告_前方高能 已提交
59 60 61
STDAPI_(extern HRESULT) Destory();
STDAPI_(extern InstancesManager *) GetInstancesManager();

报告_前方高能's avatar
报告_前方高能 已提交
62
static void ShowUsage(std::string name)
报告_前方高能's avatar
报告_前方高能 已提交
63
{
报告_前方高能's avatar
报告_前方高能 已提交
64 65 66 67 68 69 70 71
    std::string::size_type i = name.find_last_of("/\\");
    if( i != std::string::npos )
        name.erase(0, i + 1);

    printf("  Usage: %s [-4|6] configfile\n", name.c_str());
    printf("Options:\n");
    printf("      -4 Enforce IPv4\n");
    printf("      -6 Enforce IPv6\n");
报告_前方高能's avatar
报告_前方高能 已提交
72 73
}

报告_前方高能's avatar
报告_前方高能 已提交
74 75 76 77 78 79
int _tmain(int argc, _TCHAR *argv[])
{
    printf("Copyright (c) netsecsp 2012-2032, All rights reserved.\n");
    printf("Developer: Shengqian Yang, from China, E-mail: netsecsp@hotmail.com, last updated " STRING_UPDATETIME "\n");
    printf("http://ahttp.sf.net\n\n");

报告_前方高能's avatar
报告_前方高能 已提交
80
    char ipvx = AF_INET, *file = "config.txt";
报告_前方高能's avatar
报告_前方高能 已提交
81 82
    for(int i = 1; i < argc; ++ i)
    {
报告_前方高能's avatar
报告_前方高能 已提交
83 84 85
        if( strcmp(argv[i], "/?") == 0 || 
            strcmp(argv[i], "--help") == 0 )
        {
报告_前方高能's avatar
报告_前方高能 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
            file = 0;
            break;
        }

        if( argv[i][0] == '-' )
        {
            if( strcmp(argv[i], "-4") == 0 )
            {
                ipvx = AF_INET;
                continue;
            }
            if( strcmp(argv[i], "-6") == 0 )
            {
                ipvx = 23;
                continue;
            }
        }
        else
        {
            file = argv[i];
报告_前方高能's avatar
报告_前方高能 已提交
106
        }
报告_前方高能's avatar
报告_前方高能 已提交
107
    }
报告_前方高能's avatar
报告_前方高能 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

    if(!file )
    {
        ShowUsage(argv[0]);
        return 0;
    }

    setting configure(file);

    if( configure.m_sections.empty())
    {
        ShowUsage(argv[0]);
        return 0;
    }

报告_前方高能's avatar
报告_前方高能 已提交
123 124 125 126 127 128 129 130 131 132
    if( Initialize(NULL, NULL) != NO_ERROR )
    {
        printf("fail to Initialize asynframe\n");
        return 0;
    }

    do
    {
        InstancesManager *lpInstancesManager = GetInstancesManager();

报告_前方高能's avatar
报告_前方高能 已提交
133
        if( lpInstancesManager->Require(STRING_from_string(IN_AsynNetwork)) != S_OK )
报告_前方高能's avatar
报告_前方高能 已提交
134 135 136 137 138 139
        {
            printf("can't load plugin: %s\n", IN_AsynNetwork);
            break;
        }

        CComPtr<IAsynFrameThread> spAsynFrameThread;
报告_前方高能's avatar
报告_前方高能 已提交
140
        lpInstancesManager->NewInstance(0, TC_Iocp, IID_IAsynFrameThread, (void **)&spAsynFrameThread);
报告_前方高能's avatar
报告_前方高能 已提交
141

报告_前方高能's avatar
报告_前方高能 已提交
142
        std::unique_ptr<CService> pService(new CService(lpInstancesManager, configure, spAsynFrameThread, ipvx));
报告_前方高能's avatar
报告_前方高能 已提交
143 144
        if( pService->Start() )
        {
报告_前方高能's avatar
报告_前方高能 已提交
145
            while(!_kbhit())
报告_前方高能's avatar
报告_前方高能 已提交
146
            {
报告_前方高能's avatar
报告_前方高能 已提交
147
                ::Sleep(100); //0.1sec
报告_前方高能's avatar
报告_前方高能 已提交
148 149 150 151 152 153 154 155 156 157 158 159
            }
        }
        pService->Shutdown();
    }while(0);

    if( Destory() != NO_ERROR )
    {
        printf("fail to Destory asynframe\n");
    }

    return 0;
}