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

📄 cspace_isapi.c

📁 开源的OpenId的一个java实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	        start_response(pECB, 403, NULL, NULL, NULL, 0);
			return HSE_STATUS_ERROR;													
		}		
		/* Since EXEC_URL is asynchonous, we need to return STATUS_PENDING.*/
		return HSE_STATUS_PENDING;
	}
	return HSE_STATUS_SUCCESS; 
} 


void WINAPI HandleExecUrlCompletion(EXTENSION_CONTROL_BLOCK *pECB, void * pContext, DWORD cbIO, DWORD dwError)
{    
	/*Done*/
    pECB->ServerSupportFunction( pECB->ConnID, HSE_REQ_DONE_WITH_SESSION, NULL, NULL, NULL );
	return;
}

BOOL WINAPI TerminateExtension(DWORD dwFlags)
{
	return TRUE;
}

int read_client (EXTENSION_CONTROL_BLOCK *pECB, char *buffer, size_t *size)
{
	int read = 0;
	int need_to_read = 0;
	int temp = 0;
	if (pECB->cbAvailable == pECB->cbTotalBytes){
		if (*size >= pECB->cbAvailable){
			memcpy (buffer, pECB->lpbData, pECB->cbAvailable);						
		} else {
			memcpy (buffer, pECB->lpbData, pECB->cbAvailable);
		}
	} 
	else if (pECB->cbAvailable < pECB->cbTotalBytes){
		memcpy( buffer, pECB->lpbData, pECB->cbAvailable);
		need_to_read = pECB->cbTotalBytes - pECB->cbAvailable;
		while ( read != need_to_read){
			pECB->ReadClient(pECB->ConnID, buffer + read, &temp);
			read += temp;
		}
	}
	return 1;
}

int write_response(EXTENSION_CONTROL_BLOCK *pECB, const void *b, unsigned int l)
{    
    if (pECB && b) {
        if (l) {
            unsigned int written = 0;
            char *buf = (char *)b;
			// If couldn't write the data at onece try again until all the data is written.
            while (written < l) {
                DWORD try_to_write = l - written;
                if (!pECB->WriteClient(pECB->ConnID,
                                           buf + written, &try_to_write, 0)) {
                    return 0;
                }
                written += try_to_write;
            }
        }        
        return 1;
    }    
    return 0;
}


static char *status_reason(int status)
{
    static struct reasons {
        int status;
        char *reason;
    } *r, reasons[] = {
        { 100, "Continue" },
        { 101, "Switching Protocols" },
        { 200, "OK" },
        { 201, "Created" },
        { 202, "Accepted" },
        { 203, "Non-Authoritative Information" },
        { 204, "No Content" },
        { 205, "Reset Content" },
        { 206, "Partial Content" },
        { 300, "Multiple Choices" },
        { 301, "Moved Permanently" },
        { 302, "Moved Temporarily" },
        { 303, "See Other" },
        { 304, "Not Modified" },
        { 305, "Use Proxy" },
        { 400, "Bad Request" },
        { 401, "Unauthorized" },
        { 402, "Payment " },
        { 403, "Forbidden" },
        { 404, "Not Found" },
        { 405, "Method Not Allowed" },
        { 406, "Not Acceptable" },
        { 407, "Proxy Authentication Required" },
        { 408, "Request Timeout" },
        { 409, "Conflict" },
        { 410, "Gone" },
        { 411, "Length Required" },
        { 412, "Precondition Failed" },
        { 413, "Request Entity Too Large" },
        { 414, "Request-URI Too Long" },
        { 415, "Unsupported Media Type" },
        { 500, "Internal Server Error" },
        { 501, "Not Implemented" },
        { 502, "Bad Gateway" },
        { 503, "Service Unavailable" },
        { 504, "Gateway Timeout" },
        { 505, "HTTP Version Not Supported" },
        { 000, NULL}
    };

    r = reasons;
    while (r->status <= status)
        if (r->status == status)
            return r->reason;
        else
            r++;
    return "No Reason";
}

static int process_logon(EXTENSION_CONTROL_BLOCK *pECB)
{
	
	return FALSE;
}

static int process_logoff(EXTENSION_CONTROL_BLOCK *pECB)
{

	return FALSE;
}


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 crlf[3] = { (char)13, (char)10, '\0' };

    if (status < 100 || status > 1000) {        
        return FALSE;
    }

    if (pECB) {                
        size_t len_of_status;
        char *status_str;
        char *headers_str;

         /*
         * Create the status line
         */
        if (!reason) {
            reason = status_reason(status);
        }
        status_str = (char *)_alloca((6 + strlen(reason)) * sizeof(char));
        sprintf(status_str, "%d %s", status, reason);
        len_of_status = strlen(status_str);

		/*
		 * Create response headers string
		 */
		if (num_of_headers) {
			size_t i, len_of_headers;
			for (i = 0, len_of_headers = 0; i < num_of_headers; i++) {
				len_of_headers += strlen(header_names[i]);
				len_of_headers += strlen(header_values[i]);
				len_of_headers += 4;        /* extra for colon, space and crlf */
			}

			len_of_headers += 3;    /* crlf and terminating null char */
			headers_str = (char *)_alloca(len_of_headers * sizeof(char));
			headers_str[0] = '\0';

			for (i = 0; i < num_of_headers; i++) {
				strcat(headers_str, header_names[i]);
				strcat(headers_str, ": ");
				strcat(headers_str, header_values[i]);
				strcat(headers_str, crlf);
			}
			strcat(headers_str, crlf);
		}
		else {
			headers_str = crlf;
		}

        if (!pECB->ServerSupportFunction(pECB->ConnID,
                                             HSE_REQ_SEND_RESPONSE_HEADER,
                                             status_str,
                                             (LPDWORD) &len_of_status,
                                             (LPDWORD) headers_str)) {            
            return FALSE;
        }        
        return TRUE;

    }

    return FALSE;
}

BOOL create_cookie(char *buffer, int buf_size, char **names, 
				   char **values, int name_val, 
				   char *exp_date, char *domain, 
				   char *path, char *secure)
{
	int i = 0;
	int cur_buf_pos = 0;
	if (buffer && buf_size)
	{
		buffer[0] = '\0';
		if (name_val || exp_date || domain || path || secure){
			strcat(buffer, "Set-Cookie:");
			cur_buf_pos += (int)strlen("Set-Cookie:");
		} 
		else {
			return FALSE;
		}

		for(i = 0;i < name_val;i++){
			strcat(buffer + cur_buf_pos, names[i]);
			cur_buf_pos += (int)strlen(names[i] + 1);
			strcat(buffer + cur_buf_pos, ";");
			cur_buf_pos++;
		}	

		if (exp_date){
			sprintf(buffer + cur_buf_pos, "%s%s%s", "expires=", exp_date, ";");
			cur_buf_pos += (int)strlen("expires=") + (int)strlen(exp_date) + 1;
		}
		if (domain){
			sprintf(buffer + cur_buf_pos, "%s%s%s", "domain=", domain, ";");
			cur_buf_pos += (int)strlen("domain=") + (int)strlen(domain) + 1;
		}
		if (path){
			sprintf(buffer + cur_buf_pos, "%s%s%s", "path=", path, ";");
			cur_buf_pos += (int)strlen("path=") + (int)strlen(path) + 1;			
		}
		if (secure){
			strcat(buffer + cur_buf_pos, secure);
		}
	}
	return TRUE;
}

⌨️ 快捷键说明

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