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

📄 httpddev.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                    *pdwActualOut = sizeof(DWORD);
            }
            __except (ReportFault(GetExceptionInformation(),0), EXCEPTION_EXECUTE_HANDLER) {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
            }
            return TRUE;
        break;

        case IOCTL_SERVICE_REGISTER_SOCKADDR:
            if (pBufIn == NULL) {
                // pBufIn = NULL on first call by services.exe to query whether this is supported or not.
                // if we return FALSE there will be no more calls.
                // pBuf is SOCKADDR being registered on subsequent calls.  We don't care what
                // we're bound to, so don't bother checking at this stage.
                return IsHttpdEnabled();
            }
            return TRUE;
        break;

        case IOCTL_SERVICE_DEREGISTER_SOCKADDR:
            return TRUE;
        break;

        case IOCTL_SERVICE_STARTED:
            // This should only be generated by services.exe itself, so we're fine checking trust.
            if (! CheckCallerTrusted())
                return FALSE;

            if (InterlockedCompareExchange(&g_fState,SERVICE_STATE_STARTING_UP,SERVICE_STATE_OFF) == SERVICE_STATE_OFF) {
                DEBUGMSG(ZONE_INIT,(L"HTTPD:IOControl(IOCTL_SERVICE_STARTED) creating global variales\r\n"));
                DEBUGCHK(!g_hAdminThread);
                g_hAdminThread = MyCreateThread(InitializeGlobalsThread,0);
                if (g_hAdminThread) {
                    return TRUE;
                }
                return FALSE;
            }
            SetLastError(ERROR_SERVICE_ALREADY_RUNNING);
            return FALSE;
        break;

        case IOCTL_SERVICE_CONNECTION:
        {
            // This should only be generated by services.exe itself, so we're fine checking trust.
            if (! CheckCallerTrusted())
                return FALSE;

            SOCKET sock;

            // Received when from a super service.
            if ((pBufIn==NULL) || (dwLenIn!=sizeof(SOCKET)) ||
                (0 == CeSafeCopyMemory(&sock,pBufIn,sizeof(sock))))
            {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
            }

            if (g_fState != SERVICE_STATE_ON || !g_pVars->m_fAcceptConnections) {
                SetLastError(ERROR_SERVICE_CANNOT_ACCEPT_CTRL);
                DEBUGMSG(ZONE_ERROR,(L"HTTP: HTP_IOCTL(IOCTL_SERVICE_CONNECTION) fails, HTTPD not running\r\n"));
                closesocket(sock); // we still have to do this much.
                return FALSE;
            }

            SOCKADDR_STORAGE sockAddr;
            int          cbSockAddr = sizeof(sockAddr);

            if ((0 != getsockname(sock,(PSOCKADDR) &sockAddr,&cbSockAddr))) {
                DEBUGMSG(ZONE_ERROR,(L"HTTPD: getsockname fails, GLE=0x%08x\r\n",GetLastError()));
                closesocket(sock);
                return FALSE;
            }
            return CreateHTTPConnection(sock,(PSOCKADDR)&sockAddr,cbSockAddr);
        }
        break;

        // network addresses are changing.
        case IOCTL_SERVICE_NOTIFY_ADDR_CHANGE:
            // This should only be generated by services.exe itself, so we're fine checking trust.
            if (! CheckCallerTrusted())
                return FALSE;

            if ((g_fState == SERVICE_STATE_ON) || (g_fState == SERVICE_STATE_STARTING_UP))
                svsutil_HandleNotifyAddrChange();
        break;

        case IOCTL_SERVICE_SUPPORTED_OPTIONS:
            if (!pBufOut || dwLenOut < sizeof(DWORD)) {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
            }

            dwOut = 0;

            if (g_fIsapiExtensionModule)
                dwOut |= HTTPD_OPTION_ISAPI_EXTENSIONS;

            if (g_fIsapiFilterModule)
                dwOut |= HTTPD_OPTION_ISAPI_FILTERS;

            if (g_fAuthModule)
                dwOut |= (HTTPD_OPTION_AUTHENTICATION | HTTPD_OPTION_SSL);

            if (g_fWebDavModule)
                dwOut |= HTTPD_OPTION_WEBDAV;

            __try {
                *(DWORD *)pBufOut = dwOut;
                if (pdwActualOut)
                    *pdwActualOut = sizeof(DWORD);
            }
            __except(ReportFault(GetExceptionInformation(),0), EXCEPTION_EXECUTE_HANDLER) {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
            }

            return TRUE;

        break;

        default:
            DEBUGMSG(ZONE_ERROR,(L"HTTPD: HTP_IOControl unhandled dwCode 0x%08x\r\n",dwCode));
        break;
    }
    SetLastError(ERROR_INVALID_PARAMETER);
    return FALSE;
}


//      @func PVOID | HTP_Init | Device initialization routine
//  @parm DWORD | dwData | Info passed to RegisterDevice
//  @rdesc      Returns a DWORD which will be passed to Open & Deinit or NULL if
//              unable to initialize the device.
//      @remark dwData is a CTelnetContext passed in by our server thread

