コード例 #1
0
/*
 *This line is to modify the header
 */
static int mod_modify_s2o_header(HttpStateData* data, HttpHeader* hdr)
{
	assert(data);
	int fd = data->fd;
	int i, len;

	struct mod_conf_param *param = (struct mod_conf_param *)cc_get_mod_param(fd, mod);
	assert(param);

	debug(107, 3)("param->orig_name=%s, param->new_name=%s\n", strBuf(param->orig_name), strBuf(param->new_name));
	HttpHeaderPos pos = HttpHeaderInitPos;
	HttpHeaderEntry *myheader;
	HttpHeaderEntry e;

	while ((myheader = httpHeaderGetEntry(hdr, &pos)))
	{
		debug(107, 3)("myheader=%s, param->new_name=%s\n", strBuf(myheader->name), strBuf(param->new_name));
		if (strCaseCmp(myheader->name, strBuf(param->orig_name)) == 0)
		{
			debug(107, 3)("%s is myheader->value,%s is param->orig_name\n",strBuf(myheader->value), strBuf(param->orig_name));

			if(strLen(myheader->value) >= 4095)
			{
				debug(107, 3)("A too long header value!!\n");
				return -1;
			}

			stringInit(&e.name, strBuf(param->new_name));
			stringInit(&e.value, myheader->value.buf);
			len=strlen(strBuf(e.name));
			i=httpHeaderIdByNameDef(strBuf(e.name), len);
			if(-1 == i)
				e.id = HDR_OTHER;
			else    
				e.id = i;
			httpHeaderDelByName(hdr, strBuf(param->orig_name));
			httpHeaderAddEntry(hdr, httpHeaderEntryClone(&e));
			//httpHeaderDelAt(&request->header, pos);
			//httpHeaderRefreshMask(&request->header);
			//httpHeaderInsertEntry(&request->header, httpHeaderEntryClone(&e), pos);
			stringClean(&e.name);
			stringClean(&e.value);			
			break;
		}
	}
	return 0;

}
コード例 #2
0
/*
 * deletes all fields with a given name if any, returns #fields deleted; 
 */
int
httpHeaderDelByName(HttpHeader * hdr, const char *name)
{
    int count = 0;
    HttpHeaderPos pos = HttpHeaderInitPos;
    HttpHeaderEntry *e;
    httpHeaderMaskInit(&hdr->mask, 0);	/* temporal inconsistency */
    debug(55, 7) ("deleting '%s' fields in hdr %p\n", name, hdr);
    while ((e = httpHeaderGetEntry(hdr, &pos))) {
	if (!strCaseCmp(e->name, name)) {
	    httpHeaderDelAt(hdr, pos);
	    count++;
	} else
	    CBIT_SET(hdr->mask, e->id);
    }
    return count;
}
コード例 #3
0
/* returns 0 on match, -1 if no match */
static inline int strcmparray(const char *str, const char **array)
{
    const char *wgroup;

    while (*array) {
	/* If the groups we want to match are specified as 'group', and
	 * not as 'DOMAIN\group' we strip the domain from the group to
	 * match against */
	if (strstr(*array,"\\") == NULL) {
	    wgroup = strstr(str,"\\") + 1;
	    debug("Stripping domain from group name %s\n", str); 
	} else {
	    wgroup = str;
	}
	
    	debug("Windows group: %s, Squid group: %s\n", wgroup, *array);
	if ((use_case_insensitive_compare ? strCaseCmp(wgroup, *array) : strcmp(wgroup, *array)) == 0)
	    return 0;
	array++;
    }
    return -1;
}
コード例 #4
0
ファイル: Isapi.c プロジェクト: ferrasrl/easyHand
DWORD Isapi_SendHeaderToClient(EXTENSION_CONTROL_BLOCK *pECB,SINT iStatus,char *lpStatus,char *pszFormat, ...)
{
    BOOL fReturn;
    CHAR szHeader[1024] = "";
    DWORD hseStatus = HSE_STATUS_SUCCESS;
	DWORD dwSize;
	HSE_SEND_HEADER_EX_INFO hshe;
	
 	dwSize=(DWORD) strlen(szHeader);
	hshe.pszStatus=(!lpStatus)?"200 OK":lpStatus;
	hshe.cchStatus=(DWORD) strlen(hshe.pszStatus);
	if (!strCaseCmp(pECB->lpszMethod,"HEAD")) 
	{*szHeader=0;}
	else 
	{
		va_list arg_ptr;
		va_start(arg_ptr, pszFormat); 
		vsprintf(szHeader, pszFormat, arg_ptr);
		va_end(arg_ptr);
	}
	hshe.pszHeader=szHeader;
	hshe.cchHeader=(DWORD) strlen(hshe.pszHeader);
	hshe.fKeepConn=FALSE;

	pECB->dwHttpStatusCode=(iStatus==0)?200:iStatus;
	fReturn = 
    pECB->ServerSupportFunction(pECB->ConnID, 
                                HSE_REQ_SEND_RESPONSE_HEADER_EX,
                                &hshe, // Telling the client not to close the connection
                                NULL,
                                NULL);
    if (! fReturn ) {
		//ehLogWrite("HSE_STATUS_ERROR");
        hseStatus = HSE_STATUS_ERROR;
    }
    return (hseStatus);
}
コード例 #5
0
/*
 * Returns the value of the specified header.
 */
