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

📄 users.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			return 1;
		}
	}
	for(iTmp=0;; iTmp++ ) {
		const char *pTmp = AD_lookupValueEx( __pConfig, "Realms", "Ntlm", 
			iTmp );
		if ( !pTmp ) { break; };

		if (!strcmp(pTmp,pName)) {
			strcpy(pName, "Ntlm");
			return 1;
		}
	}
	return 0;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static void Internal_saveItems( const char *pRealm )
{
	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];

	assert( pRealm );

	int i;
	int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
	/*
	** Save all user types
	*/

	/*
	** No users for Ntlm authentication
	*/
	strcpy(szBuf, pRealm);
	if ( Internal_findMethod( szBuf ) && strcmp(szBuf,"Ntlm"))
		{
		/*
		** Basic authentication
		*/
		if (!strcmp(szBuf,"Basic"))
			{
			/* --- remove old ones first --- */
			PIString sSection( "__" );
			sSection.Concatenate( pRealm );
			AD_deleteValue( __pConfig, sSection, "Base64" );
			for( i=0; i<iCount; i++ )
				{
				*szBuf = '\0';
				szBuf[BUF_SIZE] = '\0';
				SendMessage( hWndList, LB_GETTEXT, i, (LPARAM)szBuf );

				int iLen = strlen( szBuf );
				int j;
				for( j=0; j<iLen && szBuf[j]!='\t'; j++ );
				if ( szBuf[j]=='\t' ) { szBuf[j] = ':'; };
				PIString sBase64;
				Base64Encode( szBuf, sBase64 );
		
				AD_addValue( __pConfig, sSection, "Base64", sBase64 );
				};
			}
		/*
		** Digest authentication
		*/
		else
			{
			/* --- remove old ones first --- */
			PIString sSection( "__" );
			sSection.Concatenate( pRealm );
			AD_deleteValue( __pConfig, sSection, "Digest" );
			for( i=0; i<iCount; i++ )
				{
				*szBuf = '\0';
				szBuf[BUF_SIZE] = '\0';
				SendMessage( hWndList, LB_GETTEXT, i, (LPARAM)szBuf );
				AD_addValue( __pConfig, sSection, "Digest", szBuf );
				};
			}
		}
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static HWND __hWndDlgOK = 0;
static HWND __hWndDlgRealm = 0;
static HWND __hWndDlgBasic = 0;
static HWND __hWndDlgDigest = 0;
static HWND __hWndDlgNtlm = 0;
static BOOL CALLBACK NewRealmDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
	LPARAM lParam)
{
	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];

	switch (uMsg)
		{
		case WM_INITDIALOG:
			__hWndDlgOK = GetDlgItem( hDlg, IDOK );
			__hWndDlgRealm = GetDlgItem( hDlg, IDC_REALM );
			__hWndDlgBasic = GetDlgItem( hDlg, IDC_BASIC );
			__hWndDlgDigest = GetDlgItem( hDlg, IDC_DIGEST );
			__hWndDlgNtlm = GetDlgItem( hDlg, IDC_NTLM );
			assert( __hWndDlgOK && __hWndDlgRealm );
			SendMessage( __hWndDlgRealm, EM_SETLIMITTEXT, 256, 0 );
			EnableWindow( __hWndDlgOK, FALSE );
			SendMessage( __hWndDlgBasic, BM_SETCHECK, BST_CHECKED, 0 );

			/*
			** Enable NTLM authentication only for NT systems
			*/
			EnableWindow( __hWndDlgNtlm,
				!strcmp( AD_lookupValue(__pConfig,"General","OS"),"NT" ));
			break;

		case WM_COMMAND:
			switch (GET_WM_COMMAND_ID(wParam, lParam))
				{
				case IDOK:
					{
					/*
					** Validate content of edit field
					*/
					*szBuf = '\0';
					SendMessage( __hWndDlgRealm, WM_GETTEXT, BUF_SIZE, 
						(LPARAM)szBuf );
					PIString sRealm( szBuf );
					int i;
					int iCount = SendMessage( hWndRealm, CB_GETCOUNT, 0, 0 );
					for( i=0; i<iCount; i++ )
						{
						*szBuf = '\0';
						SendMessage( hWndRealm, CB_GETLBTEXT, i, (LPARAM)szBuf );
						if ( sRealm == szBuf )
							{
							sprintf( szBuf, "Realm '%s' already exists.",
								(const char *)sRealm );
							MessageBox( hDlg, szBuf, "New Realm",
								MB_OK | MB_ICONEXCLAMATION );
							return (TRUE);
							};
						};

					/*
					** Can't use '(none)'
					*/
					if ( !stricmp( sRealm, "(none)" ) )
						{
						sprintf( szBuf, "'%s' is a reserved realm.",
							(const char *)sRealm );
						::MessageBox( hDlg, szBuf,  "Remove Realm",
							MB_OK | MB_ICONEXCLAMATION );
						::SetFocus( __hWndDlgRealm );
						::SendMessage( __hWndDlgRealm, EM_SETSEL, 0, -1 );
						return (TRUE);
						};

					/*
					** Add new realm
					*/
					SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)(const char *)sRealm );
					*szBuf = '\0';
					
					if (SendMessage( __hWndDlgBasic, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) {
						strcpy(szBuf, "Basic");
					};
					if (SendMessage( __hWndDlgDigest, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) {
						strcpy(szBuf, "Digest");
					};
					if (SendMessage( __hWndDlgNtlm, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) {
						strcpy(szBuf, "Ntlm");
					};

					AD_addValue( __pConfig, "Realms", szBuf, (const char *)sRealm );
					SendMessage( hWndMethod, WM_SETTEXT, 0,	(LPARAM)szBuf );

					/*
					** Save old items
					*/
					*szBuf = '\0';
					SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
					Internal_saveItems( szBuf );

					int iSel = SendMessage( hWndRealm, CB_FINDSTRINGEXACT, (WPARAM)-1, 
						(LPARAM)(const char *)sRealm );
					if ( iSel!=CB_ERR )
						{
						SendMessage( hWndRealm, CB_SETCURSEL, iSel, 0 ); 
						if ( SendMessage( hWndRealm, CB_GETCURSEL, 0, 0 )!=
							CB_ERR )
							{
							EnableWindow( hWndUser, TRUE );
							EnableWindow( hWndPassword, TRUE );
							EnableWindow( hWndConfirm, TRUE );
							};
						Internal_loadItems( sRealm );
						}		
					else
						{ assert( 0 ); };

					};
					EndDialog( hDlg, 1 );
					break;

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

				case IDC_REALM:
					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);
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
	LPARAM lParam)
{
	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];
	szBuf[BUF_SIZE]='\0';
	int aTabstop[2];
 
	switch (uMsg)
		{
		case WM_INITDIALOG:
			AD_hourglassOn();
			{
			hWndRealm = GetDlgItem( hDlg, IDC_REALM );
			hWndList = GetDlgItem( hDlg, IDC_LIST );
			hWndUser = GetDlgItem( hDlg, IDC_USER );
			hWndPassword = GetDlgItem( hDlg, IDC_PASSWORD );
			hWndConfirm = GetDlgItem( hDlg, IDC_CONFIRM );
			hWndAdd = GetDlgItem( hDlg, IDC_ADD );
			hWndReplace = GetDlgItem( hDlg, IDC_REPLACE );
			hWndDelete = GetDlgItem( hDlg, IDC_DELETE );
			hWndMethod = GetDlgItem( hDlg, IDC_AUTHMETHOD );

			assert( hWndRealm && hWndList && hWndUser && hWndPassword );
			assert( hWndConfirm && hWndAdd && hWndReplace && hWndDelete );

			EnableWindow( hWndAdd, FALSE );
			EnableWindow( hWndReplace, FALSE );
			EnableWindow( hWndDelete, FALSE );

			/*
			** Limit edit field lengths, really just a sanity thing
			*/
			SendMessage( hWndUser, EM_SETLIMITTEXT, 256, 0 );
			SendMessage( hWndPassword, EM_SETLIMITTEXT, 256, 0 );
			SendMessage( hWndConfirm, EM_SETLIMITTEXT, 256, 0 );

			/*
			** Setup tabstops
			*/
			aTabstop[0] = 0;
			aTabstop[1] = 750;
			SendMessage( hWndList, LB_SETTABSTOPS, 2, (LPARAM)&aTabstop );

			/*
			** Load all realms into realm box
			*/
			for(int iTmp = 0;; iTmp++ ) {
				const char *pTmp = AD_lookupValueEx( __pConfig, "Realms", "Basic", iTmp );
				if ( !pTmp ) { break; };
				SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)pTmp );
			};
			for(iTmp = 0;; iTmp++ ) {
				const char *pTmp = AD_lookupValueEx( __pConfig, "Realms", "Digest", iTmp );
				if ( !pTmp ) { break; };
				SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)pTmp );
			};
			for(iTmp = 0;; iTmp++ ) {
				const char *pTmp = AD_lookupValueEx( __pConfig, "Realms", "Ntlm", iTmp );
				if ( !pTmp ) { break; };
				SendMessage( hWndRealm, CB_ADDSTRING, 0, (LPARAM)pTmp );
			};

			/*
			** Load all users into realm box
			*/
			if ( SendMessage( hWndRealm, CB_GETCOUNT, 0, 0 )>0 )
				{
				SendMessage( hWndRealm, CB_SETCURSEL, 0, 0 );
				*szBuf = '\0';
				SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );

				/*
				** Load items into list box
				*/
				Internal_loadItems( szBuf );

				/*
				** update static method text for realm
				*/
				if ( Internal_findMethod( szBuf ))
					{
					SendMessage( hWndMethod, WM_SETTEXT, 0,
						(LPARAM)szBuf );
					if (!strcmp(szBuf,"Ntlm"))
						{
						EnableWindow( hWndUser, FALSE);
						EnableWindow( hWndPassword, FALSE );
						EnableWindow( hWndConfirm, FALSE );
						}
					}
				}
			else
				{
				/* --- no realms, disable edit fields --- */
				EnableWindow( hWndUser, FALSE );
				EnableWindow( hWndPassword, FALSE );
				EnableWindow( hWndConfirm, FALSE );
				};
			}
			AD_hourglassOff();
			break;

		case WM_DESTROY:
			{ Internal_clearArrays(); };
			break;

		case WM_COMMAND:
			switch (GET_WM_COMMAND_ID(wParam, lParam))
				{
				case IDC_REALM:
					switch( GET_WM_COMMAND_CMD(wParam, lParam) )
						{
						case CBN_DROPDOWN:
							/*
							** Save current realm users
							*/
							*szBuf = '\0';
							SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE, 
								(LPARAM)szBuf );
							Internal_saveItems( szBuf );
							break;

						case CBN_SELCHANGE:
							/*
							** Load new realm users
							*/
							*szBuf = '\0';
							SendMessage( hWndRealm, WM_GETTEXT, 
								BUF_SIZE, (LPARAM)szBuf );
							if ( SendMessage( hWndRealm, CB_GETCURSEL, 0, 0 )!=
								CB_ERR )
								{
								EnableWindow( hWndUser, TRUE );
								EnableWindow( hWndPassword, TRUE );
								EnableWindow( hWndConfirm, TRUE );
								};
							Internal_loadItems( szBuf );

							/*
							** update static method text for realm
							*/
							if ( Internal_findMethod( szBuf ))

⌨️ 快捷键说明

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