Index: mozilla/security/nss/lib/pk11wrap/pk11pars.c |
=================================================================== |
--- mozilla/security/nss/lib/pk11wrap/pk11pars.c (revision 166571) |
+++ mozilla/security/nss/lib/pk11wrap/pk11pars.c (working copy) |
@@ -15,7 +15,7 @@ |
#include "pki3hack.h" |
#include "secerr.h" |
-#include "pk11pars.h" |
+#include "utilpars.h" |
/* create a new module */ |
static SECMODModule * |
@@ -148,22 +148,22 @@ |
if (parameters) { |
mod->libraryParams = PORT_ArenaStrdup(mod->arena,parameters); |
} |
- mod->internal = secmod_argHasFlag("flags","internal",nssc); |
- mod->isFIPS = secmod_argHasFlag("flags","FIPS",nssc); |
- mod->isCritical = secmod_argHasFlag("flags","critical",nssc); |
- slotParams = secmod_argGetParamValue("slotParams",nssc); |
- mod->slotInfo = secmod_argParseSlotInfo(mod->arena,slotParams, |
+ mod->internal = NSSUTIL_ArgHasFlag("flags","internal",nssc); |
+ mod->isFIPS = NSSUTIL_ArgHasFlag("flags","FIPS",nssc); |
+ mod->isCritical = NSSUTIL_ArgHasFlag("flags","critical",nssc); |
+ slotParams = NSSUTIL_ArgGetParamValue("slotParams",nssc); |
+ mod->slotInfo = NSSUTIL_ArgParseSlotInfo(mod->arena,slotParams, |
&mod->slotInfoCount); |
if (slotParams) PORT_Free(slotParams); |
/* new field */ |
- mod->trustOrder = secmod_argReadLong("trustOrder",nssc, |
- SECMOD_DEFAULT_TRUST_ORDER,NULL); |
+ mod->trustOrder = NSSUTIL_ArgReadLong("trustOrder",nssc, |
+ NSSUTIL_DEFAULT_TRUST_ORDER,NULL); |
/* new field */ |
- mod->cipherOrder = secmod_argReadLong("cipherOrder",nssc, |
- SECMOD_DEFAULT_CIPHER_ORDER,NULL); |
+ mod->cipherOrder = NSSUTIL_ArgReadLong("cipherOrder",nssc, |
+ NSSUTIL_DEFAULT_CIPHER_ORDER,NULL); |
/* new field */ |
- mod->isModuleDB = secmod_argHasFlag("flags","moduleDB",nssc); |
- mod->moduleDBOnly = secmod_argHasFlag("flags","moduleDBOnly",nssc); |
+ mod->isModuleDB = NSSUTIL_ArgHasFlag("flags","moduleDB",nssc); |
+ mod->moduleDBOnly = NSSUTIL_ArgHasFlag("flags","moduleDBOnly",nssc); |
if (mod->moduleDBOnly) mod->isModuleDB = PR_TRUE; |
/* we need more bits, but we also want to preserve binary compatibility |
@@ -174,10 +174,10 @@ |
* code checking if (mod->isModuleDB) will continue to work correctly. */ |
if (mod->isModuleDB) { |
char flags = SECMOD_FLAG_MODULE_DB_IS_MODULE_DB; |
- if (secmod_argHasFlag("flags","skipFirst",nssc)) { |
+ if (NSSUTIL_ArgHasFlag("flags","skipFirst",nssc)) { |
flags |= SECMOD_FLAG_MODULE_DB_SKIP_FIRST; |
} |
- if (secmod_argHasFlag("flags","defaultModDB",nssc)) { |
+ if (NSSUTIL_ArgHasFlag("flags","defaultModDB",nssc)) { |
flags |= SECMOD_FLAG_MODULE_DB_DEFAULT_MODDB; |
} |
/* additional moduleDB flags could be added here in the future */ |
@@ -187,14 +187,14 @@ |
if (mod->internal) { |
char flags = SECMOD_FLAG_INTERNAL_IS_INTERNAL; |
- if (secmod_argHasFlag("flags", "internalKeySlot", nssc)) { |
+ if (NSSUTIL_ArgHasFlag("flags", "internalKeySlot", nssc)) { |
flags |= SECMOD_FLAG_INTERNAL_KEY_SLOT; |
} |
mod->internal = (PRBool) flags; |
} |
- ciphers = secmod_argGetParamValue("ciphers",nssc); |
- secmod_argSetNewCipherFlags(&mod->ssl[0],ciphers); |
+ ciphers = NSSUTIL_ArgGetParamValue("ciphers",nssc); |
+ NSSUTIL_ArgParseCipherFlags(&mod->ssl[0],ciphers); |
if (ciphers) PORT_Free(ciphers); |
secmod_PrivateModuleCount++; |
@@ -239,10 +239,6 @@ |
mod->internal = flags; |
} |
-/* forward declarations */ |
-static int secmod_escapeSize(const char *string, char quote); |
-static char *secmod_addEscape(const char *string, char quote); |
- |
/* |
* copy desc and value into target. Target is known to be big enough to |
* hold desc +2 +value, which is good because the result of this will be |
@@ -258,7 +254,7 @@ |
{ |
int diff, esc_len; |
- esc_len = secmod_escapeSize(value, '\"') - 1; |
+ esc_len = NSSUTIL_EscapeSize(value, '\"') - 1; |
diff = esc_len - strlen(value); |
if (diff > 0) { |
/* we need to escape... expand newSpecPtr as well to make sure |
@@ -269,7 +265,7 @@ |
} |
*targetLen += diff; |
target = newPtr; |
- value = secmod_addEscape(value, '\"'); |
+ value = NSSUTIL_Escape(value, '\"'); |
if (value == NULL) { |
return target; /* couldn't escape value, just drop the copy */ |
} |
@@ -280,6 +276,9 @@ |
PORT_Memcpy(target, value, esc_len); |
target += esc_len; |
*target++='\"'; |
+ if (diff > 0) { |
+ PORT_Free(value); |
+ } |
return target; |
} |
@@ -327,7 +326,7 @@ |
if (ids) { |
*ids = NULL; |
} |
- moduleSpec = secmod_argStrip(moduleSpec); |
+ moduleSpec = NSSUTIL_ArgStrip(moduleSpec); |
SECMOD_SPEC_COPY(newSpecPtr, modulePrev, moduleSpec); |
/* Notes on 'convert' and 'isFIPS' flags: The base parameters for opening |
@@ -359,13 +358,13 @@ |
while (*moduleSpec) { |
int next; |
modulePrev = moduleSpec; |
- SECMOD_HANDLE_STRING_ARG(moduleSpec, target, "tokens=", |
+ NSSUTIL_HANDLE_STRING_ARG(moduleSpec, target, "tokens=", |
modulePrev = moduleSpec; /* skip copying */ ) |
- SECMOD_HANDLE_STRING_ARG(moduleSpec, tmp, "cryptoTokenDescription=", |
+ NSSUTIL_HANDLE_STRING_ARG(moduleSpec, tmp, "cryptoTokenDescription=", |
if (convert) { modulePrev = moduleSpec; } ); |
- SECMOD_HANDLE_STRING_ARG(moduleSpec, tmp, "cryptoSlotDescription=", |
+ NSSUTIL_HANDLE_STRING_ARG(moduleSpec, tmp, "cryptoSlotDescription=", |
if (convert) { modulePrev = moduleSpec; } ); |
- SECMOD_HANDLE_STRING_ARG(moduleSpec, tmp, "dbTokenDescription=", |
+ NSSUTIL_HANDLE_STRING_ARG(moduleSpec, tmp, "dbTokenDescription=", |
if (convert) { |
modulePrev = moduleSpec; |
if (!isFIPS) { |
@@ -374,7 +373,7 @@ |
sizeof(SECMOD_TOKEN_DESCRIPTION)-1, tmp); |
} |
}); |
- SECMOD_HANDLE_STRING_ARG(moduleSpec, tmp, "dbSlotDescription=", |
+ NSSUTIL_HANDLE_STRING_ARG(moduleSpec, tmp, "dbSlotDescription=", |
if (convert) { |
modulePrev = moduleSpec; /* skip copying */ |
if (!isFIPS) { |
@@ -383,7 +382,7 @@ |
sizeof(SECMOD_SLOT_DESCRIPTION)-1, tmp); |
} |
} ); |
- SECMOD_HANDLE_STRING_ARG(moduleSpec, tmp, "FIPSTokenDescription=", |
+ NSSUTIL_HANDLE_STRING_ARG(moduleSpec, tmp, "FIPSTokenDescription=", |
if (convert) { |
modulePrev = moduleSpec; /* skip copying */ |
if (isFIPS) { |
@@ -392,7 +391,7 @@ |
sizeof(SECMOD_TOKEN_DESCRIPTION)-1, tmp); |
} |
} ); |
- SECMOD_HANDLE_STRING_ARG(moduleSpec, tmp, "FIPSSlotDescription=", |
+ NSSUTIL_HANDLE_STRING_ARG(moduleSpec, tmp, "FIPSSlotDescription=", |
if (convert) { |
modulePrev = moduleSpec; /* skip copying */ |
if (isFIPS) { |
@@ -401,7 +400,7 @@ |
sizeof(SECMOD_SLOT_DESCRIPTION)-1, tmp); |
} |
} ); |
- SECMOD_HANDLE_FINAL_ARG(moduleSpec) |
+ NSSUTIL_HANDLE_FINAL_ARG(moduleSpec) |
SECMOD_SPEC_COPY(newSpecPtr, modulePrev, moduleSpec); |
} |
if (tmp) { |
@@ -417,8 +416,8 @@ |
/* now build the child array from target */ |
/*first count them */ |
- for (tokenIndex = secmod_argStrip(target); *tokenIndex; |
- tokenIndex = secmod_argStrip(secmod_argSkipParameter(tokenIndex))) { |
+ for (tokenIndex = NSSUTIL_ArgStrip(target); *tokenIndex; |
+ tokenIndex = NSSUTIL_ArgStrip(NSSUTIL_ArgSkipParameter(tokenIndex))) { |
tokenCount++; |
} |
@@ -438,22 +437,22 @@ |
} |
/* now fill them in */ |
- for (tokenIndex = secmod_argStrip(target), i=0 ; |
+ for (tokenIndex = NSSUTIL_ArgStrip(target), i=0 ; |
*tokenIndex && (i < tokenCount); |
- tokenIndex=secmod_argStrip(tokenIndex)) { |
+ tokenIndex=NSSUTIL_ArgStrip(tokenIndex)) { |
int next; |
- char *name = secmod_argGetName(tokenIndex, &next); |
+ char *name = NSSUTIL_ArgGetLabel(tokenIndex, &next); |
tokenIndex += next; |
if (idArray) { |
- idArray[i] = secmod_argDecodeNumber(name); |
+ idArray[i] = NSSUTIL_ArgDecodeNumber(name); |
} |
PORT_Free(name); /* drop the explicit number */ |
/* if anything is left, copy the args to the child array */ |
- if (!secmod_argIsBlank(*tokenIndex)) { |
- childArray[i++] = secmod_argFetchValue(tokenIndex, &next); |
+ if (!NSSUTIL_ArgIsBlank(*tokenIndex)) { |
+ childArray[i++] = NSSUTIL_ArgFetchValue(tokenIndex, &next); |
tokenIndex += next; |
} |
} |
@@ -481,15 +480,15 @@ |
*certPrefix = NULL; |
*keyPrefix = NULL; |
- *readOnly = secmod_argHasFlag("flags","readOnly",spec); |
+ *readOnly = NSSUTIL_ArgHasFlag("flags","readOnly",spec); |
- spec = secmod_argStrip(spec); |
+ spec = NSSUTIL_ArgStrip(spec); |
while (*spec) { |
int next; |
- SECMOD_HANDLE_STRING_ARG(spec, config, "configdir=", ;) |
- SECMOD_HANDLE_STRING_ARG(spec, *certPrefix, "certPrefix=", ;) |
- SECMOD_HANDLE_STRING_ARG(spec, *keyPrefix, "keyPrefix=", ;) |
- SECMOD_HANDLE_FINAL_ARG(spec) |
+ NSSUTIL_HANDLE_STRING_ARG(spec, config, "configdir=", ;) |
+ NSSUTIL_HANDLE_STRING_ARG(spec, *certPrefix, "certPrefix=", ;) |
+ NSSUTIL_HANDLE_STRING_ARG(spec, *keyPrefix, "keyPrefix=", ;) |
+ NSSUTIL_HANDLE_FINAL_ARG(spec) |
} |
return config; |
} |
@@ -670,94 +669,14 @@ |
return; |
} |
- |
-static int |
-secmod_escapeSize(const char *string, char quote) |
-{ |
- int escapes = 0, size = 0; |
- const char *src; |
- for (src=string; *src ; src++) { |
- if ((*src == quote) || (*src == '\\')) escapes++; |
- size++; |
- } |
- |
- return escapes+size+1; |
-} |
- |
- |
/* |
- * add escapes to protect quote characters... |
- */ |
-static char * |
-secmod_addEscape(const char *string, char quote) |
-{ |
- char *newString = 0; |
- int size = 0; |
- const char *src; |
- char *dest; |
- |
- |
- size = secmod_escapeSize(string,quote); |
- newString = PORT_ZAlloc(size); |
- if (newString == NULL) { |
- return NULL; |
- } |
- |
- for (src=string, dest=newString; *src; src++,dest++) { |
- if ((*src == '\\') || (*src == quote)) { |
- *dest++ = '\\'; |
- } |
- *dest = *src; |
- } |
- |
- return newString; |
-} |
- |
-static int |
-secmod_doubleEscapeSize(const char *string, char quote1, char quote2) |
-{ |
- int escapes = 0, size = 0; |
- const char *src; |
- for (src=string; *src ; src++) { |
- if (*src == '\\') escapes+=3; /* \\\\ */ |
- if (*src == quote1) escapes+=2; /* \\quote1 */ |
- if (*src == quote2) escapes++; /* \quote2 */ |
- size++; |
- } |
- |
- return escapes+size+1; |
-} |
- |
-char * |
-secmod_DoubleEscape(const char *string, char quote1, char quote2) |
-{ |
- char *round1 = NULL; |
- char *retValue = NULL; |
- if (string == NULL) { |
- goto done; |
- } |
- round1 = secmod_addEscape(string,quote1); |
- if (round1) { |
- retValue = secmod_addEscape(round1,quote2); |
- PORT_Free(round1); |
- } |
- |
-done: |
- if (retValue == NULL) { |
- retValue = PORT_Strdup(""); |
- } |
- return retValue; |
-} |
- |
- |
-/* |
* caclulate the length of each child record: |
* " 0x{id}=<{escaped_child}>" |
*/ |
static int |
secmod_getChildLength(char *child, CK_SLOT_ID id) |
{ |
- int length = secmod_doubleEscapeSize(child, '>', ']'); |
+ int length = NSSUTIL_DoubleEscapeSize(child, '>', ']'); |
if (id == 0) { |
length++; |
} |
@@ -785,7 +704,7 @@ |
} |
*next += len; |
*length -= len; |
- escSpec = secmod_DoubleEscape(child, '>', ']'); |
+ escSpec = NSSUTIL_DoubleEscape(child, '>', ']'); |
if (escSpec == NULL) { |
return SECFailure; |
} |
@@ -951,7 +870,7 @@ |
if (module->slots[i]->defaultFlags) { |
PORT_Assert(si < slotCount); |
if (si >= slotCount) break; |
- slotStrings[si] = secmod_mkSlotString(module->slots[i]->slotID, |
+ slotStrings[si] = NSSUTIL_MkSlotString(module->slots[i]->slotID, |
module->slots[i]->defaultFlags, |
module->slots[i]->timeout, |
module->slots[i]->askpw, |
@@ -962,7 +881,8 @@ |
} |
} else { |
for (i=0; i < slotCount; i++) { |
- slotStrings[i] = secmod_mkSlotString(module->slotInfo[i].slotID, |
+ slotStrings[i] = NSSUTIL_MkSlotString( |
+ module->slotInfo[i].slotID, |
module->slotInfo[i].defaultFlags, |
module->slotInfo[i].timeout, |
module->slotInfo[i].askpw, |
@@ -972,11 +892,12 @@ |
} |
SECMOD_ReleaseReadLock(moduleLock); |
- nss = secmod_mkNSS(slotStrings,slotCount,module->internal, module->isFIPS, |
- module->isModuleDB, module->moduleDBOnly, |
- module->isCritical, module->trustOrder, |
- module->cipherOrder,module->ssl[0],module->ssl[1]); |
- modSpec= secmod_mkNewModuleSpec(module->dllName,module->commonName, |
+ nss = NSSUTIL_MkNSSString(slotStrings,slotCount,module->internal, |
+ module->isFIPS, module->isModuleDB, |
+ module->moduleDBOnly, module->isCritical, |
+ module->trustOrder, module->cipherOrder, |
+ module->ssl[0],module->ssl[1]); |
+ modSpec= NSSUTIL_MkModuleSpec(module->dllName,module->commonName, |
module->libraryParams,nss); |
PORT_Free(slotStrings); |
PR_smprintf_free(nss); |
@@ -1064,7 +985,7 @@ |
/* initialize the underlying module structures */ |
SECMOD_Init(); |
- status = secmod_argParseModuleSpec(modulespec, &library, &moduleName, |
+ status = NSSUTIL_ArgParseModuleSpec(modulespec, &library, &moduleName, |
¶meters, &nss); |
if (status != SECSuccess) { |
goto loser; |