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

📄 http.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
						::SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)szBuf );
						};
						EndDialog( hDlg, 1 );
						break;

					case IDCANCEL:
						EndDialog( hDlg, 0 );
						break;

					case IDC_INDEX1:
						if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE )
							{
							if ( SendMessage( GET_WM_COMMAND_HWND(wParam, lParam ), EM_LINELENGTH,
								0, 0 )>0 )
								{ EnableWindow( hWndDlgOK, TRUE ); }
							else
								{ EnableWindow( hWndDlgOK, FALSE ); }
							}
						else
							return (FALSE);
						break;

					default:;
					};

			default:
				return (FALSE);
			};

		return (TRUE);
		}

	BOOL DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
	    {
	    enum { BUF_SIZE=1023 };
	    char szBuf[BUF_SIZE+1];

		switch (uMsg)
			{
			case WM_INITDIALOG:
				{
				const char *pA = M_LookupValue( pConfig, "General", "Admin" );
				hWndSrvStamp = GetDlgItem( hDlg, IDC_SERVERSTAMP );
				hWndList = GetDlgItem( hDlg, IDC_LIST );
				hWndGet = GetDlgItem( hDlg, IDC_GET );
				hWndHead = GetDlgItem( hDlg, IDC_HEAD );
				hWndPost = GetDlgItem( hDlg, IDC_POST );
				hWndPut = GetDlgItem( hDlg, IDC_PUT );
				hWndDelete = GetDlgItem( hDlg, IDC_DELETE );
				hWndOptions = GetDlgItem( hDlg, IDC_OPTIONS );
				hWndTrace = GetDlgItem( hDlg, IDC_TRACE );
				hWndDescription = GetDlgItem( hDlg, IDC_DESCR );
				hWndAnnotation = GetDlgItem( hDlg, IDC_ANNOTATION );
				hWndUploadPath = GetDlgItem( hDlg, IDC_DOCUMENTROOT );
				hWndUploadLimit = GetDlgItem( hDlg, IDC_LIMIT );
				hWndChunkLimit = GetDlgItem( hDlg, IDC_CHUNKED );
				hWndRanges = GetDlgItem( hDlg, IDC_RANGES );
	
				assert( hWndSrvStamp && hWndList );
				assert( hWndGet && hWndHead && hWndPost && hWndPut );
				assert( hWndDelete && hWndOptions && hWndTrace );
				assert( hWndDescription && hWndAnnotation );
				assert( hWndUploadPath && hWndUploadLimit );
				assert( hWndChunkLimit && hWndRanges );

				assert( pA );
	
				/* --- just for sanity --- */
				::SendMessage( hWndSrvStamp, EM_SETLIMITTEXT, 256, 0 );
				::SendMessage( hWndUploadPath, EM_SETLIMITTEXT, 256, 0 );
				::SendMessage( hWndUploadLimit, EM_SETLIMITTEXT, 256, 0 );
	
				/* --- General --- */
				const char *pVal = M_LookupValue( pConfig, "HTTP", "ServerStamp" );
				::SendMessage( hWndSrvStamp, WM_SETTEXT, 0, (LPARAM)pVal );
				Internal_loadItems( hDlg );

				/* --- General Options --- */
				pVal = M_LookupValue( pConfig, "HTTP", "ChunkLimit" );
				::SendMessage( hWndChunkLimit, BM_SETCHECK, (WPARAM)(pVal[0]), 0 );
				pVal = M_LookupValue( pConfig, "HTTP", "Ranges" );
				::SendMessage( hWndRanges, BM_SETCHECK, (WPARAM)(pVal[0]), 0 );

				/* --- Methods --- */
				int iTmp = atoi(M_LookupValue( pConfig, "HTTP", "Methods" ));
				::SendMessage( hWndGet, BM_SETCHECK, (WPARAM)(iTmp & 1), 0 );
				::SendMessage( hWndHead, BM_SETCHECK, (WPARAM)(iTmp & 2), 0 );
				::SendMessage( hWndPost, BM_SETCHECK, (WPARAM)(iTmp & 4), 0 );
				::SendMessage( hWndPut, BM_SETCHECK, (WPARAM)(iTmp & 8), 0 );
				::SendMessage( hWndDelete, BM_SETCHECK, (WPARAM)(iTmp & 16), 0 );
				::SendMessage( hWndOptions, BM_SETCHECK, (WPARAM)(iTmp & 32), 0 );
				::SendMessage( hWndTrace, BM_SETCHECK, (WPARAM)(iTmp & 64), 0 );

				/* --- Upload Options --- */
				pVal = M_LookupValue( pConfig, "HTTP", "Description" );
				::SendMessage( hWndDescription, BM_SETCHECK, (WPARAM)(pVal[0]), 0 );
				pVal = M_LookupValue( pConfig, "HTTP", "Annotation" );
				::SendMessage( hWndAnnotation, BM_SETCHECK, (WPARAM)(pVal[0]), 0 );
				pVal = M_LookupValue( pConfig, "HTTP", "UploadPath" );
				::SendMessage( hWndUploadPath, WM_SETTEXT, 0, (LPARAM)pVal );
				pVal = M_LookupValue( pConfig, "HTTP", "Limit" );
				::SendMessage( hWndUploadLimit, WM_SETTEXT, 0, (LPARAM)pVal );
			
				iTmp = ::SendMessage( hWndPost, BM_GETCHECK, 0, 0 );
				::EnableWindow( hWndDescription, iTmp );
				::EnableWindow( hWndAnnotation, iTmp );
				::EnableWindow( hWndUploadPath, iTmp );
				::EnableWindow( hWndUploadLimit, iTmp );
	
				Unchanged( hDlg );
				};
				break;
	
			case WM_COMMAND:
				if ( GET_WM_COMMAND_CMD(wParam, lParam)==BN_CLICKED )
					{
					switch( GET_WM_COMMAND_ID( wParam, lParam) )
						{
						case IDC_POST:
							::EnableWindow( hWndDescription,
								::SendMessage( hWndPost, BM_GETCHECK, 0, 0 ));
							::EnableWindow( hWndAnnotation,
								::SendMessage( hWndPost, BM_GETCHECK, 0, 0 ));
							::EnableWindow( hWndUploadPath,
								::SendMessage( hWndPost, BM_GETCHECK, 0, 0 ));
							::EnableWindow( hWndUploadLimit,
								::SendMessage( hWndPost, BM_GETCHECK, 0, 0 ));
							Changed( hDlg );
							break;

						case IDC_ADD:
							if ( DialogBoxParam(
		                        tPsp.hInstance,
								MAKEINTRESOURCE( IDD_NEWINDEXFILE ),
								hDlg,
								(DLGPROC)fnNewIndexFileDialogProc,
						        (LPARAM)this
								) )
								{
								::EnableWindow( ::GetDlgItem( hDlg, IDC_REMOVE ),
									::SendMessage( hWndList, LB_GETCOUNT, 0, 0 ));
								Changed( hDlg );
								};
							break;

						case IDC_REMOVE:
							{
							int iSel = ::SendMessage( hWndList, LB_GETCURSEL, 0, 0 );
							if ( iSel==CB_ERR ) { break; };

							::SendMessage( hWndList, LB_DELETESTRING, iSel, 0 );
							int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0);
							if (iSel >= iCount) {
								SendMessage( hWndList, LB_SETCURSEL, iCount-1, 0 );
							} else {
								SendMessage( hWndList, LB_SETCURSEL, iSel, 0 );
							}

							::EnableWindow( ::GetDlgItem( hDlg, IDC_REMOVE ),
								::SendMessage( hWndList, LB_GETCOUNT, 0, 0 ));
							Changed( hDlg );
							}
						break;

						default:;
						};

					/* --- mark property sheet as modified --- */
					Changed( hDlg );
					}
			if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE )
				{
				/* --- mark property sheet as modified --- */
				Changed( hDlg );
				}
			if ( GET_WM_COMMAND_CMD(wParam, lParam)==BN_CLICKED )
				{
				/* --- mark property sheet as modified --- */
				Changed( hDlg );
				}
			break;
	
			case WM_DESTROY:
				break;
	
			case WM_NOTIFY:
				switch( ((NMHDR *)lParam)->code )
					{
					case PSN_QUERYCANCEL:
						return SHEET->Cancel(pInterface, hDlg);
					
					case PSN_KILLACTIVE:
						{
						/* --- General --- */
						*szBuf = '\0';
						::SendMessage( hWndSrvStamp, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "HTTP", "ServerStamp", szBuf ); 
	
						M_DeleteValue( pConfig, "HTTP", "IndexFile" ); 
						int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0);
						int iTmp = 0;
						for (;iTmp<iCount;iTmp++)
							{
							*szBuf = '\0';
							SendMessage( hWndList, LB_GETTEXT, iTmp, (LPARAM)szBuf );
							M_AddValue( pConfig, "HTTP", "IndexFile", szBuf ); 
							}

						/* --- General Options --- */
						if ( ::SendMessage( hWndChunkLimit, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{ M_ReplaceValue( pConfig, "HTTP", "ChunkLimit", "8192" ); }
						else
							{ M_ReplaceValue( pConfig, "HTTP", "ChunkLimit", "" ); };

						if ( ::SendMessage( hWndRanges, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{ M_ReplaceValue( pConfig, "HTTP", "Ranges", "bytes" ); }
						else
							{ M_ReplaceValue( pConfig, "HTTP", "Ranges", "" ); };

						/* --- Methods --- */
						iTmp = 0;
						if ( ::SendMessage( hWndGet, BM_GETCHECK, 0, 0 ))
							{ iTmp += 1; };
						if ( ::SendMessage( hWndHead, BM_GETCHECK, 0, 0 ))
							{ iTmp += 2; };
						if ( ::SendMessage( hWndPost, BM_GETCHECK, 0, 0 ))
							{ iTmp += 4; };
						if ( ::SendMessage( hWndPut, BM_GETCHECK, 0, 0 ))
							{ iTmp += 8; };
						if ( ::SendMessage( hWndDelete, BM_GETCHECK, 0, 0 ))
							{ iTmp += 16; };
						if ( ::SendMessage( hWndOptions, BM_GETCHECK, 0, 0 ))
							{ iTmp += 32; };
						if ( ::SendMessage( hWndTrace, BM_GETCHECK, 0, 0 ))
							{ iTmp += 64; };
						M_ReplaceValue( pConfig, "HTTP", "Methods",
							itoa(iTmp, szBuf, 10));

						/* --- Upload Options --- */
						if ( ::SendMessage( hWndDescription, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{ M_ReplaceValue( pConfig, "HTTP", "Description", "On" ); }
						else
							{ M_ReplaceValue( pConfig, "HTTP", "Description", "" ); };

						if ( ::SendMessage( hWndAnnotation, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{ M_ReplaceValue( pConfig, "HTTP", "Annotation", "On" ); }
						else
							{ M_ReplaceValue( pConfig, "HTTP", "Annotation", "" ); };

						*szBuf = '\0';
						::SendMessage( hWndUploadPath, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "HTTP", "UploadPath", szBuf ); 

						*szBuf = '\0';
						::SendMessage( hWndUploadLimit, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "HTTP", "UploadLimit", szBuf ); 
	
						SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
						return (TRUE);
						}
	
					case PSN_APPLY:
						return SHEET->SaveConfig(pInterface, hDlg);

					default:
						return (FALSE);
					};
				break;
	
			default:
					return (FALSE);
			};
	
		return (TRUE);
		}
};

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK fnDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
    LPARAM lParam)
{
    if ( uMsg==WM_INITDIALOG )
        {
        ::SetWindowLong( hDlg, DWL_USER, ((LPPROPSHEETPAGE)lParam)->lParam );
        };

    HttpPage *pPage = (HttpPage *)::GetWindowLong( hDlg, DWL_USER );
    return pPage ? pPage->DialogProc( hDlg, uMsg, wParam, lParam ) : FALSE;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK fnNewIndexFileDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
    LPARAM lParam)
{
    if ( uMsg==WM_INITDIALOG )
        {
        ::SetWindowLong( hDlg, DWL_USER, lParam );
        };

    HttpPage *pPage = (HttpPage *)::GetWindowLong( hDlg, DWL_USER );
    return pPage ? pPage->NewIdxFileDialogProc( hDlg, uMsg, wParam, lParam ) :
        FALSE;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int HttpPage_constructor( PIObject *pObj,
	int iArgc, const char *ppArgv[] )
{
	return IFaceBase_constructor( pObj, PI_NEW( HttpPage( pObj,
		iArgc, ppArgv ) ) );
}

#if 0
/*___+++CNF_BEGIN+++___*/
	<Class>
		Name HttpPageClass
		Type LogicExtension
		Library IntrFace
		OnClassLoad IFaceBase_onClassLoad
		Constructor HttpPage_constructor
		CopyConstructor IFaceBase_copyConstructor
		Destructor IFaceBase_destructor
		Execute IFaceBase_execute
	</Class>

	<Object>
		Name HttpPage
		Class HttpPageClass
	</Object>

/*___+++CNF_END+++___*/
#endif

⌨️ 快捷键说明

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