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

📄 cspace_isapi.c

📁 开源的OpenId的一个java实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <httpext.h>
#include <httpfilt.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#define POST_METHOD "post"

#define INTERNET_MAX_PATH_LENGTH        2048
#define INTERNET_MAX_SCHEME_LENGTH      32          // longest protocol name length
#define INTERNET_MAX_URL_LENGTH         (INTERNET_MAX_SCHEME_LENGTH \
                                        + sizeof("://") \
                                        + INTERNET_MAX_PATH_LENGTH)

#define EXTENSION_URL					"/test_folder/cspace_isapi.dll"
#define LOGON_URL						"/Logon"
#define LOGOFF_URL						"/Logoff"

#define FOLDER_NAME_HEADER				"CSPACE-FOLDER-NAME:"
#define ORIGINAL_URL					"CSPACE-ORI-URL:"
#define HTTP_FOLDER_NAME_HEADER			"HTTP_CSPACE_FOLDER_NAME"
#define HTTP_ORIGINAL_URL				"HTTP_CSPACE_ORI_URL"

#define HTML_ERROR_400          "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"  \
                                "<HTML><HEAD><TITLE>Bad request!</TITLE></HEAD>"                    \
                                "<BODY><H1>Bad request!</H1><DL><DD>\n"                             \
                                "Your browser (or proxy) sent a request that "                      \
                                "this server could not understand.</DL></DD></BODY></HTML>"

#define HTML_ERROR_404          "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"  \
                                "<HTML><HEAD><TITLE>Object not found!</TITLE></HEAD>"               \
                                "<BODY><H1>The requested URL was not found on this server"          \
                                "</H1><DL><DD>\nIf you entered the URL manually please check your"  \
                                "spelling and try again.</DL></DD></BODY></HTML>"

typedef struct config_s {
	char *name;
	char *value;
} config_t;

char *folders[] = {"/test/", "/test1/t/"};
const int no_folders = 2;

static int start_response(EXTENSION_CONTROL_BLOCK *pECB,
                                    int status,
                                    const char *reason,
                                    const char *const *header_names,
                                    const char *const *header_values,
                                    unsigned int num_of_headers);

static char *status_reason(int status);
int read_client (EXTENSION_CONTROL_BLOCK *pECB, char *buffer, size_t *size);
void WINAPI HandleExecUrlCompletion(EXTENSION_CONTROL_BLOCK *pECB, void * pContext, DWORD cbIO, DWORD dwError);

BOOL WINAPI DllMain(IN HINSTANCE hinstDll, IN DWORD dwReason, IN LPVOID lpvContext) 
{ 
	// Note that appropriate initialization and termination code 
	// would usually be written within the switch statement below. But because 
	// this example is very simple, no initialization and termination code is  needed. 
	switch(dwReason) { 
		case DLL_PROCESS_ATTACH : 
			break; 
		case DLL_PROCESS_DETACH : 
			break; 
	} 
	return TRUE; 
} 



BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer) 
{
	DWORD rc = FALSE;
    ULONG http_filter_revision = HTTP_FILTER_REVISION;
    pVer->dwFilterVersion = pVer->dwServerFilterVersion;
    if (pVer->dwFilterVersion > http_filter_revision) {
        pVer->dwFilterVersion = http_filter_revision;
    }

	/*
	Receive notifictions when
		1. Server preprocessed the headers.
		2. Log 
		3. All the request coming in secure and none secure ports.
	*/
	pVer->dwFlags = (SF_NOTIFY_ORDER_LOW |
                    SF_NOTIFY_SECURE_PORT |
                    SF_NOTIFY_NONSECURE_PORT |
                    SF_NOTIFY_PREPROC_HEADERS |
                    SF_NOTIFY_LOG |
                    SF_NOTIFY_AUTH_COMPLETE
					);

	// Give a short discription about the module.
	strcpy(pVer->lpszFilterDesc, "axis2c filter");
	
	return TRUE;
}

