Commit 024a0ac1 authored by Gerhard Gruber's avatar Gerhard Gruber Committed by Alexandre Julliard

WritePrivateProfileSection should allow to create duplicate keys

because it takes the buffer as it is without any modifications.
parent 861d7c83
...@@ -442,9 +442,8 @@ void PROFILE_DeleteAllKeys( LPCSTR section_name) ...@@ -442,9 +442,8 @@ void PROFILE_DeleteAllKeys( LPCSTR section_name)
* *
* Find a key in a profile tree, optionally creating it. * Find a key in a profile tree, optionally creating it.
*/ */
static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, const char *section_name,
const char *section_name, const char *key_name, BOOL create, BOOL create_always )
const char *key_name, int create )
{ {
const char *p; const char *p;
int seclen, keylen; int seclen, keylen;
...@@ -462,15 +461,23 @@ static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, ...@@ -462,15 +461,23 @@ static PROFILEKEY *PROFILE_Find( PROFILESECTION **section,
while (*section) while (*section)
{ {
if ( ((*section)->name[0]) if ( ((*section)->name[0])
&& (!(strncasecmp( (*section)->name, section_name, seclen ))) && (!(strncasecmp( (*section)->name, section_name, seclen )))
&& (((*section)->name)[seclen] == '\0') ) && (((*section)->name)[seclen] == '\0') )
{ {
PROFILEKEY **key = &(*section)->key; PROFILEKEY **key = &(*section)->key;
while (*key) while (*key)
{ {
if ( (!(strncasecmp( (*key)->name, key_name, keylen ))) /* If create_always is FALSE then we check if the keyname already exists.
&& (((*key)->name)[keylen] == '\0') ) * Otherwise we add it regardless of its existence, to allow
return *key; * keys to be added more then once in some cases.
*/
if(!create_always)
{
if ( (!(strncasecmp( (*key)->name, key_name, keylen )))
&& (((*key)->name)[keylen] == '\0') )
return *key;
}
key = &(*key)->next; key = &(*key)->next;
} }
if (!create) return NULL; if (!create) return NULL;
...@@ -827,7 +834,7 @@ static INT PROFILE_GetString( LPCSTR section, LPCSTR key_name, ...@@ -827,7 +834,7 @@ static INT PROFILE_GetString( LPCSTR section, LPCSTR key_name,
if (!def_val) def_val = ""; if (!def_val) def_val = "";
if (key_name && key_name[0]) if (key_name && key_name[0])
{ {
key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE ); key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE, FALSE);
PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val, PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
len, FALSE ); len, FALSE );
TRACE("('%s','%s','%s'): returning '%s'\n", TRACE("('%s','%s','%s'): returning '%s'\n",
...@@ -851,7 +858,7 @@ static INT PROFILE_GetString( LPCSTR section, LPCSTR key_name, ...@@ -851,7 +858,7 @@ static INT PROFILE_GetString( LPCSTR section, LPCSTR key_name,
* Set a profile string. * Set a profile string.
*/ */
static BOOL PROFILE_SetString( LPCSTR section_name, LPCSTR key_name, static BOOL PROFILE_SetString( LPCSTR section_name, LPCSTR key_name,
LPCSTR value ) LPCSTR value, BOOL create_always )
{ {
if (!key_name) /* Delete a whole section */ if (!key_name) /* Delete a whole section */
{ {
...@@ -871,8 +878,8 @@ static BOOL PROFILE_SetString( LPCSTR section_name, LPCSTR key_name, ...@@ -871,8 +878,8 @@ static BOOL PROFILE_SetString( LPCSTR section_name, LPCSTR key_name,
} }
else /* Set the key value */ else /* Set the key value */
{ {
PROFILEKEY *key = PROFILE_Find( &CurProfile->section, section_name, PROFILEKEY *key = PROFILE_Find(&CurProfile->section, section_name,
key_name, TRUE ); key_name, TRUE, create_always );
TRACE("('%s','%s','%s'): \n", TRACE("('%s','%s','%s'): \n",
section_name, key_name, value ); section_name, key_name, value );
if (!key) return FALSE; if (!key) return FALSE;
...@@ -1484,7 +1491,7 @@ BOOL WINAPI WritePrivateProfileStringA( LPCSTR section, LPCSTR entry, ...@@ -1484,7 +1491,7 @@ BOOL WINAPI WritePrivateProfileStringA( LPCSTR section, LPCSTR entry,
if (!section) { if (!section) {
FIXME("(NULL?,%s,%s,%s)? \n",entry,string,filename); FIXME("(NULL?,%s,%s,%s)? \n",entry,string,filename);
} else { } else {
ret = PROFILE_SetString( section, entry, string ); ret = PROFILE_SetString( section, entry, string, FALSE);
} }
} }
} }
...@@ -1536,7 +1543,7 @@ BOOL WINAPI WritePrivateProfileSectionA( LPCSTR section, ...@@ -1536,7 +1543,7 @@ BOOL WINAPI WritePrivateProfileSectionA( LPCSTR section,
if (!section && !string) if (!section && !string)
PROFILE_ReleaseFile(); /* always return FALSE in this case */ PROFILE_ReleaseFile(); /* always return FALSE in this case */
else if (!string) /* delete the named section*/ else if (!string) /* delete the named section*/
ret = PROFILE_SetString(section,NULL,NULL); ret = PROFILE_SetString(section,NULL,NULL, FALSE);
else { else {
PROFILE_DeleteAllKeys(section); PROFILE_DeleteAllKeys(section);
ret = TRUE; ret = TRUE;
...@@ -1545,13 +1552,11 @@ BOOL WINAPI WritePrivateProfileSectionA( LPCSTR section, ...@@ -1545,13 +1552,11 @@ BOOL WINAPI WritePrivateProfileSectionA( LPCSTR section,
strcpy( buf, string ); strcpy( buf, string );
if((p=strchr( buf, '='))){ if((p=strchr( buf, '='))){
*p='\0'; *p='\0';
ret = PROFILE_SetString( section, buf, p+1 ); ret = PROFILE_SetString( section, buf, p+1, TRUE);
} }
HeapFree( GetProcessHeap(), 0, buf ); HeapFree( GetProcessHeap(), 0, buf );
string += strlen(string)+1; string += strlen(string)+1;
} }
} }
} }
...@@ -1716,7 +1721,7 @@ BOOL WINAPI GetPrivateProfileStructA (LPCSTR section, LPCSTR key, ...@@ -1716,7 +1721,7 @@ BOOL WINAPI GetPrivateProfileStructA (LPCSTR section, LPCSTR key,
EnterCriticalSection( &PROFILE_CritSect ); EnterCriticalSection( &PROFILE_CritSect );
if (PROFILE_Open( filename )) { if (PROFILE_Open( filename )) {
PROFILEKEY *k = PROFILE_Find ( &CurProfile->section, section, key, FALSE); PROFILEKEY *k = PROFILE_Find ( &CurProfile->section, section, key, FALSE, FALSE);
if (k) { if (k) {
TRACE("value (at %p): '%s'\n", k->value, k->value); TRACE("value (at %p): '%s'\n", k->value, k->value);
if (((strlen(k->value) - 2) / 2) == len) if (((strlen(k->value) - 2) / 2) == len)
...@@ -1842,7 +1847,7 @@ BOOL WINAPI WritePrivateProfileStructA (LPCSTR section, LPCSTR key, ...@@ -1842,7 +1847,7 @@ BOOL WINAPI WritePrivateProfileStructA (LPCSTR section, LPCSTR key,
EnterCriticalSection( &PROFILE_CritSect ); EnterCriticalSection( &PROFILE_CritSect );
if (PROFILE_Open( filename )) if (PROFILE_Open( filename ))
ret = PROFILE_SetString( section, key, outstring ); ret = PROFILE_SetString( section, key, outstring, FALSE);
LeaveCriticalSection( &PROFILE_CritSect ); LeaveCriticalSection( &PROFILE_CritSect );
......
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