static char *createFullPathName( char *dirName, char *certFile, void *plContext) { PKIX_UInt32 certFileLen; PKIX_UInt32 dirNameLen; char *certPathName = NULL; PKIX_TEST_STD_VARS(); certFileLen = PL_strlen(certFile); dirNameLen = PL_strlen(dirName); PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc (dirNameLen + certFileLen + 2, (void **)&certPathName, plContext)); PL_strcpy(certPathName, dirName); PL_strcat(certPathName, "/"); PL_strcat(certPathName, certFile); printf("certPathName = %s\n", certPathName); cleanup: PKIX_TEST_RETURN(); return (certPathName); }
/** * ZIP_FindNext * * Puts the next name in the passed buffer. Returns ZIP_ERR_SMALLBUF when * the name is too large for the buffer, and ZIP_ERR_FNF when there are no * more files that match the pattern * * @param hFind handle obtained from ZIP_FindInit * @param outbuf buffer to receive next filename * @param bufsize size of allocated buffer */ PR_PUBLIC_API(PRInt32) ZIP_FindNext(void* hFind, char * outbuf, PRUint16 bufsize) { PRInt32 status; /*--- error check args ---*/ if (hFind == 0) return ZIP_ERR_PARAM; nsZipFind* find = static_cast<nsZipFind*>(hFind); if (find->kMagic != ZIPFIND_MAGIC) return ZIP_ERR_PARAM; /* whatever it is isn't one of ours! */ /*--- return next filename file ---*/ const char* itemName; status = find->FindNext(&itemName); if (status == ZIP_OK) { PRUint16 namelen = (PRUint16)PL_strlen(itemName); if (bufsize > namelen) { PL_strcpy(outbuf, itemName); } else status = ZIP_ERR_SMALLBUF; } return status; }
static char * catDirName(char *platform, char *dir, void *plContext) { char *pathName = NULL; PKIX_UInt32 dirLen; PKIX_UInt32 platformLen; PKIX_TEST_STD_VARS(); dirLen = PL_strlen(dir); platformLen = PL_strlen(platform); PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc(platformLen + dirLen + 2, (void **)&pathName, plContext)); PL_strcpy(pathName, platform); PL_strcat(pathName, "/"); PL_strcat(pathName, dir); cleanup: PKIX_TEST_RETURN(); return (pathName); }
static char *catDirName(char *dir, char *name, void *plContext) { char *pathName = NULL; PKIX_UInt32 nameLen; PKIX_UInt32 dirLen; PKIX_TEST_STD_VARS(); nameLen = PL_strlen(name); dirLen = PL_strlen(dir); PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc (dirLen + nameLen + 2, (void **)&pathName, plContext)); PL_strcpy(pathName, dir); PL_strcat(pathName, "/"); PL_strcat(pathName, name); printf("pathName = %s\n", pathName); cleanup: PKIX_TEST_RETURN(); return (pathName); }
static const nsIID getSwarmIID (const char *interfaceName) { nsIID iid; nsIID default_iid = NS_GET_IID (nsISupports); if (interfaceName) { char *buf = (char *) malloc (6 + PL_strlen (interfaceName) + 1); const nsIID *iidptr; if (buf == NULL) abort (); PL_strcpy (buf, "swarmI"); PL_strcat (buf, interfaceName); if ((iidptr = findIIDFromName (buf))) iid = *iidptr; else iid = default_iid; free (buf); } else iid = default_iid; return iid; }
NS_IMETHODIMP nsSaveAsCharset::DoConversionFallBack(PRUint32 inUCS4, char *outString, PRInt32 bufferLength) { NS_ASSERTION(outString, "invalid input"); if(nullptr == outString ) return NS_ERROR_NULL_POINTER; *outString = '\0'; nsresult rv = NS_OK; if (ATTR_NO_FALLBACK(mAttribute)) { return NS_OK; } if (attr_EntityAfterCharsetConv == MASK_ENTITY(mAttribute)) { char *entity = NULL; rv = mEntityConverter->ConvertUTF32ToEntity(inUCS4, mEntityVersion, &entity); if (NS_SUCCEEDED(rv)) { if (NULL == entity || (PRInt32)strlen(entity) > bufferLength) { return NS_ERROR_OUT_OF_MEMORY; } PL_strcpy(outString, entity); nsMemory::Free(entity); return rv; } } switch (MASK_FALLBACK(mAttribute)) { case attr_FallbackQuestionMark: if(bufferLength>=2) { *outString++='?'; *outString='\0'; rv = NS_OK; } else { rv = NS_ERROR_FAILURE; } break; case attr_FallbackEscapeU: if (inUCS4 & 0xff0000) rv = (PR_snprintf(outString, bufferLength, "\\u%.6x", inUCS4) > 0) ? NS_OK : NS_ERROR_FAILURE; else rv = (PR_snprintf(outString, bufferLength, "\\u%.4x", inUCS4) > 0) ? NS_OK : NS_ERROR_FAILURE; break; case attr_FallbackDecimalNCR: rv = ( PR_snprintf(outString, bufferLength, "&#%u;", inUCS4) > 0) ? NS_OK : NS_ERROR_FAILURE; break; case attr_FallbackHexNCR: rv = (PR_snprintf(outString, bufferLength, "&#x%x;", inUCS4) > 0) ? NS_OK : NS_ERROR_FAILURE; break; case attr_FallbackNone: rv = NS_OK; break; default: rv = NS_ERROR_ILLEGAL_VALUE; break; } return rv; }
NSAPI_PUBLIC char *fcgi_util_arg_str(char *name) { char *t; t = (char *) PR_Malloc(strlen(name)+1); /* 1 = '\0' */ PL_strcpy(t, name); return t; }
static char* MimePgpe_generate(void *output_closure) { const char htmlMsg[] = "<html><body><b>GEN MSG<b></body></html>"; char* msg = (char *) PR_MALLOC(strlen(htmlMsg) + 1); if (msg) PL_strcpy(msg, htmlMsg); return msg; }
char* nsPop3Sink::GetDummyEnvelope(void) { static char result[75]; char *ct; time_t now = time ((time_t *) 0); #if defined (XP_WIN) if (now < 0 || now > 0x7FFFFFFF) now = 0x7FFFFFFF; #endif ct = ctime(&now); PR_ASSERT(ct[24] == '\r' || ct[24] == '\n'); ct[24] = 0; /* This value must be in ctime() format, with English abbreviations. strftime("... %c ...") is no good, because it is localized. */ PL_strcpy(result, "From - "); PL_strcpy(result + 7, ct); PL_strcpy(result + 7 + 24, MSG_LINEBREAK); return result; }
static char* MimeEnig_generate(void *output_closure) { fprintf(stderr, "MimeEnig_generate:\n"); const char htmlMsg[] = "<html><body><b>GEN MSG<b></body></html>"; char* msg = (char *) PR_MALLOC(strlen(htmlMsg) + 1); if (msg) { PL_strcpy(msg, htmlMsg); } return msg; }
static int sign_all_arc_fn(char *relpath, char *basedir, char *reldir, char *filename, void *arg) { char *zipfile = NULL; char *arc = NULL, *archive = NULL; int retval = 0; SignArcInfo * infop = (SignArcInfo * )arg; /* Make sure there is one and only one ".arc" in the relative path, * and that it is at the end of the path (don't sign .arcs within .arcs) */ if ( (PL_strcaserstr(relpath, ".arc") == relpath + strlen(relpath) - 4) && (PL_strcasestr(relpath, ".arc") == relpath + strlen(relpath) - 4) ) { if (!infop) { PR_fprintf(errorFD, "%s: Internal failure\n", PROGRAM_NAME); errorCount++; retval = -1; goto finish; } archive = PR_smprintf("%s/%s", basedir, relpath); zipfile = PL_strdup(archive); arc = PORT_Strrchr (zipfile, '.'); if (arc == NULL) { PR_fprintf(errorFD, "%s: Internal failure\n", PROGRAM_NAME); errorCount++; retval = -1; goto finish; } PL_strcpy (arc, ".jar"); if (verbosity >= 0) { PR_fprintf(outputFD, "\nsigning: %s\n", zipfile); } retval = SignArchive(archive, infop->keyName, zipfile, infop->javascript, infop->metafile, infop->install_script, infop->optimize, PR_TRUE /* recurse */); } finish: if (archive) PR_Free(archive); if (zipfile) PR_Free(zipfile); return retval; }
int main(int argc, char** argv) { PRInt32 id; // First make sure we can find all of the tags that are supposed to // be in the table. Futz with the case to make sure any case will // work const nsHTMLTags::NameTableEntry* et = &nsHTMLTags::kNameTable[0]; const nsHTMLTags::NameTableEntry* end = &nsHTMLTags::kNameTable[TAG_MAX]; while (et < end) { char tagName[100]; id = nsHTMLTags::LookupName(et->name); if (id < 0) { printf("bug: can't find '%s'\n", et->name); } if (et->id != id) { printf("bug: name='%s' et->id=%d id=%d\n", et->name, et->id, id); } // fiddle with the case to make sure we can still find it PL_strcpy(tagName, et->name); tagName[0] = tagName[0] - 32; id = nsHTMLTags::LookupName(tagName); if (id < 0) { printf("bug: can't find '%s'\n", tagName); } if (et->id != id) { printf("bug: name='%s' et->id=%d id=%d\n", et->name, et->id, id); } et++; } // Now make sure we don't find some garbage for (int i = 0; i < sizeof(kJunkNames) / sizeof(const char*); i++) { const char* tag = kJunkNames[i]; id = nsHTMLTags::LookupName(tag); if (id >= 0) { printf("bug: found '%s'\n", tag ? tag : "(null)"); } } return 0; }
int nsMsgSendPart::AppendOtherHeaders(const char* more) { if (!m_other) return SetOtherHeaders(more); if (!more || !*more) return 0; char* tmp = (char *) PR_Malloc(sizeof(char) * (PL_strlen(m_other) + PL_strlen(more) + 2)); if (!tmp) return NS_ERROR_OUT_OF_MEMORY; PL_strcpy(tmp, m_other); PL_strcat(tmp, more); PR_FREEIF(m_other); m_other = tmp; return 0; }
COMclass COMfindComponent (const char *className) { const char *prefix = "urn:"; const char *modulePrefix = "swarm/"; size_t prefixLen = PL_strlen (prefix); size_t modulePrefixLen = PL_strlen (modulePrefix); nsCID *cClass = new nsCID (); size_t classNameLen = PL_strlen (className); char *buf = (char *) malloc (prefixLen + classNameLen + 1); if (!buf) abort (); nsresult rv; PL_strcpy (buf, prefix); PL_strcat (buf, className); if (PL_strncmp (className, modulePrefix, modulePrefixLen) == 0) { unsigned i; buf[prefixLen + 5] = ':'; for (i = modulePrefixLen; i < classNameLen; i++) { unsigned pos = prefixLen + i; if (buf[pos] == '/') buf[pos] = '.'; } } nsCOMPtr<nsIComponentManager> compMgr; NS_GetComponentManager (getter_AddRefs (compMgr)); if (!compMgr) abort (); nsCOMPtr<nsIComponentManagerObsolete> compMgrO = do_QueryInterface (compMgr); rv = compMgrO->ContractIDToClassID (buf, cClass); free (buf); if (NS_FAILED (rv)) abort (); return (COMclass) cClass; }
static char * AppendAndAlloc(char *string, const char *newSubstring, bool withComma) { if (!newSubstring) return NULL; if (!string) return PL_strdup(newSubstring); char *separator = (char *) (withComma ? ", " : " "); char *oldString = string; string = (char *)PR_Calloc(PL_strlen(oldString) + PL_strlen(separator) + PL_strlen(newSubstring) + 1, sizeof(char)); PL_strcpy(string, oldString); PL_strcat(string, separator); PL_strcat(string, newSubstring); PR_Free(oldString); return string; }
static int MimeExternalBody_parse_eof (MimeObject *obj, bool abort_p) { int status = 0; MimeExternalBody *bod = (MimeExternalBody *) obj; if (obj->closed_p) return 0; /* Run parent method first, to flush out any buffered data. */ status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_eof(obj, abort_p); if (status < 0) return status; #ifdef XP_MACOSX if (obj->parent && mime_typep(obj->parent, (MimeObjectClass*) &mimeMultipartAppleDoubleClass)) goto done; #endif /* XP_MACOSX */ if (!abort_p && obj->output_p && obj->options && obj->options->write_html_p) { bool all_headers_p = obj->options->headers == MimeHeadersAll; MimeDisplayOptions *newopt = obj->options; /* copy it */ char *ct = MimeHeaders_get(obj->headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE); char *at, *lexp, *size, *perm; char *url, *dir, *mode, *name, *site, *svr, *subj; char *h = 0, *lname = 0, *lurl = 0, *body = 0; MimeHeaders *hdrs = 0; if (!ct) return MIME_OUT_OF_MEMORY; at = MimeHeaders_get_parameter(ct, "access-type", NULL, NULL); lexp = MimeHeaders_get_parameter(ct, "expiration", NULL, NULL); size = MimeHeaders_get_parameter(ct, "size", NULL, NULL); perm = MimeHeaders_get_parameter(ct, "permission", NULL, NULL); dir = MimeHeaders_get_parameter(ct, "directory", NULL, NULL); mode = MimeHeaders_get_parameter(ct, "mode", NULL, NULL); name = MimeHeaders_get_parameter(ct, "name", NULL, NULL); site = MimeHeaders_get_parameter(ct, "site", NULL, NULL); svr = MimeHeaders_get_parameter(ct, "server", NULL, NULL); subj = MimeHeaders_get_parameter(ct, "subject", NULL, NULL); url = MimeHeaders_get_parameter(ct, "url", NULL, NULL); PR_FREEIF(ct); /* the *internal* content-type */ ct = MimeHeaders_get(bod->hdrs, HEADER_CONTENT_TYPE, PR_TRUE, PR_FALSE); PRUint32 hlen = ((at ? strlen(at) : 0) + (lexp ? strlen(lexp) : 0) + (size ? strlen(size) : 0) + (perm ? strlen(perm) : 0) + (dir ? strlen(dir) : 0) + (mode ? strlen(mode) : 0) + (name ? strlen(name) : 0) + (site ? strlen(site) : 0) + (svr ? strlen(svr) : 0) + (subj ? strlen(subj) : 0) + (ct ? strlen(ct) : 0) + (url ? strlen(url) : 0) + 100); h = (char *) PR_MALLOC(hlen); if (!h) { status = MIME_OUT_OF_MEMORY; goto FAIL; } /* If there's a URL parameter, remove all whitespace from it. (The URL parameter to one of these headers is stored with lines broken every 40 characters or less; it's assumed that all significant whitespace was URL-hex-encoded, and all the rest of it was inserted just to keep the lines short.) */ if (url) { char *in, *out; for (in = url, out = url; *in; in++) if (!IS_SPACE(*in)) *out++ = *in; *out = 0; } hdrs = MimeHeaders_new(); if (!hdrs) { status = MIME_OUT_OF_MEMORY; goto FAIL; } # define FROB(STR,VAR) \ if (VAR) \ { \ PL_strncpyz(h, STR ": ", hlen); \ PL_strcatn(h, hlen, VAR); \ PL_strcatn(h, hlen, MSG_LINEBREAK); \ status = MimeHeaders_parse_line(h, strlen(h), hdrs); \ if (status < 0) goto FAIL; \ } FROB("Access-Type", at); FROB("URL", url); FROB("Site", site); FROB("Server", svr); FROB("Directory", dir); FROB("Name", name); FROB("Type", ct); FROB("Size", size); FROB("Mode", mode); FROB("Permission", perm); FROB("Expiration", lexp); FROB("Subject", subj); # undef FROB PL_strncpyz(h, MSG_LINEBREAK, hlen); status = MimeHeaders_parse_line(h, strlen(h), hdrs); if (status < 0) goto FAIL; lurl = MimeExternalBody_make_url(ct, at, lexp, size, perm, dir, mode, name, url, site, svr, subj, bod->body); if (lurl) { lname = MimeGetStringByID(MIME_MSG_LINK_TO_DOCUMENT); } else { lname = MimeGetStringByID(MIME_MSG_DOCUMENT_INFO); all_headers_p = PR_TRUE; } all_headers_p = PR_TRUE; /* #### just do this all the time? */ if (bod->body && all_headers_p) { char *s = bod->body; while (IS_SPACE(*s)) s++; if (*s) { char *s2; const char *pre = "<P><PRE>"; const char *suf = "</PRE>"; PRInt32 i; for(i = strlen(s)-1; i >= 0 && IS_SPACE(s[i]); i--) s[i] = 0; s2 = MsgEscapeHTML(s); if (!s2) goto FAIL; body = (char *) PR_MALLOC(strlen(pre) + strlen(s2) + strlen(suf) + 1); if (!body) { NS_Free(s2); goto FAIL; } PL_strcpy(body, pre); PL_strcat(body, s2); PL_strcat(body, suf); } } newopt->fancy_headers_p = PR_TRUE; newopt->headers = (all_headers_p ? MimeHeadersAll : MimeHeadersSome); FAIL: if (hdrs) MimeHeaders_free(hdrs); PR_FREEIF(h); PR_FREEIF(lname); PR_FREEIF(lurl); PR_FREEIF(body); PR_FREEIF(ct); PR_FREEIF(at); PR_FREEIF(lexp); PR_FREEIF(size); PR_FREEIF(perm); PR_FREEIF(dir); PR_FREEIF(mode); PR_FREEIF(name); PR_FREEIF(url); PR_FREEIF(site); PR_FREEIF(svr); PR_FREEIF(subj); } #ifdef XP_MACOSX done: #endif return status; }
PRStatus getNetAddr(const char *host, PRNetAddr *addr) { PRStatus rv = PR_SUCCESS; memset(addr, 0, sizeof(*addr)); // Extract the port number int port = 0; char *h = PL_strdup(host); char * p = host_port_suffix(h); // uds name if(!p) { #ifndef XP_WIN32 addr->local.family = PR_AF_LOCAL; strcpy(addr->local.path, h); #else addr = NULL; return PR_SUCCESS; #endif // XP_WIN32 } else { if (p) { *p = '\0'; p++; // validate the port number if(*p == '\0') { // port is empty PL_strcpy(errorMsg, "port is missing in the bind-path"); return PR_FAILURE; } // check if port has only digits PRBool invalidPort = PR_FALSE; char *startP = p; while(p && *p) { if(!isdigit(*p)) { invalidPort = PR_TRUE; break; } p++; } if(invalidPort) { PR_snprintf(errorMsg, 256, "invalid port %s specified in the bind-path", startP); return PR_FAILURE; } port = atoi(startP); if(port < 1 || port > 65535) { PR_snprintf(errorMsg, 256, "port %s specified in the bind-path is out of range", startP); return PR_FAILURE; } } // try to resolve the hostname PRHostEnt he; char buffer[PR_NETDB_BUF_SIZE]; if(h && *h != '\0') { // Format a PRNetAddr rv = PR_GetHostByName(h, buffer, sizeof(buffer), &he); } else { // no host specified, consider it as localhost rv = PR_GetHostByName("localhost", buffer, sizeof(buffer), &he); } if (rv == PR_SUCCESS) { if (PR_EnumerateHostEnt(0, &he, port, addr) < 0) { rv = PR_FAILURE; PR_snprintf(errorMsg, 256, "invalid host %s specified in the bind-path", h); printf("invalid host is specified in the bind-path\n"); } } } PL_strfree(h); return rv; }
PRStatus getSockAddr(const char *host, struct sockaddr **addr, int *localAddr ) { PRStatus rv = PR_SUCCESS; *localAddr = 0; // Extract the port number int port = 0; char *h = PL_strdup(host); char * p = host_port_suffix(h); // uds name if(!p) { *localAddr = 1; #ifndef XP_WIN32 struct sockaddr_un *udsSock = (struct sockaddr_un *)malloc(sizeof(struct sockaddr_un)); memset((char *)udsSock, 0, sizeof(struct sockaddr_un)); udsSock->sun_family = PR_AF_LOCAL; strcpy(udsSock->sun_path, h); *addr = (struct sockaddr *)udsSock; #else PL_strcpy(errorMsg, "UDS is not supported on Windows"); return PR_FAILURE; // no UDS on Windows #endif // XP_WIN32 } else { if (p) { *p = '\0'; p++; // validate the port number if(*p == '\0') { // port is empty PL_strcpy(errorMsg, "port is missing in the bind-path"); return PR_FAILURE; } // check if port has only digits PRBool invalidPort = PR_FALSE; char *startP = p; while(p && *p) { if(!isdigit(*p)) { invalidPort = PR_TRUE; break; } p++; } if(invalidPort) { PR_snprintf(errorMsg, 256, "invalid port %s specified in the bind-path", startP); return PR_FAILURE; } port = atoi(startP); if(port < 1 || port > 65535) { PR_snprintf(errorMsg, 256, "port %s specified in the bind-path is out of range", startP); return PR_FAILURE; } } struct sockaddr_in *servAddr = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in)); memset((char*)servAddr, 0, sizeof(struct sockaddr_in)); servAddr->sin_family = PF_INET; struct hostent *pHostEnt; if(h && *h != '\0') { // if hostname is specified pHostEnt = gethostbyname( h ); } else { // if no hostname specified, consider "localhost" pHostEnt = gethostbyname( "localhost" ); } if ( !pHostEnt ) { PR_snprintf(errorMsg, 256, "invalid host %s specified in the bind-path", h); return PR_FAILURE; } memcpy ( &(servAddr->sin_addr), pHostEnt->h_addr, pHostEnt->h_length ); servAddr->sin_port = htons(port); *addr = (struct sockaddr *)servAddr; } PL_strfree(h); return rv; }
void display( nsIRegistry *reg, nsRegistryKey root, const char *rootName ) { // Print out key name. printf( "%s\n", rootName ); // Make sure it isn't a "root" key. if ( root != nsIRegistry::Common && root != nsIRegistry::Users && root != nsIRegistry::CurrentUser ) { // Print values stored under this key. displayValues( reg, root ); } // Enumerate all subkeys (immediately) under the given node. nsIEnumerator *keys; nsresult rv = reg->EnumerateSubtrees( root, &keys ); // Check result. if ( rv == NS_OK ) { // Set enumerator to beginning. rv = keys->First(); // Enumerate subkeys till done. while( NS_SUCCEEDED( rv ) && (NS_OK != keys->IsDone()) ) { nsISupports *base; rv = keys->CurrentItem( &base ); // Test result. if ( rv == NS_OK ) { // Get specific interface. nsIRegistryNode *node; nsIID nodeIID = NS_IREGISTRYNODE_IID; rv = base->QueryInterface( nodeIID, (void**)&node ); // Test that result. if ( rv == NS_OK ) { // Get node name. char *name; rv = node->GetNameUTF8( &name ); // Test result. if ( rv == NS_OK ) { // Build complete name. char *fullName = new char[ PL_strlen(rootName) + PL_strlen(name) + 5 ]; PL_strcpy( fullName, rootName ); PL_strcat( fullName, " - " ); PL_strcat( fullName, name ); // Display contents under this subkey. nsRegistryKey key; rv = reg->GetSubtreeRaw( root, name, &key ); if ( rv == NS_OK ) { display( reg, key, fullName ); printf( "\n" ); } else { printf( "Error getting key, rv=0x%08X\n", (int)rv ); } delete [] fullName; } else { printf( "Error getting subtree name, rv=0x%08X\n", (int)rv ); } // Release node. node->Release(); } else { printf( "Error converting base node ptr to nsIRegistryNode, rv=0x%08X\n", (int)rv ); } // Release item. base->Release(); // Advance to next key. rv = keys->Next(); // Check result. if ( NS_SUCCEEDED( rv ) ) { } else { printf( "Error advancing enumerator, rv=0x%08X\n", (int)rv ); } } else { printf( "Error getting current item, rv=0x%08X\n", (int)rv ); } } // Release key enumerator. keys->Release(); } else { printf( "Error creating enumerator for %s, root=0x%08X, rv=0x%08X\n", rootName, (int)root, (int)rv ); } return; }
nsresult nsMsgKeySet::Output(char **outputStr) { NS_ENSURE_ARG(outputStr); PRInt32 size; PRInt32 *head; PRInt32 *tail; PRInt32 *end; PRInt32 s_size; char *s_head; char *s, *s_end; PRInt32 last_art = -1; *outputStr = nsnull; size = m_length; head = m_data; tail = head; end = head + size; s_size = (size * 12) + 10; // dmb - try to make this allocation get used at least once. s_head = (char *) nsMemory::Alloc(s_size); if (! s_head) return NS_ERROR_OUT_OF_MEMORY; s_head[0] = '\0'; // otherwise, s_head will contain garbage. s = s_head; s_end = s + s_size; while (tail < end) { PRInt32 from; PRInt32 to; if (s > (s_end - (12 * 2 + 10))) { /* 12 bytes for each number (enough for "2147483647" aka 2^31-1), plus 10 bytes of slop. */ PRInt32 so = s - s_head; s_size += 200; char* tmp = (char *) nsMemory::Alloc(s_size); if (tmp) PL_strcpy(tmp, s_head); nsMemory::Free(s_head); s_head = tmp; if (!s_head) return NS_ERROR_OUT_OF_MEMORY; s = s_head + so; s_end = s_head + s_size; } if (*tail < 0) { /* it's a range */ from = tail[1]; to = from + (-(tail[0])); tail += 2; } else /* it's a literal */ { from = *tail; to = from; tail++; } if (from == 0) { from = 1; /* See 'hack' comment above ### */ } if (from <= last_art) from = last_art + 1; if (from <= to) { if (from < to) { PR_snprintf(s, s_end - s, "%lu-%lu,", from, to); } else { PR_snprintf(s, s_end - s, "%lu,", from); } s += PL_strlen(s); last_art = to; } } if (last_art >= 0) { s--; /* Strip off the last ',' */ } *s = 0; *outputStr = s_head; return NS_OK; }
bool TestKeywords() { nsCSSKeywords::AddRefTable(); bool success = true; nsCSSKeyword id; nsCSSKeyword index; extern const char* const kCSSRawKeywords[]; // First make sure we can find all of the tags that are supposed to // be in the table. Futz with the case to make sure any case will // work const char*const* et = &kCSSRawKeywords[0]; const char*const* end = &kCSSRawKeywords[eCSSKeyword_COUNT - 1]; index = eCSSKeyword_UNKNOWN; while (et < end) { char tagName[512]; char* underscore = &(tagName[0]); PL_strcpy(tagName, *et); while (*underscore) { if (*underscore == '_') { *underscore = '-'; } underscore++; } index = nsCSSKeyword(PRInt32(index) + 1); id = nsCSSKeywords::LookupKeyword(nsCString(tagName)); if (id <= eCSSKeyword_UNKNOWN) { printf("bug: can't find '%s'\n", tagName); success = false; } if (id != index) { printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); success = false; } // fiddle with the case to make sure we can still find it if (('a' <= tagName[0]) && (tagName[0] <= 'z')) { tagName[0] = tagName[0] - 32; } id = nsCSSKeywords::LookupKeyword(nsCString(tagName)); if (id <= eCSSKeyword_UNKNOWN) { printf("bug: can't find '%s'\n", tagName); success = false; } if (id != index) { printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); success = false; } et++; } // Now make sure we don't find some garbage for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) { const char* const tag = kJunkNames[i]; id = nsCSSKeywords::LookupKeyword(nsCAutoString(tag)); if (eCSSKeyword_UNKNOWN < id) { printf("bug: found '%s'\n", tag ? tag : "(null)"); success = false; } } nsCSSKeywords::ReleaseTable(); return success; }
static bool TestProps() { bool success = true; nsCSSProperty id; nsCSSProperty index; // Everything appears to assert if we don't do this first... nsCSSProps::AddRefTable(); // First make sure we can find all of the tags that are supposed to // be in the table. Futz with the case to make sure any case will // work extern const char* const kCSSRawProperties[]; const char*const* et = &kCSSRawProperties[0]; const char*const* end = &kCSSRawProperties[eCSSProperty_COUNT]; index = eCSSProperty_UNKNOWN; while (et < end) { char tagName[100]; PL_strcpy(tagName, *et); index = nsCSSProperty(PRInt32(index) + 1); id = nsCSSProps::LookupProperty(nsCString(tagName), nsCSSProps::eAny); if (id == eCSSProperty_UNKNOWN) { printf("bug: can't find '%s'\n", tagName); success = false; } if (id != index) { printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); success = false; } // fiddle with the case to make sure we can still find it if (('a' <= tagName[0]) && (tagName[0] <= 'z')) { tagName[0] = tagName[0] - 32; } id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName), nsCSSProps::eAny); if (id < 0) { printf("bug: can't find '%s'\n", tagName); success = false; } if (index != id) { printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); success = false; } et++; } // Now make sure we don't find some garbage for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) { const char* const tag = kJunkNames[i]; id = nsCSSProps::LookupProperty(nsCAutoString(tag), nsCSSProps::eAny); if (id >= 0) { printf("bug: found '%s'\n", tag ? tag : "(null)"); success = false; } } nsCSSProps::ReleaseTable(); return success; }
/* * FUNCTION: pkix_pl_CollectionCertStoreContext_PopulateCRL * DESCRIPTION: * * Create list of CRLs from *.crl files at directory specified in dirName, * Not recursive to sub-dirctory. Also assume the directory contents are * not changed dynamically. * * PARAMETERS * "colCertStoreContext" - Address of CollectionCertStoreContext * where the dirName is specified and where the return * CRLs are stored as a list. Must be non-NULL. * "plContext" - Platform-specific context pointer. * * THREAD SAFETY: * Not Thread Safe - A lock at top level is required. * * RETURNS: * Returns NULL if the function succeeds. * Returns a CollectionCertStoreContext Error if the function fails in * a non-fatal way. * Returns a Fatal Error if the function fails in an unrecoverable way. */ static PKIX_Error * pkix_pl_CollectionCertStoreContext_PopulateCRL( PKIX_PL_CollectionCertStoreContext *colCertStoreContext, void *plContext) { PKIX_List *crlList = NULL; PKIX_PL_CRL *crlItem = NULL; char *dirName = NULL; char *pathName = NULL; PKIX_UInt32 dirNameLen = 0; PRErrorCode prError = 0; PRDir *dir = NULL; PRDirEntry *dirEntry = NULL; PKIX_ENTER(COLLECTIONCERTSTORECONTEXT, "pkix_pl_CollectionCertStoreContext_PopulateCRL"); PKIX_NULLCHECK_ONE(colCertStoreContext); /* convert directory to ascii */ PKIX_CHECK(PKIX_PL_String_GetEncoded (colCertStoreContext->storeDir, PKIX_ESCASCII, (void **)&dirName, &dirNameLen, plContext), PKIX_STRINGGETENCODEDFAILED); /* create CRL list, if no CRL file, should return an empty list */ PKIX_CHECK(PKIX_List_Create(&crlList, plContext), PKIX_LISTCREATEFAILED); /* open directory and read in .crl files */ PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG("\t\t Calling PR_OpenDir.\n"); dir = PR_OpenDir(dirName); if (!dir) { PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG_ARG ("\t\t Directory Name:%s\n", dirName); PKIX_ERROR(PKIX_CANNOTOPENCOLLECTIONCERTSTORECONTEXTDIRECTORY); } PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG("\t\t Calling PR_ReadDir.\n"); dirEntry = PR_ReadDir(dir, PR_SKIP_HIDDEN | PR_SKIP_BOTH); if (!dirEntry) { PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Empty directory.\n"); PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PR_GetError.\n"); prError = PR_GetError(); } PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG("\t\t Calling PR_SetError.\n"); PR_SetError(0, 0); while (dirEntry != NULL && prError == 0) { if (PL_strrstr(dirEntry->name, ".crl") == dirEntry->name + PL_strlen(dirEntry->name) - 4) { PKIX_CHECK_ONLY_FATAL (PKIX_PL_Malloc (dirNameLen + PL_strlen(dirEntry->name) + 2, (void **)&pathName, plContext), PKIX_MALLOCFAILED); if ((!PKIX_ERROR_RECEIVED) && (pathName != NULL)){ PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PL_strcpy for dirName.\n"); PL_strcpy(pathName, dirName); PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PL_strcat for dirName.\n"); PL_strcat(pathName, "/"); PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PL_strcat for /.\n"); PL_strcat(pathName, dirEntry->name); PKIX_CHECK_ONLY_FATAL (pkix_pl_CollectionCertStoreContext_CreateCRL (pathName, &crlItem, plContext), PKIX_COLLECTIONCERTSTORECONTEXTCREATECRLFAILED); if (!PKIX_ERROR_RECEIVED){ PKIX_CHECK_ONLY_FATAL (PKIX_List_AppendItem (crlList, (PKIX_PL_Object *)crlItem, plContext), PKIX_LISTAPPENDITEMFAILED); } } PKIX_DECREF(crlItem); PKIX_FREE(pathName); } PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PR_SetError.\n"); PR_SetError(0, 0); PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PR_ReadDir.\n"); dirEntry = PR_ReadDir(dir, PR_SKIP_HIDDEN | PR_SKIP_BOTH); if (!dirEntry) { PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PR_GetError.\n"); prError = PR_GetError(); } } if ((prError != 0) && (prError != PR_NO_MORE_FILES_ERROR)) { PKIX_ERROR(PKIX_COLLECTIONCERTSTORECONTEXTGETSELECTCRLFAILED); } PKIX_CHECK(PKIX_List_SetImmutable(crlList, plContext), PKIX_LISTSETIMMUTABLEFAILED); PKIX_INCREF(crlList); colCertStoreContext->crlList = crlList; cleanup: if (dir) { PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG ("\t\t Calling PR_CloseDir.\n"); PR_CloseDir(dir); } PKIX_FREE(pathName); PKIX_FREE(dirName); if (PKIX_ERROR_RECEIVED){ PKIX_DECREF(crlList); } PKIX_DECREF(crlItem); PKIX_DECREF(crlList); PKIX_RETURN(COLLECTIONCERTSTORECONTEXT); }