DWORD WINAPI HttpFilterProc(
		PHTTP_FILTER_CONTEXT pfc,
		DWORD notificationType,
		LPVOID pvNotification)
{		

	int i = 0;
	size_t length = 0, j = 0;
	BOOL matched = TRUE;
	char org_url[INTERNET_MAX_URL_LENGTH] = {0};
	char redi_url[INTERNET_MAX_URL_LENGTH] = {0};
	int ret_val = INTERNET_MAX_URL_LENGTH;
	int temp = 0;
	switch (notificationType){
		case SF_NOTIFY_PREPROC_HEADERS:						
			if(temp = ((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->GetHeader(pfc, "url", org_url, &ret_val)){				
				for (i = 0; i < no_folders; i++) {
					length = strlen(folders[i]);
					matched = TRUE;
					for (j = 0; j < length; j++){
						if (folders[i][j] != org_url[j]) {
							matched = FALSE;
						}
					}
					if (matched) {
						strcpy(redi_url, EXTENSION_URL);
						//strcat(redi_url, (char *)(org_url + length));						
						if(!((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->SetHeader(pfc, "url", redi_url)){												
							return SF_STATUS_REQ_ERROR;
						}
						if(!((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->AddHeader(pfc, FOLDER_NAME_HEADER, folders[i])){
							return SF_STATUS_REQ_ERROR;
						}
						if(!((PHTTP_FILTER_PREPROC_HEADERS)pvNotification)->AddHeader(pfc, ORIGINAL_URL, org_url)){
							return SF_STATUS_REQ_ERROR;
						}
						return SF_STATUS_REQ_HANDLED_NOTIFICATION;
					}
				}
			}
			break;				
		default:
			break;
	}
	return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


BOOL WINAPI TerminateFilter(DWORD dwfalgs)
{
	return TRUE;	
}

BOOL init_module ()
{
	return TRUE;
}

BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) 
{ 
	pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR); 

	strcpy(pVer->lpszExtensionDesc, "IIS for Testing"); 

	return TRUE; 
} 


DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB) 
{ 	
	size_t read_bytes = 0;
	char *buffer = NULL;
	char https[8];
	int buffer_size = 8;
	char *ori_url = NULL;
	int ret_val = 0;
	HSE_EXEC_URL_INFO *exec_url_info;

	if (_stricmp(pECB->lpszMethod, POST_METHOD)) {
		start_response(pECB, 403, NULL, NULL, NULL, 0);
		return HSE_STATUS_ERROR;
	}
	
	if (!pECB->GetServerVariable(pECB->ConnID, "HTTPS", https, &buffer_size)){
		return HSE_STATUS_ERROR;
	}

	if (_stricmp("ON", https)){
		start_response(pECB, 403, NULL, NULL, NULL, 0);
		return HSE_STATUS_ERROR;
	}

	buffer = malloc(sizeof(char) * (pECB->cbTotalBytes + 1));
	read_bytes = pECB->cbTotalBytes + 1;
	read_client(pECB, buffer, &read_bytes);

	if (strstr(buffer, "ABC")){
		start_response(pECB, 403, NULL, NULL, NULL, 0);
		return HSE_STATUS_ERROR;													
	} else {
		ori_url = malloc(INTERNET_MAX_URL_LENGTH * sizeof(char));
		ret_val = INTERNET_MAX_URL_LENGTH;
		if (!pECB->GetServerVariable(pECB->ConnID, HTTP_ORIGINAL_URL, ori_url, &ret_val)) {
			start_response(pECB, 403, NULL, NULL, NULL, 0);
			return HSE_STATUS_ERROR;													
		}
		exec_url_info = (HSE_EXEC_URL_INFO *) malloc(sizeof(HSE_EXEC_URL_INFO));
		exec_url_info->pszUrl = ori_url;				
		//We need to set the child headers here
		exec_url_info->pszChildHeaders = NULL;
		exec_url_info->dwExecUrlFlags = HSE_EXEC_URL_IGNORE_CURRENT_INTERCEPTOR;
		// Followng two are inherited from the paren request
		exec_url_info->pszMethod = NULL;
		exec_url_info->pEntity = NULL;
		exec_url_info->pUserInfo = NULL;

		if ( !pECB->ServerSupportFunction( pECB->ConnID,
                                      HSE_REQ_IO_COMPLETION,
                                      HandleExecUrlCompletion,
                                      NULL,
									  NULL )){
			start_response(pECB, 403, NULL, NULL, NULL, 0);
			return HSE_STATUS_ERROR;													
		}
		    
		/* Call ExecUrl */
		if (!pECB->ServerSupportFunction( pECB->ConnID,
										  HSE_REQ_EXEC_URL,
										  exec_url_info,
										  NULL,
										  NULL )){

⌨️ 快捷键说明

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