extern "C" DWORD HTP_Init (DWORD dwData) {
    DEBUGMSG(ZONE_INIT,(L"HTTPD:HTP_Init(0x%08x)\r\n",dwData));

    if (! (dwData & SERVICE_INIT_STOPPED)) {
        // If services.exe was not configured to startup super-service
        // ports for HTTPD, then there's nothing we can do
        DEBUGMSG(ZONE_ERROR,(L"HTTPD: Error, must run in super-services mode.  Cannot start\r\n"));
        SetLastError(ERROR_SERVICE_CANNOT_ACCEPT_CTRL);
        DEBUGCHK(0); // Indicates a serious system misconfiguration which needs fixing!
        return 0;
    }

    if (InterlockedCompareExchange(&g_fState,SERVICE_STATE_OFF,SERVICE_STATE_UNINITIALIZED) == (INTERLOCKED_RESULT)SERVICE_STATE_UNINITIALIZED)  {
        DEBUGCHK(g_pTimer == NULL);

        DEBUGMSG(ZONE_INIT,(L"HTTPD: Initializing web server: creating thread pool, initing interface mapping...\r\n"));
        DEBUGMSG(ZONE_INIT,(L"HTTPD: Web Server supports the following components: %s %s %s %s\r\n",
            g_fIsapiExtensionModule ? L"ISAPI Extensions," : L"",
            g_fIsapiFilterModule    ? L"ISAPI Filters," : L"",
            g_fAuthModule       ? L"Authentication, SSL," : L"",
            g_fWebDavModule     ? L"Web DAV": L""
        ));

        if (! HttpInitializeOnce())
            return FALSE;

        return (DWORD) &g_fState;
    }

    // HTTPD cannot be initialized more than once.
    SetLastError(ERROR_SERVICE_ALREADY_RUNNING);
    return 0;
}

//      @func PVOID | HTP_Deinit | Device deinitialization routine
//  @parm DWORD | dwData | value returned from HTP_Init call
//  @rdesc      Returns TRUE for success, FALSE for failure.

extern "C" BOOL HTP_Deinit(DWORD dwData) {
    DEBUGMSG(ZONE_DEVICE, (TEXT("HTP_Deinit(0x%08x)\r\n"),dwData));
    return HttpUnload();
}

//      @func PVOID | HTP_Open      | Device open routine
//  @parm DWORD | dwData        | value returned from HTP_Init call
//  @parm DWORD | dwAccess          | requested access (combination of GENERIC_READ
//                                and GENERIC_WRITE)
//  @parm DWORD | dwShareMode   | requested share mode (combination of
//                                FILE_SHARE_READ and FILE_SHARE_WRITE)
//  @rdesc      Returns a DWORD which will be passed to Read, Write, etc or NULL if
//              unable to open device.
extern "C" DWORD HTP_Open (DWORD dwData, DWORD dwAccess, DWORD dwShareMode) {
    DEBUGMSG (ZONE_DEVICE, (TEXT("HTP_Open(0x%X)\r\n"), dwData));
    return (DWORD)dwData;
}

//      @func BOOL | HTP_Close | Device close routine
//  @parm DWORD | dwOpenData | value returned from HTP_Open call
//  @rdesc      Returns TRUE for success, FALSE for failure
extern "C" BOOL HTP_Close (DWORD dwData)  {
    DEBUGMSG (ZONE_DEVICE, (TEXT("HTP_Close(0x%X)\r\n"), dwData));

    return TRUE;
}

//      @func DWORD | HTP_Write | Device write routine
//  @parm DWORD | dwOpenData | value returned from HTP_Open call
//  @parm LPCVOID | pBuf | buffer containing data
//  @parm DWORD | len | maximum length to write [IN BYTES, NOT WORDS!!!]
//  @rdesc      Returns -1 for error, otherwise the number of bytes written.  The
//              length returned is guaranteed to be the length requested unless an
//              error condition occurs.
extern "C" DWORD HTP_Write (DWORD dwData, LPCVOID pInBuf, DWORD dwInLen) {
    DEBUGMSG (ZONE_DEVICE, (TEXT("HTP_Write(0x%X, 0x%X, %d)\r\n"),
                  dwData, pInBuf, dwInLen));
    return (DWORD)-1;
}

//      @func DWORD | HTP_Read | Device read routine
//  @parm DWORD | dwOpenData | value returned from HTP_Open call
//  @parm LPVOID | pBuf | buffer to receive data
//  @parm DWORD | len | maximum length to read [IN BYTES, not WORDS!!]
//  @rdesc      Returns 0 for end of file, -1 for error, otherwise the number of
//              bytes read.  The length returned is guaranteed to be the length
//              requested unless end of file or an error condition occurs.
//
// !!!!NOTE that this function ALWAYS returns ANSI text, NOT UNICODE!!!!
//
extern "C" DWORD HTP_Read (DWORD dwData, LPVOID pBuf, DWORD dwLen) {
    DEBUGMSG (ZONE_DEVICE, (TEXT("HTP_Read Enter(0x%X, 0x%X, %d)\r\n"), dwData, pBuf, dwLen));
    return (DWORD)-1;
}


//      @func DWORD | HTP_Seek | Device seek routine
//  @parm DWORD | dwOpenData | value returned from HTP_Open call
//  @parm long | pos | position to seek to (relative to type)
//  @parm DWORD | type | FILE_BEGIN, FILE_CURRENT, or FILE_END
//  @rdesc      Returns current position relative to start of file, or -1 on error

extern "C" DWORD HTP_Seek (DWORD dwData, long pos, DWORD type) {
    DEBUGMSG (ZONE_DEVICE, (TEXT("HTP_Seek(0x%X, %d, %d) NOT SUPPORTED\r\n"), dwData, pos, type));
    return (DWORD)-1;
}

//      @func void | HTP_PowerUp | Device powerup routine
//      @comm   Called to restore device from suspend mode.  You cannot call any
//              routines aside from those in your dll in this call.
extern "C" void HTP_PowerUp(void) {
    return;
}
//      @func void | HTP_PowerDown | Device powerdown routine
//      @comm   Called to suspend device.  You cannot call any routines aside from
//              those in your dll in this call.
extern "C" void HTP_PowerDown(void) {
    return;
}


⌨️ 快捷键说明

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