String
httpHeaderGetByName(const HttpHeader * hdr, const char *name)
{
    http_hdr_type id;
    HttpHeaderPos pos = HttpHeaderInitPos;
    HttpHeaderEntry *e;
    String result = StringNull;

    assert(hdr);
    assert(name);

    /* First try the quick path */
    id = httpHeaderIdByNameDef(name, strlen(name));
    if (id != -1)
	return httpHeaderGetStrOrList(hdr, id);

    /* Sorry, an unknown header name. Do linear search */
    while ((e = httpHeaderGetEntry(hdr, &pos))) {
	if (e->id == HDR_OTHER && strCaseCmp(e->name, name) == 0) {
	    strListAdd(&result, strBuf(e->value), ',');
	}
    }
    return result;
}
コード例 #6
0
ファイル: testmain.cpp プロジェクト: crishoj/dep_feat
int main(int argc,char **argv)
    {
    FILE * f = fopen("foldingLenghts.txt","wb");
    int cmp = strCaseCmp("MASSE","Maße");
    fprintf(f,"MASSE %s Maße\n",cmp == 0? "==" : cmp < 0 ? "<" : ">");
    for(int y=0;y < 0x11000;++y)
        {
        int L = lowerEquivalent(y);
        int U = upperEquivalent(y);
        if(L == y && U == y)
            continue;
        char buf1[5];
        char buf2[5];
        char buf3[5];
        buf1[UnicodeToUtf8(y,buf1,5)] = '\0';
        buf2[UnicodeToUtf8(L,buf2,5)] = '\0';
        buf3[UnicodeToUtf8(U,buf3,5)] = '\0';
        if(y < 0x80)
            {
            if(L >= 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x>0x80  %x\n",L,y);
                }
            if(U >= 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x>0x80  %x\n",U,y);
                }
            }
        else if(y < 0x800)
            {
            if(L >= 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x>0x800  %x\n",L,y);
                }
            else if(L < 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x<0x80  %x\n",L,y);
                }
            if(U >= 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x>0x800  %x\n",U,y);
                }
            else if(U < 0x80)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x<0x80  %x\n",U,y);
                }
            }
        else if(y < 0x10000)
            {
            if(L >= 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x>0x10000 %x\n",L,y);
                }
            else if(L < 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x<0x800  %x\n",L,y);
                }
            if(U >= 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x>0x10000 %x\n",U,y);
                }
            else if(U < 0x800)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x<0x800  %x\n",U,y);
                }
            }
        else
            {
            if(L < 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"L%x<0x10000  %x\n",L,y);
                }
            if(U < 0x10000)
                {
                fprintf(f,"%s %s %s ",buf1,buf2,buf3);
                fprintf(f,"U%x<0x10000  %x\n",U,y);
                }
            }
        }
    fclose(f);
    return 0;
    }
コード例 #7
0
ファイル: Isapi.c プロジェクト: ferrasrl/easyHand
// Isapi_FilePutOut()
// FALSE = Tutto ok
// TRUE = Errore
BOOL Isapi_FilePutOut(EXTENSION_CONTROL_BLOCK *pECB,SINT iStatus,CHAR *lpStatus,CHAR *lpFile,SINT iMode)
{
	HANDLE hFile;
	DWORD dwSize,dwSizeH,dwSizeR;
	BYTE *lpBuf;
	CHAR szServ[1024];
	 
	hFile=CreateFile(lpFile,
					 GENERIC_READ,
					 FILE_SHARE_READ,//0,//FILE_SHARE_WRITE,
					 NULL,
					 OPEN_EXISTING,
					 FILE_ATTRIBUTE_ARCHIVE//FILE_FLAG_SEQUENTIAL_SCAN
					 ,(HANDLE) NULL);

	if (hFile!=INVALID_HANDLE_VALUE) 
	{
		dwSize=GetFileSize(hFile,&dwSizeH);
		if (dwSize<1) {CloseHandle(hFile); return TRUE;}

		switch (iMode)
		{
		 case 1: // HTML Zippato
			Isapi_SendHeaderToClient(pECB,iStatus,lpStatus,"Content-Type: text/html" CRLF "Content-Encoding: gzip" CRLF "Content-Length: %d" CRLF CRLF,dwSize);
			break;
		 
		 default:
		 case 2: // Html
			//Isapi_SendHeaderToClient(pECB,iStatus,lpStatus,"Content-Type: text/html" "\n\n"); // "Connection:Keep-Alive"
			 Isapi_SendHeaderToClient(pECB,iStatus,lpStatus,
									  "Content-Type: text/html" CRLF 
									  "Content-Length: %d" CRLF CRLF
						//			  "Connection:Keep-Alive\n"
									  ,dwSize);
			break;

		 case 3: // Jpg
			Isapi_SendHeaderToClient(pECB,iStatus,lpStatus,"Content-Type: image/jpeg" CRLF "Content-Length: %d" CRLF CRLF ,dwSize);
			break;

		 case 4: // Html
			 Isapi_SendHeaderToClient(pECB,iStatus,lpStatus,
									  "Content-Type: text/html" CRLF 
									  "Content-Length: %d" CRLF CRLF 
									  ,dwSize);
			break;
		}

		lpBuf=ehAlloc(dwSize); 
		if (!lpBuf) // No ho memoria
		{
			CloseHandle(hFile);	return TRUE;
		}

		if (ReadFile(hFile,lpBuf,dwSize,&dwSizeR,NULL))
		{
			if (strCaseCmp(pECB->lpszMethod,"HEAD")) // Non sono HEAD
				pECB->WriteClient(pECB->ConnID, lpBuf, &dwSizeR, 0); // Sparo fuori ...
		} 
		else 
		{
			ehFree(lpBuf);
			CloseHandle(hFile);
			return TRUE;
		}

		ehFree(lpBuf);
		CloseHandle(hFile);
		return FALSE;
	}
	else 
	{
		BYTE *lpError=osErrorStr(osGetError(),szServ,sizeof(szServ));
		ehLogWrite("Isapi_FilePutOut(): %s - Errore: %d : %s\n%s",lpFile,GetLastError(),lpError);
		ehFreeNN(lpError);
		return TRUE;
	}
}
コード例 #8
0
ファイル: mod_header.c プロジェクト: selecli/squid
/*
 *?????Ǵ????޸ġ?????һ??header?Ĵ??�??
 */
static int modifyHeader3(struct action_part* acp, HttpReply* reply)
{
	assert(acp);
	assert(reply);

	int flag = 0;
	int act = acp->action;
	struct header_info* hdr = acp->hdr;
	HttpHeaderEntry e;
	//HttpHeaderEntry *mye;
	int i;
	HttpHeaderEntry *myheader;
	HttpHeaderPos pos = HttpHeaderInitPos + HDR_ENUM_END;
	e.name = stringDup(&hdr->header);
	e.value = stringDup(&hdr->value);
	i = httpHeaderIdByNameDef(strBuf(hdr->header), strLen(hdr->header));
	e.id = i;
	if(i == -1)
	{
		e.id = HDR_OTHER;
		if(0 == act)
		{
			httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
		else if(2 == act)
		{
			while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) 
			{
				if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0)
				{
					debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value));
					stringReset(&myheader->value, strBuf(hdr->value));

				}
			}
		}
		else if(1 == act)
		{
			httpHeaderDelByName(&reply->header,strBuf(hdr->header));
		}
		else if(3 == act)
		{
			while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) 
			{
				if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0)
				{
					debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value));
					flag = 1;
					stringReset(&myheader->value, strBuf(hdr->value));

				}
			}
			
			if(!flag)
				httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
	}
	else
	{
		//mye = httpHeaderFindEntry2(&reply->header, i);
		//debug(98, 3) ("%d is i\n", i);

		if(0 == act)
		{
			httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
		else if(2 == act)
		{
			if(httpHeaderDelByName(&reply->header,strBuf(hdr->header)))
			{
				httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
			}
			//mye = httpHeaderFindEntry2(&reply->header, i);
			//debug(98, 3)("%s is newvalue\n",strBuf(mye->value));
		}
		else if(1 == act)
		{
			httpHeaderDelByName(&reply->header,strBuf(hdr->header));
		}
		else if(3 == act)
		{
			httpHeaderDelByName(&reply->header,strBuf(hdr->header));
			httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
	}
	stringClean(&e.name);
	stringClean(&e.value);

	return 0;
}