static SECStatus secu_PrintUserNoticeQualifier(FILE *out, SECItem * qualifierValue, char *msg, int level) { CERTUserNotice *userNotice = NULL; if (qualifierValue) userNotice = CERT_DecodeUserNotice(qualifierValue); if (userNotice) { if (userNotice->noticeReference.organization.len != 0) { char *string = itemToString(&userNotice->noticeReference.organization); SECItem **itemList = userNotice->noticeReference.noticeNumbers; while (itemList && *itemList) { SECU_PrintInteger(out,*itemList,string,level+1); itemList++; } PORT_Free(string); } if (userNotice->displayText.len != 0) { SECU_PrintString(out,&userNotice->displayText, "Display Text", level+1); } CERT_DestroyUserNotice(userNotice); return SECSuccess; } return SECFailure; /* caller will print this value */ }
char * stringFromUserNotice(SECItem *noticeItem) { SECItem *org; unsigned int len, headerlen; char *stringbuf; CERTUserNotice *userNotice; char *policystr; char *retstr = NULL; SECItem *displayText; SECItem **noticeNumbers; unsigned int strnum; /* decode the user notice */ userNotice = CERT_DecodeUserNotice(noticeItem); if ( userNotice == NULL ) { return(NULL); } org = &userNotice->noticeReference.organization; if ( (org->len != 0 ) && ( policyStringCB != NULL ) ) { /* has a noticeReference */ /* extract the org string */ len = org->len; stringbuf = (char*)PORT_Alloc(len + 1); if ( stringbuf != NULL ) { PORT_Memcpy(stringbuf, org->data, len); stringbuf[len] = '\0'; noticeNumbers = userNotice->noticeReference.noticeNumbers; while ( *noticeNumbers != NULL ) { /* XXX - only one byte integers right now*/ strnum = (*noticeNumbers)->data[0]; policystr = (* policyStringCB)(stringbuf, strnum, policyStringCBArg); if ( policystr != NULL ) { if ( retstr != NULL ) { retstr = PR_sprintf_append(retstr, "\n%s", policystr); } else { retstr = PR_sprintf_append(retstr, "%s", policystr); } PORT_Free(policystr); } noticeNumbers++; } PORT_Free(stringbuf); } } if ( retstr == NULL ) { if ( userNotice->displayText.len != 0 ) { displayText = &userNotice->displayText; if ( displayText->len > 2 ) { if ( displayText->data[0] == SEC_ASN1_VISIBLE_STRING ) { headerlen = 2; if ( displayText->data[1] & 0x80 ) { /* multibyte length */ headerlen += ( displayText->data[1] & 0x7f ); } len = displayText->len - headerlen; retstr = (char*)PORT_Alloc(len + 1); if ( retstr != NULL ) { PORT_Memcpy(retstr, &displayText->data[headerlen],len); retstr[len] = '\0'; } } } } } CERT_DestroyUserNotice(userNotice); return(retstr); }