Commit e9749651 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Directly return error status from HTTP_HttpAddRequestHeadersW.

parent 85a057e1
...@@ -200,9 +200,9 @@ static CRITICAL_SECTION authcache_cs = { &critsect_debug, -1, 0, 0, 0, 0 }; ...@@ -200,9 +200,9 @@ static CRITICAL_SECTION authcache_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
static DWORD HTTP_OpenConnection(http_request_t *req); static DWORD HTTP_OpenConnection(http_request_t *req);
static BOOL HTTP_GetResponseHeaders(http_request_t *req, BOOL clear); static BOOL HTTP_GetResponseHeaders(http_request_t *req, BOOL clear);
static BOOL HTTP_ProcessHeader(http_request_t *req, LPCWSTR field, LPCWSTR value, DWORD dwModifier); static DWORD HTTP_ProcessHeader(http_request_t *req, LPCWSTR field, LPCWSTR value, DWORD dwModifier);
static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer); static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer);
static BOOL HTTP_InsertCustomHeader(http_request_t *req, LPHTTPHEADERW lpHdr); static DWORD HTTP_InsertCustomHeader(http_request_t *req, LPHTTPHEADERW lpHdr);
static INT HTTP_GetCustomHeaderIndex(http_request_t *req, LPCWSTR lpszField, INT index, BOOL Request); static INT HTTP_GetCustomHeaderIndex(http_request_t *req, LPCWSTR lpszField, INT index, BOOL Request);
static BOOL HTTP_DeleteCustomHeader(http_request_t *req, DWORD index); static BOOL HTTP_DeleteCustomHeader(http_request_t *req, DWORD index);
static LPWSTR HTTP_build_req( LPCWSTR *list, int len ); static LPWSTR HTTP_build_req( LPCWSTR *list, int len );
...@@ -884,14 +884,13 @@ static BOOL HTTP_DoAuthorization( http_request_t *lpwhr, LPCWSTR pszAuthValue, ...@@ -884,14 +884,13 @@ static BOOL HTTP_DoAuthorization( http_request_t *lpwhr, LPCWSTR pszAuthValue,
/*********************************************************************** /***********************************************************************
* HTTP_HttpAddRequestHeadersW (internal) * HTTP_HttpAddRequestHeadersW (internal)
*/ */
static BOOL HTTP_HttpAddRequestHeadersW(http_request_t *lpwhr, static DWORD HTTP_HttpAddRequestHeadersW(http_request_t *lpwhr,
LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
{ {
LPWSTR lpszStart; LPWSTR lpszStart;
LPWSTR lpszEnd; LPWSTR lpszEnd;
LPWSTR buffer; LPWSTR buffer;
BOOL bSuccess = FALSE; DWORD len, res = ERROR_HTTP_INVALID_HEADER;
DWORD len;
TRACE("copying header: %s\n", debugstr_wn(lpszHeader, dwHeaderLength)); TRACE("copying header: %s\n", debugstr_wn(lpszHeader, dwHeaderLength));
...@@ -930,25 +929,25 @@ static BOOL HTTP_HttpAddRequestHeadersW(http_request_t *lpwhr, ...@@ -930,25 +929,25 @@ static BOOL HTTP_HttpAddRequestHeadersW(http_request_t *lpwhr,
{ {
/* Skip 0-length headers */ /* Skip 0-length headers */
lpszStart = lpszEnd; lpszStart = lpszEnd;
bSuccess = TRUE; res = ERROR_SUCCESS;
continue; continue;
} }
pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart); pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart);
if (pFieldAndValue) if (pFieldAndValue)
{ {
bSuccess = HTTP_VerifyValidHeader(lpwhr, pFieldAndValue[0]); res = HTTP_VerifyValidHeader(lpwhr, pFieldAndValue[0]);
if (bSuccess) if (res == ERROR_SUCCESS)
bSuccess = HTTP_ProcessHeader(lpwhr, pFieldAndValue[0], res = HTTP_ProcessHeader(lpwhr, pFieldAndValue[0],
pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ); pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ);
HTTP_FreeTokens(pFieldAndValue); HTTP_FreeTokens(pFieldAndValue);
} }
lpszStart = lpszEnd; lpszStart = lpszEnd;
} while (bSuccess); } while (res == ERROR_SUCCESS);
HeapFree(GetProcessHeap(), 0, buffer); HeapFree(GetProcessHeap(), 0, buffer);
return bSuccess; return res;
} }
/*********************************************************************** /***********************************************************************
...@@ -970,8 +969,8 @@ static BOOL HTTP_HttpAddRequestHeadersW(http_request_t *lpwhr, ...@@ -970,8 +969,8 @@ static BOOL HTTP_HttpAddRequestHeadersW(http_request_t *lpwhr,
BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest, BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
{ {
BOOL bSuccess = FALSE;
http_request_t *lpwhr; http_request_t *lpwhr;
DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_wn(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_wn(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier);
...@@ -979,17 +978,14 @@ BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest, ...@@ -979,17 +978,14 @@ BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
return TRUE; return TRUE;
lpwhr = (http_request_t*) WININET_GetObject( hHttpRequest ); lpwhr = (http_request_t*) WININET_GetObject( hHttpRequest );
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) if (lpwhr && lpwhr->hdr.htype == WH_HHTTPREQ)
{ res = HTTP_HttpAddRequestHeadersW( lpwhr, lpszHeader, dwHeaderLength, dwModifier );
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
goto lend;
}
bSuccess = HTTP_HttpAddRequestHeadersW( lpwhr, lpszHeader, dwHeaderLength, dwModifier );
lend:
if( lpwhr ) if( lpwhr )
WININET_Release( &lpwhr->hdr ); WININET_Release( &lpwhr->hdr );
return bSuccess; if(res != ERROR_SUCCESS)
SetLastError(res);
return res == ERROR_SUCCESS;
} }
/*********************************************************************** /***********************************************************************
...@@ -4665,12 +4661,12 @@ static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer) ...@@ -4665,12 +4661,12 @@ static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer)
#define COALESCEFLAGS (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON) #define COALESCEFLAGS (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier) static DWORD HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier)
{ {
LPHTTPHEADERW lphttpHdr = NULL; LPHTTPHEADERW lphttpHdr = NULL;
BOOL bSuccess = FALSE;
INT index = -1; INT index = -1;
BOOL request_only = dwModifier & HTTP_ADDHDR_FLAG_REQ; BOOL request_only = dwModifier & HTTP_ADDHDR_FLAG_REQ;
DWORD res = ERROR_HTTP_INVALID_HEADER;
TRACE("--> %s: %s - 0x%08x\n", debugstr_w(field), debugstr_w(value), dwModifier); TRACE("--> %s: %s - 0x%08x\n", debugstr_w(field), debugstr_w(value), dwModifier);
...@@ -4686,9 +4682,7 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val ...@@ -4686,9 +4682,7 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val
if (index >= 0) if (index >= 0)
{ {
if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW) if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW)
{ return ERROR_HTTP_INVALID_HEADER;
return FALSE;
}
lphttpHdr = &lpwhr->pCustHeaders[index]; lphttpHdr = &lpwhr->pCustHeaders[index];
} }
else if (value) else if (value)
...@@ -4705,7 +4699,7 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val ...@@ -4705,7 +4699,7 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val
return HTTP_InsertCustomHeader(lpwhr, &hdr); return HTTP_InsertCustomHeader(lpwhr, &hdr);
} }
/* no value to delete */ /* no value to delete */
else return TRUE; else return ERROR_SUCCESS;
if (dwModifier & HTTP_ADDHDR_FLAG_REQ) if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
lphttpHdr->wFlags |= HDR_ISREQUEST; lphttpHdr->wFlags |= HDR_ISREQUEST;
...@@ -4730,7 +4724,7 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val ...@@ -4730,7 +4724,7 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val
return HTTP_InsertCustomHeader(lpwhr, &hdr); return HTTP_InsertCustomHeader(lpwhr, &hdr);
} }
return TRUE; return ERROR_SUCCESS;
} }
else if (dwModifier & COALESCEFLAGS) else if (dwModifier & COALESCEFLAGS)
{ {
...@@ -4768,16 +4762,16 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val ...@@ -4768,16 +4762,16 @@ static BOOL HTTP_ProcessHeader(http_request_t *lpwhr, LPCWSTR field, LPCWSTR val
memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR)); memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR));
lphttpHdr->lpszValue[len] = '\0'; lphttpHdr->lpszValue[len] = '\0';
bSuccess = TRUE; res = ERROR_SUCCESS;
} }
else else
{ {
WARN("HeapReAlloc (%d bytes) failed\n",len+1); WARN("HeapReAlloc (%d bytes) failed\n",len+1);
INTERNET_SetLastError(ERROR_OUTOFMEMORY); res = ERROR_OUTOFMEMORY;
} }
} }
TRACE("<-- %d\n",bSuccess); TRACE("<-- %d\n", res);
return bSuccess; return res;
} }
...@@ -4848,11 +4842,10 @@ static INT HTTP_GetCustomHeaderIndex(http_request_t *lpwhr, LPCWSTR lpszField, ...@@ -4848,11 +4842,10 @@ static INT HTTP_GetCustomHeaderIndex(http_request_t *lpwhr, LPCWSTR lpszField,
* Insert header into array * Insert header into array
* *
*/ */
static BOOL HTTP_InsertCustomHeader(http_request_t *lpwhr, LPHTTPHEADERW lpHdr) static DWORD HTTP_InsertCustomHeader(http_request_t *lpwhr, LPHTTPHEADERW lpHdr)
{ {
INT count; INT count;
LPHTTPHEADERW lph = NULL; LPHTTPHEADERW lph = NULL;
BOOL r = FALSE;
TRACE("--> %s: %s\n", debugstr_w(lpHdr->lpszField), debugstr_w(lpHdr->lpszValue)); TRACE("--> %s: %s\n", debugstr_w(lpHdr->lpszField), debugstr_w(lpHdr->lpszValue));
count = lpwhr->nCustHeaders + 1; count = lpwhr->nCustHeaders + 1;
...@@ -4861,22 +4854,17 @@ static BOOL HTTP_InsertCustomHeader(http_request_t *lpwhr, LPHTTPHEADERW lpHdr) ...@@ -4861,22 +4854,17 @@ static BOOL HTTP_InsertCustomHeader(http_request_t *lpwhr, LPHTTPHEADERW lpHdr)
else else
lph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HTTPHEADERW) * count); lph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HTTPHEADERW) * count);
if (NULL != lph) if (!lph)
{ return ERROR_OUTOFMEMORY;
lpwhr->pCustHeaders = lph; lpwhr->pCustHeaders = lph;
lpwhr->pCustHeaders[count-1].lpszField = heap_strdupW(lpHdr->lpszField); lpwhr->pCustHeaders[count-1].lpszField = heap_strdupW(lpHdr->lpszField);
lpwhr->pCustHeaders[count-1].lpszValue = heap_strdupW(lpHdr->lpszValue); lpwhr->pCustHeaders[count-1].lpszValue = heap_strdupW(lpHdr->lpszValue);
lpwhr->pCustHeaders[count-1].wFlags = lpHdr->wFlags; lpwhr->pCustHeaders[count-1].wFlags = lpHdr->wFlags;
lpwhr->pCustHeaders[count-1].wCount= lpHdr->wCount; lpwhr->pCustHeaders[count-1].wCount= lpHdr->wCount;
lpwhr->nCustHeaders++; lpwhr->nCustHeaders++;
r = TRUE;
}
else
{
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
}
return r; return ERROR_SUCCESS;
} }
...@@ -4915,9 +4903,9 @@ static BOOL HTTP_VerifyValidHeader(http_request_t *lpwhr, LPCWSTR field) ...@@ -4915,9 +4903,9 @@ static BOOL HTTP_VerifyValidHeader(http_request_t *lpwhr, LPCWSTR field)
{ {
/* Accept-Encoding is stripped from HTTP/1.0 requests. It is invalid */ /* Accept-Encoding is stripped from HTTP/1.0 requests. It is invalid */
if (!strcmpW(lpwhr->lpszVersion, g_szHttp1_0) && !strcmpiW(field, szAccept_Encoding)) if (!strcmpW(lpwhr->lpszVersion, g_szHttp1_0) && !strcmpiW(field, szAccept_Encoding))
return FALSE; return ERROR_HTTP_INVALID_HEADER;
return TRUE; return ERROR_SUCCESS;
} }
/*********************************************************************** /***********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment