Use multimap type for storing header values (issue #386).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@346 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2011-10-28 21:31:26 +00:00
parent 0ec9541b78
commit ef80d4ae6b
17 changed files with 419 additions and 45 deletions

View File

@@ -99,7 +99,7 @@ void CEF_CALLBACK request_set_post_data(struct _cef_request_t* self,
}
void CEF_CALLBACK request_get_header_map(struct _cef_request_t* self,
cef_string_map_t headerMap)
cef_string_multimap_t headerMap)
{
DCHECK(self);
if(!self)
@@ -107,11 +107,11 @@ void CEF_CALLBACK request_get_header_map(struct _cef_request_t* self,
CefRequest::HeaderMap map;
CefRequestCppToC::Get(self)->GetHeaderMap(map);
transfer_string_map_contents(map, headerMap);
transfer_string_multimap_contents(map, headerMap);
}
void CEF_CALLBACK request_set_header_map(struct _cef_request_t* self,
cef_string_map_t headerMap)
cef_string_multimap_t headerMap)
{
DCHECK(self);
if(!self)
@@ -119,14 +119,14 @@ void CEF_CALLBACK request_set_header_map(struct _cef_request_t* self,
CefRequest::HeaderMap map;
if(headerMap)
transfer_string_map_contents(headerMap, map);
transfer_string_multimap_contents(headerMap, map);
CefRequestCppToC::Get(self)->SetHeaderMap(map);
}
void CEF_CALLBACK request_set(struct _cef_request_t* self,
const cef_string_t* url, const cef_string_t* method,
struct _cef_post_data_t* postData, cef_string_map_t headerMap)
struct _cef_post_data_t* postData, cef_string_multimap_t headerMap)
{
DCHECK(self);
if(!self)
@@ -138,7 +138,7 @@ void CEF_CALLBACK request_set(struct _cef_request_t* self,
if(postData)
postDataPtr = CefPostDataCppToC::Unwrap(postData);
if(headerMap)
transfer_string_map_contents(headerMap, map);
transfer_string_multimap_contents(headerMap, map);
CefRequestCppToC::Get(self)->Set(CefString(url), CefString(method),
postDataPtr, map);

View File

@@ -88,7 +88,7 @@ cef_string_userfree_t CEF_CALLBACK response_get_header(
}
void CEF_CALLBACK response_get_header_map(struct _cef_response_t* self,
cef_string_map_t headerMap)
cef_string_multimap_t headerMap)
{
DCHECK(self);
if(!self)
@@ -96,11 +96,11 @@ void CEF_CALLBACK response_get_header_map(struct _cef_response_t* self,
CefResponse::HeaderMap map;
CefResponseCppToC::Get(self)->GetHeaderMap(map);
transfer_string_map_contents(map, headerMap);
transfer_string_multimap_contents(map, headerMap);
}
void CEF_CALLBACK response_set_header_map(struct _cef_response_t* self,
cef_string_map_t headerMap)
cef_string_multimap_t headerMap)
{
DCHECK(self);
if(!self)
@@ -108,7 +108,7 @@ void CEF_CALLBACK response_set_header_map(struct _cef_response_t* self,
CefResponse::HeaderMap map;
if(headerMap)
transfer_string_map_contents(headerMap, map);
transfer_string_multimap_contents(headerMap, map);
CefResponseCppToC::Get(self)->SetHeaderMap(map);
}

View File

@@ -94,13 +94,13 @@ void CefRequestCToCpp::GetHeaderMap(HeaderMap& headerMap)
if(CEF_MEMBER_MISSING(struct_, get_header_map))
return;
cef_string_map_t map = cef_string_map_alloc();
cef_string_multimap_t map = cef_string_multimap_alloc();
if(!map)
return;
struct_->get_header_map(struct_, map);
transfer_string_map_contents(map, headerMap);
cef_string_map_free(map);
transfer_string_multimap_contents(map, headerMap);
cef_string_multimap_free(map);
}
void CefRequestCToCpp::SetHeaderMap(const HeaderMap& headerMap)
@@ -108,18 +108,18 @@ void CefRequestCToCpp::SetHeaderMap(const HeaderMap& headerMap)
if(CEF_MEMBER_MISSING(struct_, set_header_map))
return;
cef_string_map_t map = NULL;
cef_string_multimap_t map = NULL;
if(!headerMap.empty()) {
map = cef_string_map_alloc();
map = cef_string_multimap_alloc();
if(!map)
return;
transfer_string_map_contents(headerMap, map);
transfer_string_multimap_contents(headerMap, map);
}
struct_->set_header_map(struct_, map);
if(map)
cef_string_map_free(map);
cef_string_multimap_free(map);
}
void CefRequestCToCpp::Set(const CefString& url, const CefString& method,
@@ -132,19 +132,19 @@ void CefRequestCToCpp::Set(const CefString& url, const CefString& method,
if(postData.get())
postDataStruct = CefPostDataCToCpp::Unwrap(postData);
cef_string_map_t map = NULL;
cef_string_multimap_t map = NULL;
if(!headerMap.empty()) {
map = cef_string_map_alloc();
map = cef_string_multimap_alloc();
if(!map)
return;
transfer_string_map_contents(headerMap, map);
transfer_string_multimap_contents(headerMap, map);
}
struct_->set(struct_, url.GetStruct(), method.GetStruct(), postDataStruct,
map);
if(map)
cef_string_map_free(map);
cef_string_multimap_free(map);
}
CefRequest::RequestFlags CefRequestCToCpp::GetFlags()

View File

@@ -86,13 +86,13 @@ void CefResponseCToCpp::GetHeaderMap(HeaderMap& headerMap)
if(CEF_MEMBER_MISSING(struct_, get_header_map))
return;
cef_string_map_t map = cef_string_map_alloc();
cef_string_multimap_t map = cef_string_multimap_alloc();
if(!map)
return;
struct_->get_header_map(struct_, map);
transfer_string_map_contents(map, headerMap);
cef_string_map_free(map);
transfer_string_multimap_contents(map, headerMap);
cef_string_multimap_free(map);
}
void CefResponseCToCpp::SetHeaderMap(const HeaderMap& headerMap)
@@ -100,18 +100,18 @@ void CefResponseCToCpp::SetHeaderMap(const HeaderMap& headerMap)
if(CEF_MEMBER_MISSING(struct_, set_header_map))
return;
cef_string_map_t map = NULL;
cef_string_multimap_t map = NULL;
if(!headerMap.empty()) {
map = cef_string_map_alloc();
map = cef_string_multimap_alloc();
if(!map)
return;
transfer_string_map_contents(headerMap, map);
transfer_string_multimap_contents(headerMap, map);
}
struct_->set_header_map(struct_, map);
if(map)
cef_string_map_free(map);
cef_string_multimap_free(map);
}

View File

@@ -34,7 +34,7 @@ void transfer_string_map_contents(cef_string_map_t fromMap,
cef_string_map_key(fromMap, i, key.GetWritableStruct());
cef_string_map_value(fromMap, i, value.GetWritableStruct());
toMap.insert(std::pair<CefString, CefString>(key, value));
toMap.insert(std::make_pair(key, value));
}
}
@@ -45,3 +45,28 @@ void transfer_string_map_contents(const StringMap& fromMap,
for(; it != fromMap.end(); ++it)
cef_string_map_append(toMap, it->first.GetStruct(), it->second.GetStruct());
}
void transfer_string_multimap_contents(cef_string_multimap_t fromMap,
StringMultimap& toMap)
{
int size = cef_string_multimap_size(fromMap);
CefString key, value;
for(int i = 0; i < size; ++i) {
cef_string_multimap_key(fromMap, i, key.GetWritableStruct());
cef_string_multimap_value(fromMap, i, value.GetWritableStruct());
toMap.insert(std::make_pair(key, value));
}
}
void transfer_string_multimap_contents(const StringMultimap& fromMap,
cef_string_multimap_t toMap)
{
StringMultimap::const_iterator it = fromMap.begin();
for(; it != fromMap.end(); ++it) {
cef_string_multimap_append(toMap,
it->first.GetStruct(),
it->second.GetStruct());
}
}

View File

@@ -7,6 +7,7 @@
#include "include/internal/cef_string_list.h"
#include "include/internal/cef_string_map.h"
#include "include/internal/cef_string_multimap.h"
#include <map>
#include <vector>
@@ -24,4 +25,11 @@ void transfer_string_map_contents(cef_string_map_t fromMap,
void transfer_string_map_contents(const StringMap& fromMap,
cef_string_map_t toMap);
// Copy contents from one map type to another.
typedef std::multimap<CefString, CefString> StringMultimap;
void transfer_string_multimap_contents(cef_string_multimap_t fromMap,
StringMultimap& toMap);
void transfer_string_multimap_contents(const StringMultimap& fromMap,
cef_string_multimap_t toMap);
#endif // _TRANSFER_UTIL_H