int berDecStrmMatchTag (OSCTXT* pctxt, ASN1TAG tag, int *len_p, OSBOOL advance) { int stat; ASN1TAG parsed_tag; int parsed_len; stat = rtxStreamDirectBufCheck (pctxt); if (stat < 0) return LOG_RTERR (pctxt, stat); stat = rtxStreamMark (pctxt, 32); if (stat != 0) return LOG_RTERR (pctxt, stat); stat = berDecStrmTagAndLen (pctxt, &parsed_tag, &parsed_len); if (stat != 0) return LOG_RTERR (pctxt, stat); parsed_tag &= ~TM_CONS; if ((tag & ~TM_CONS) != parsed_tag) { rtxStreamReset (pctxt); #ifndef _COMPACT berErrAddTagParm (pctxt, tag); /* expected tag */ berErrAddTagParm (pctxt, parsed_tag); /* parsed tag */ #endif return RTERR_IDNOTFOU; } else { if (len_p != 0) *len_p = parsed_len; if (!advance) { stat = rtxStreamReset (pctxt); if (stat != 0) return LOG_RTERR (pctxt, stat); } } return 0; }
EXTERN int asn1PD_RUA_CauseProtocol (OSCTXT* pctxt, RUA_CauseProtocol* pvalue) { int stat = 0; OSUINT32 ui; OSBOOL extbit = FALSE; /* extension bit */ stat = PD_BIT (pctxt, &extbit); if (stat != 0) return LOG_RTERR (pctxt, stat); if (extbit) { stat = pd_SmallNonNegWholeNumber (pctxt, &ui); if (stat != 0) return LOG_RTERR (pctxt, stat); *pvalue = 0x7fffffff; } else { stat = pd_ConsUnsigned (pctxt, &ui, 0, OSUINTCONST(6)); if (stat != 0) return LOG_RTERR (pctxt, stat); switch (ui) { case 0: *pvalue = RUA_transfer_syntax_error; break; case 1: *pvalue = RUA_abstract_syntax_error_reject; break; case 2: *pvalue = RUA_abstract_syntax_error_ignore_and_notify; break; case 3: *pvalue = RUA_message_not_compatible_with_receiver_state; break; case 4: *pvalue = RUA_semantic_error; break; case 5: *pvalue = RUA_unspecified_2; break; case 6: *pvalue = RUA_abstract_syntax_error_falsely_constructed_message; break; default: return LOG_RTERR (pctxt, RTERR_INVENUM); } } return (stat); }
EXTERN int asn1PD_RUA_Establishment_Cause (OSCTXT* pctxt, RUA_Establishment_Cause* pvalue) { int stat = 0; OSUINT32 ui; OSBOOL extbit = FALSE; /* extension bit */ stat = PD_BIT (pctxt, &extbit); if (stat != 0) return LOG_RTERR (pctxt, stat); if (extbit) { stat = pd_SmallNonNegWholeNumber (pctxt, &ui); if (stat != 0) return LOG_RTERR (pctxt, stat); *pvalue = 0x7fffffff; } else { stat = pd_ConsUnsigned (pctxt, &ui, 0, OSUINTCONST(1)); if (stat != 0) return LOG_RTERR (pctxt, stat); switch (ui) { case 0: *pvalue = RUA_emergency_call; break; case 1: *pvalue = RUA_normal_call; break; default: return LOG_RTERR (pctxt, RTERR_INVENUM); } } return (stat); }
EXTRTMETHOD int rtMakeGeneralizedTime (OSCTXT* pctxt, const OSNumDateTime* dateTime, char** outdata, size_t outdataSize) { char dateTimeStr[46]; int j; double frac; if (!rtxDateTimeIsValid (dateTime)) return LOG_RTERR(pctxt, RTERR_INVFORMAT); /* YYYYMMDDHH[MM[SS[(.|,)SSSS]]][TZD] */ j = sprintf (dateTimeStr, "%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d", dateTime->year, dateTime->mon, dateTime->day, dateTime->hour, dateTime->min, (int)dateTime->sec); frac = dateTime->sec - (int)dateTime->sec; if (frac > 0.00000001) { char tmpbuf[32]; int i, len; sprintf (tmpbuf, "%.6f", frac); len = strlen (tmpbuf); /* cut trailing zeros off frac part */ for (i = len - 1; i > 0; i--) { if (tmpbuf [i] == '0') tmpbuf [i] = '\0'; else break; } if (i > 2) { strcat (dateTimeStr, "."); strcat (dateTimeStr, tmpbuf + 2); } } if (dateTime->tz_flag) { dateTimeStr [j++] = 'Z'; dateTimeStr [j] = '\0'; } else if (dateTime->tzo != 0) { char tzd = (dateTime->tzo < 0) ? '-' : '+'; int tzo = dateTime->tzo; if (tzo < 0) tzo *= -1; sprintf (dateTimeStr + j, "%c%02d%02d", tzd, tzo/60, tzo%60); } if (outdataSize == 0) { *outdata = (char*) rtxMemAlloc (pctxt, strlen(dateTimeStr)+1); if (0 == *outdata) return LOG_RTERR (pctxt, RTERR_NOMEM); } else { size_t size = strlen (dateTimeStr); if (outdataSize <= size) return LOG_RTERR (pctxt, RTERR_STROVFLW); } strcpy (*outdata, dateTimeStr); return (0); }
EXTERN int asn1PD_RUA_CauseRadioNetwork (OSCTXT* pctxt, RUA_CauseRadioNetwork* pvalue) { int stat = 0; OSUINT32 ui; OSBOOL extbit = FALSE; /* extension bit */ stat = PD_BIT (pctxt, &extbit); if (stat != 0) return LOG_RTERR (pctxt, stat); if (extbit) { stat = pd_SmallNonNegWholeNumber (pctxt, &ui); if (stat != 0) return LOG_RTERR (pctxt, stat); *pvalue = 0x7fffffff; } else { stat = pd_ConsUnsigned (pctxt, &ui, 0, OSUINTCONST(3)); if (stat != 0) return LOG_RTERR (pctxt, stat); switch (ui) { case 0: *pvalue = RUA_normal; break; case 1: *pvalue = RUA_connect_failed; break; case 2: *pvalue = RUA_network_release; break; case 3: *pvalue = RUA_unspecified; break; default: return LOG_RTERR (pctxt, RTERR_INVENUM); } } return (stat); }
int berDecStrmReal (OSCTXT *pctxt, OSREAL *object_p, ASN1TagType tagging, int length) { OSRTBuffer savedBuf; OSOCTET tmpbuf[16]; register int stat = 0; if (tagging == ASN1EXPL) { if ((stat = berDecStrmMatchTag (pctxt, ASN_ID_REAL, &length, TRUE)) != 0) /* RTERR_IDNOTFOU will be logged later, by the generated code, or reset by rtxErrReset (for optional seq elements). */ return (stat == RTERR_IDNOTFOU) ? stat : LOG_RTERR (pctxt, stat); } /* Read encoded value into memory */ if (length > sizeof(tmpbuf)) { return LOG_RTERR (pctxt, RTERR_TOOBIG); } stat = rtxStreamRead (pctxt, tmpbuf, length); if (stat < 0) return LOG_RTERR (pctxt, stat); /* Decode */ memcpy (&savedBuf, &pctxt->buffer, sizeof(OSRTBuffer)); rtxInitContextBuffer (pctxt, tmpbuf, length); stat = xd_real (pctxt, object_p, ASN1IMPL, length); /* Reset context buffer */ memcpy (&pctxt->buffer, &savedBuf, sizeof(OSRTBuffer)); return stat; }
EXTRTMETHOD int rtxWriteBytes (OSCTXT* pctxt, const OSOCTET* pdata, size_t nocts) { if (nocts > 0) { if (!OSRTISSTREAM (pctxt)) { int stat = rtxCheckBuffer (pctxt, nocts); if (0 == stat) { OSCRTLMEMCPY (&pctxt->buffer.data[pctxt->buffer.byteIndex], pdata, nocts); pctxt->buffer.byteIndex += nocts; } else return LOG_RTERR (pctxt, stat); } #ifndef _NO_STREAM else { if (OSRTSTREAM_ID (pctxt) != OSRTSTRMID_DIRECTBUF && !(OSRTSTREAM_FLAGS (pctxt) & OSRTSTRMF_UNBUFFERED)) { int stat = rtxStreamDirectBufCreate (pctxt); if (stat != 0) return LOG_RTERR (pctxt, stat); } return rtxStreamWrite (pctxt, pdata, nocts); } #endif } LCHECKX (pctxt); return 0; }
EXTRTMETHOD int rtxStreamSocketCreateWriter (OSCTXT* pctxt, const char* host, int port) { int i, stat; OSRTSOCKET socket; if (0 != pctxt->pStream) { return LOG_RTERR (pctxt, RTERR_STRMINUSE); } stat = rtxSocketCreate (&socket); if (0 != stat) return LOG_RTERR (pctxt, stat); RTDIAG3 (pctxt, "Connecting to %s:%i..", host, port); for (i = 0; i < MAX_CONNECT_ATTEMPTS; i++) { stat = rtxSocketConnect (socket, host, port); if (0 != stat) { if (i + 1 == MAX_CONNECT_ATTEMPTS) { RTDIAG2 (pctxt, "\nConnection failed, error code is %i\n", stat); return LOG_RTERR (pctxt, stat); } } else break; } RTDIAG1 (pctxt, "\nConnection established.\n"); rtxStreamInit (pctxt); stat = rtxStreamSocketAttach (pctxt, socket, OSRTSTRMF_OUTPUT); if (0 != stat) return LOG_RTERR (pctxt, stat); return 0; }
int xd_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p, ASN1TagType tagging, ASN1TAG tag, int length) { OSUINT32 i; OSINT32 stat = 0, isConstructedTag; OSOCTET* data = 0; OSUINT32 nchars = 0; OS32BITCHAR* data32 = 0; if (tagging == ASN1EXPL) { if ((stat = xd_match1 (pctxt, ASN1TAG2BYTE(tag), &length)) < 0) /* RTERR_IDNOTFOU will be logged later, by the generated code, or reset by rtxErrReset (for optional seq elements). */ return (stat == RTERR_IDNOTFOU) ? stat : LOG_RTERR (pctxt, stat); } isConstructedTag = (int)((pctxt->flags & ASN1CONSTAG) != 0); if (0 == length) { nchars = 0; data32 = 0; } else { int size, ll = 0; /* For an indefinite length message, need to get the actual */ /* length by parsing tags until the end of the message is */ /* reached.. */ if (length == ASN_K_INDEFLEN) { /* indefinite length message */ if ((stat = xd_consStrIndefLenAndSize (pctxt, TM_UNIV|ASN_ID_OCTSTR, &ll, &size)) != 0) return LOG_RTERR (pctxt, stat); } else ll = size = length; data = (OSOCTET*) rtxMemAlloc (pctxt, ll); data32 = (OS32BITCHAR*)data; if (0 != data) { ll = size; if ((stat = xd_octstr_s (pctxt, data, (OSUINT32*) &ll, ASN1IMPL, size)) != 0) return LOG_RTERR_AND_FREE_MEM (pctxt, stat, data); nchars = ll / 4; for (i = 0; i < nchars; i++, data += 4) { data32[i] = (OS32BITCHAR) (((data[0] * 256) + data[1]) * 65536UL + (((data[2] * 256) + data[3]))); } } else return LOG_RTERR (pctxt, RTERR_NOMEM); } if (isConstructedTag && length == ASN_K_INDEFLEN) { if (XD_MATCHEOC (pctxt)) XD_BUMPIDX (pctxt, 2); else return LOG_RTERR_AND_FREE_MEM (pctxt, ASN_E_INVLEN, data); } object_p->data = data32; object_p->nchars = nchars; return 0; }
int xerEncAscCharStr (OSCTXT* pctxt, const char* pvalue, const char* elemName) { int stat; /* Element name must be specified because this function could be */ /* invoked to handle any of the useful character string types. */ if (0 == elemName) return LOG_RTERR (pctxt, RTERR_INVPARAM); /* Encode start element */ stat = xerEncStartElement (pctxt, elemName, 0); if (stat != 0) return LOG_RTERR (pctxt, stat); pctxt->state = XERDATA; /* Loop through all characters and convert special characters into */ /* XML escape sequences. */ stat = xerPutCharStr (pctxt, pvalue, strlen (pvalue)); if (stat != 0) return LOG_RTERR (pctxt, stat); /* Encode end element */ stat = xerEncEndElement (pctxt, elemName); if (stat != 0) return LOG_RTERR (pctxt, stat); return 0; }
EXTPERMETHOD int PD_CONSINTFUNC (OSCTXT* pctxt, OSINTTYPE* pvalue, OSINTTYPE lower, OSINTTYPE upper) { OSINTTYPE range_value; OSINTTYPE adjusted_value; int stat; /* Check for special case: if lower is 0 and upper is OSINTMAX, */ /* set range to OSINTMAX; otherwise to upper - lower + 1 */ range_value = (lower == 0 && upper == OSINTMAX) ? OSINTMAX : upper - lower + 1; PU_NEWFIELD (pctxt, "ConsUnsigned"); if (lower != upper) { stat = PD_CONSWHOLENUMBER (pctxt, &adjusted_value, range_value); if (stat == 0) { *pvalue = adjusted_value + lower; /* Verify value is within given range */ if (*pvalue < lower || *pvalue > upper) { rtxErrAddElemNameParm (pctxt); RTXERRADDINTPARM (pctxt, *pvalue); return LOG_RTERR (pctxt, RTERR_CONSVIO); } } else return LOG_RTERR (pctxt, stat); } else *pvalue = lower; PU_SETBITCOUNT (pctxt); return 0; }
EXTXMLMETHOD int rtAsn1XmlEncOpenType (OSCTXT *pctxt, const OSOCTET* data, OSUINT32 nocts, const OSUTF8CHAR* elemName, const OSUTF8CHAR* nsPrefix) { OSUTF8CHAR* qname = 0; int stat; if (0 != isBinaryData (data, nocts)) { const OSUTF8CHAR *ename = (elemName == 0 || strcmp ("", elemName) == 0 ) ? OSUTF8("binext") : elemName; qname = rtXmlNewQName (pctxt, ename, nsPrefix); if (0 != qname) { stat = rtXmlEncStartElement (pctxt, qname, 0, 0, TRUE); if (stat != 0) return LOG_RTERR (pctxt, stat); } else return RTERR_NOMEM; if (0 != data && nocts > 0) { stat = rtXmlEncHexStrValue (pctxt, nocts, data); pctxt->state = OSXMLDATA; if (stat != 0) return LOG_RTERR (pctxt, stat); } if (0 != qname) { stat = rtXmlEncEndElement (pctxt, qname, 0); if (stat != 0) return LOG_RTERR (pctxt, stat); rtxMemFreePtr (pctxt, qname); } } else { if (0 != elemName) { qname = rtXmlNewQName (pctxt, elemName, nsPrefix); if (0 != qname) { stat = rtXmlEncStartElement (pctxt, qname, 0, 0, TRUE); if (stat != 0) return LOG_RTERR (pctxt, stat); } else return RTERR_NOMEM; } if (0 != data && nocts > 0) { OSRTSAFEMEMCPY (pctxt, data, nocts); pctxt->state = OSXMLDATA; } if (0 != qname) { stat = rtXmlEncEndElement (pctxt, qname, 0); if (stat != 0) return LOG_RTERR (pctxt, stat); rtxMemFreePtr (pctxt, qname); } } return 0; }
int xd_len (OSCTXT *pctxt, int *len_p) { OSOCTET b = XD_FETCH1 (pctxt); register int i; *len_p = 0; if (b > 0x80) { i = b & 0x7F; if (i > 4) return LOG_RTERR (pctxt, ASN_E_INVLEN); for (*len_p = 0; i > 0; i--) { b = XD_FETCH1 (pctxt); *len_p = (*len_p * 256) + b; } } else if (b == 0x80) *len_p = ASN_K_INDEFLEN; else *len_p = b; /* Length is not indefinite length */ if (*len_p != ASN_K_INDEFLEN) { if (*len_p < 0 || *len_p > (int)(pctxt->buffer.size - pctxt->buffer.byteIndex)) return LOG_RTERR (pctxt, ASN_E_INVLEN); } return (0); }
int berDecStrmInt8 (OSCTXT *pctxt, OSINT8 *object_p, ASN1TagType tagging, int length) { register int stat = 0; if (tagging == ASN1EXPL) { stat = berDecStrmMatchTag (pctxt, ASN_ID_INT, &length, TRUE); /* RTERR_IDNOTFOU will be logged later, by the generated code, or reset by rtxErrReset (for optional seq elements). */ if (stat != 0) return (stat == RTERR_IDNOTFOU) ? stat : LOG_RTERR (pctxt, stat); } /* Make sure integer will fit in target variable */ if (length > (sizeof(OSINT8))) { return LOG_RTERR (pctxt, RTERR_TOOBIG); } else if (length <= 0) return LOG_RTERR (pctxt, ASN_E_INVLEN); /* note: indef len not allowed */ /* Copy first byte into a signed char variable and assign it to */ /* object. This should handle sign extension in the case of a */ /* negative number.. */ stat = rtxStreamRead (pctxt, (OSOCTET*)object_p, 1); if (stat < 0) return LOG_RTERR (pctxt, stat); return 0; }
int xerDecUInt64 (OSCTXT* pctxt, OSUINT64* pvalue) { XMLCHAR* inpdata = (XMLCHAR*) ASN1BUFPTR (pctxt); int i; OSBOOL minus = FALSE; register OSUINT64 value = 0, prevVal = 0; *pvalue = 0; /* Consume leading white space */ for (i = 0; inpdata[i] != 0; i++) { if (!OS_ISSPACE (inpdata[i])) break; } /* Convert Unicode characters to an integer value */ for ( ; inpdata[i] != 0; i++, prevVal = value) { if (OS_ISDIGIT (inpdata[i])) value = (value * 10) + (inpdata[i] - '0'); else return LOG_RTERR (pctxt, RTERR_INVCHAR); if (value/10 != prevVal) /* test for int overflow AB, 09/27/02 */ return LOG_RTERR (pctxt, RTERR_TOOBIG); } *pvalue = value; return (0); }
int xerEncRelativeOID (OSCTXT* pctxt, const ASN1OBJID *pvalue, const char* elemName) { char lbuf[40], *p; int stat; OSUINT32 i; if (0 == elemName) elemName = "RELATIVE_OID"; stat = xerEncStartElement (pctxt, elemName, 0); if (stat != 0) return LOG_RTERR (pctxt, stat); pctxt->state = XERDATA; for (i = 0; i < pvalue->numids; i++) { p = (char*) lbuf; if (i != 0) *p++ = '.'; sprintf (p, "%d", pvalue->subid[i]); stat = xerCopyText (pctxt, lbuf); if (stat != 0) return LOG_RTERR (pctxt, stat); } stat = xerEncEndElement (pctxt, elemName); if (stat != 0) return LOG_RTERR (pctxt, stat); return (0); }
EXTXMLMETHOD int OSXMLEncodeBuffer::addXMLHeader ( const OSUTF8CHAR* version, const OSUTF8CHAR* encoding, OSBOOL newLine) { if (0 != version && 0 != encoding) { size_t len = OSUTF8LEN(version) + OSUTF8LEN(encoding) + 32; OSCTXT* pctxt = getCtxtPtr(); /* Encode Unicode BOM */ int stat = rtXmlEncBOM (pctxt); if (stat != 0) return LOG_RTERR (pctxt, stat); // Verify text will fit in encode buffer stat = rtxCheckBuffer (pctxt, len+1); if (stat != 0) return LOG_RTERR (pctxt, stat); OSRTMEMCPY (pctxt, "<?xml version=\"", 15); OSRTMEMCPY (pctxt, version, OSUTF8LEN(version)); OSRTMEMCPY (pctxt, "\" encoding=\"", 12); OSRTMEMCPY (pctxt, encoding, OSUTF8LEN(encoding)); OSRTMEMCPY (pctxt, "\"?>", 3); if (newLine) OSRTPUTCHAR (pctxt, '\n'); // Indicate XML message shouls be encoded as a fragment since // header had already been added manually.. setFragment (); } return 0; }
int xd_int8 (OSCTXT *pctxt, OSINT8 *object_p, ASN1TagType tagging, int length) { register int status = 0; if (tagging == ASN1EXPL) { if ((status = XD_CHKDEFLEN (pctxt, 3)) != 0) /* tag + len + val */ return LOG_RTERR (pctxt, status); if (!XD_MATCH1 (pctxt, ASN_ID_INT)) { return berErrUnexpTag (pctxt, ASN_ID_INT); } length = (int) XD_FETCH1 (pctxt); } /* Make sure integer will fit in target variable */ if (length != sizeof(OSINT8)) { /* note: only 1 byte len is allowed */ return LOG_RTERR (pctxt, ASN_E_INVLEN); } *object_p = (OSINT8) XD_FETCH1 (pctxt); return 0; }
int XmlEnc_EncodingStyle_1 (OSCTXT* pctxt, EncodingStyle_1* pvalue, const OSUTF8CHAR* elemName, const OSUTF8CHAR* nsPrefix) { int stat = 0; if (elemName != 0) { stat = rtXmlEncStartElement (pctxt, elemName, nsPrefix, TRUE); if (stat != 0) return LOG_RTERR (pctxt, stat); } { const OSUTF8CHAR* savedPrefix = nsPrefix; nsPrefix = rtXmlNSGetPrefix (pctxt, OSUTF8( "http://schemas.xmlsoap.org/soap/envelope/")); { OSRTDListNode* pnode = pvalue->head; while (0 != pnode) { stat = rtXmlEncUTF8Str (pctxt, ((const OSUTF8CHAR*)pnode->data) , OSUTF8(""), 0); if (stat != 0) return LOG_RTERR (pctxt, stat); OSRTSAFEPUTCHAR (pctxt, ' '); pnode = pnode->next; }} nsPrefix = savedPrefix; } stat = rtXmlEncEndElement (pctxt, elemName, nsPrefix); if (stat != 0) return LOG_RTERR (pctxt, stat); return (stat); }
int berEncStrmBMPStr (OSCTXT* pctxt, const Asn116BitCharString* object_p, ASN1TagType tagging) { OSOCTET lbuf[2]; int stat; OSUINT32 i; if (0 == object_p) return LOG_RTERR (pctxt, RTERR_BADVALUE); if (tagging == ASN1EXPL) stat = berEncStrmTagAndLen (pctxt, TM_UNIV|TM_PRIM|ASN_ID_BMPString, object_p->nchars * 2); else stat = berEncStrmLength (pctxt, object_p->nchars * 2); if (stat != 0) return LOG_RTERR (pctxt, stat); for (i = 0; i < object_p->nchars; i++) { lbuf[0] = (OSOCTET) (object_p->data[i] / 256); lbuf[1] = (OSOCTET) (object_p->data[i] % 256); stat = berEncStrmWriteOctets (pctxt, lbuf, 2); if (stat != 0) return LOG_RTERR (pctxt, stat); } return 0; }
int xe_oid64 (OSCTXT* pctxt, ASN1OID64 *object_p, ASN1TagType tagging) { OSUINT64 subid; register int aal, ll, i; /* Validate given object ID by applying ASN.1 rules */ if (0 == object_p) return LOG_RTERR(pctxt, ASN_E_INVOBJID); if (object_p->numids < 2) return LOG_RTERR(pctxt, ASN_E_INVOBJID); if (object_p->subid[0] > 2) return LOG_RTERR(pctxt, ASN_E_INVOBJID); if (object_p->subid[0] != 2 && object_p->subid[1] > 39) return LOG_RTERR(pctxt, ASN_E_INVOBJID); /* Passed checks, encode object identifier */ for (aal = 0, i = object_p->numids - 1; i >= 1 && aal >= 0; i--) { subid = (i == 1) ? (object_p->subid[0] * 40) + object_p->subid[1] : object_p->subid[i]; aal = ((ll = xe_ident64 (pctxt, subid)) >= 0) ? aal + ll : ll; } if (tagging == ASN1EXPL && aal > 0) aal = xe_tag_len (pctxt, TM_UNIV|TM_PRIM|ASN_ID_OBJID, aal); return (aal); }
int xd_OpenTypeExt (OSCTXT* pctxt, ASN1CCB* ccb_p, ASN1TAG tag, OSRTDList *pElemList) { int length, stat; if (tag == ASN_K_NOTAG) { /* Loop through remaining elements in SEQUENCE */ while (!XD_CHKEND (pctxt, ccb_p)) { stat = xd_OpenTypeAppend (pctxt, pElemList); /*!AB 11/06/02 */ if (stat != 0) return LOG_RTERR (pctxt, stat); } } else { /* Loop through elements until matching tag found or some other */ /* error occurs.. */ while ((stat = xd_match (pctxt, tag, &length, 0)) == RTERR_IDNOTFOU) { rtxErrReset (pctxt); if (XD_CHKEND (pctxt, ccb_p)) { return LOG_RTERR (pctxt, RTERR_ENDOFBUF); } else { stat = xd_OpenTypeAppend (pctxt, pElemList); /*!AB 11/06/02 */ if (stat != 0) return LOG_RTERR (pctxt, stat); } } if (stat != 0) return LOG_RTERR (pctxt, stat); } return 0; }
EXTERN int asn1PD_HnbPrivateMessage (OSCTXT* pctxt, HnbPrivateMessage* pvalue) { int stat = 0; OSCTXT lctxt; ASN1OpenType openType; ASN1OpenType* pOpenType; OSUINT32 bitcnt; OSUINT32 i; OSBOOL optbit = FALSE; OSBOOL extbit = FALSE; /* extension bit */ stat = PD_BIT (pctxt, &extbit); if (stat != 0) return LOG_RTERR (pctxt, stat); rtxDListInit (&pvalue->extElem1); /* decode privateIEs */ asn1Init_PrivateIE_Container (&pvalue->privateIEs); stat = asn1PD_PrivateIE_Container (pctxt, &pvalue->privateIEs); if (stat != 0) return LOG_RTERR (pctxt, stat); if (extbit) { /* decode extension optional bits length */ stat = pd_SmallNonNegWholeNumber (pctxt, &bitcnt); if (stat != 0) return LOG_RTERR (pctxt, stat); bitcnt += 1; rtxPreInitContext (&lctxt); rtxCopyContext (&lctxt, pctxt); stat = pd_moveBitCursor (pctxt, bitcnt); if (stat != 0) return LOG_RTERR (pctxt, stat); for (i = 0; i < bitcnt; i++) { PD_BIT (&lctxt, &optbit); if (optbit) { stat = pd_OpenType (pctxt, &openType.data, &openType.numocts); if (stat != 0) return LOG_RTERR (pctxt, stat); pOpenType = rtxMemAllocType (pctxt, ASN1OpenType); pOpenType->numocts = openType.numocts; pOpenType->data = openType.data; rtxDListAppend (pctxt, &pvalue->extElem1, pOpenType); } else { /* unknown element */ rtxDListAppend (pctxt, &pvalue->extElem1, 0); } } } return (stat); }
EXTERN int asn1E_Ns1_Max_height (OSCTXT* pctxt, Ns1_Max_height *pvalue, ASN1TagType tagging) { int ll; int ll0 = 0; int ll1 = 0; ll0 = 0; switch (pvalue->t) { case 1: ll = xe_tag_len (pctxt, TM_CTXT|TM_PRIM|0, xe_utf8str (pctxt, pvalue->u.alt, ASN1IMPL)); if (ll < 0) return LOG_RTERR (pctxt, ll); ll1 += ll; break; case 2: ll = xe_tag_len (pctxt, TM_CTXT|TM_PRIM|1, xe_utf8str (pctxt, pvalue->u.alt_1, ASN1IMPL)); if (ll < 0) return LOG_RTERR (pctxt, ll); ll1 += ll; break; default: return LOG_RTERR (pctxt, RTERR_INVOPT); } ll0 += ll1; return (ll0); }
EXTERN int asn1PD_RUA_CauseTransport (OSCTXT* pctxt, RUA_CauseTransport* pvalue) { int stat = 0; OSUINT32 ui; OSBOOL extbit = FALSE; /* extension bit */ stat = PD_BIT (pctxt, &extbit); if (stat != 0) return LOG_RTERR (pctxt, stat); if (extbit) { stat = pd_SmallNonNegWholeNumber (pctxt, &ui); if (stat != 0) return LOG_RTERR (pctxt, stat); *pvalue = 0x7fffffff; } else { stat = pd_ConsUnsigned (pctxt, &ui, 0, OSUINTCONST(1)); if (stat != 0) return LOG_RTERR (pctxt, stat); switch (ui) { case 0: *pvalue = RUA_transport_resource_unavailable; break; case 1: *pvalue = RUA_unspecified_1; break; default: return LOG_RTERR (pctxt, RTERR_INVENUM); } } return (stat); }
EXTXMLMETHOD int rtXmlEncUnicodeStr (OSCTXT* pctxt, const OSUNICHAR* value, OSUINT32 nchars, const OSUTF8CHAR* elemName, OSXMLNamespace* pNS) { int stat; if (0 != elemName) { stat = rtXmlEncStartElement (pctxt, elemName, pNS, 0, TRUE); if (stat != 0) return LOG_RTERR (pctxt, stat); } /* Encode string contents */ if (0 != value && nchars > 0) { if (pctxt->state != OSXMLATTR) pctxt->state = OSXMLDATA; stat = rtXmlEncUnicodeData (pctxt, value, nchars); if (stat != 0) return LOG_RTERR (pctxt, stat); } if (0 != elemName) { stat = rtXmlEncEndElement (pctxt, elemName, pNS); if (stat != 0) return LOG_RTERR (pctxt, stat); } return 0; }
EXTERN int asn1PD_RUA_CauseMisc (OSCTXT* pctxt, RUA_CauseMisc* pvalue) { int stat = 0; OSUINT32 ui; OSBOOL extbit = FALSE; /* extension bit */ stat = PD_BIT (pctxt, &extbit); if (stat != 0) return LOG_RTERR (pctxt, stat); if (extbit) { stat = pd_SmallNonNegWholeNumber (pctxt, &ui); if (stat != 0) return LOG_RTERR (pctxt, stat); *pvalue = 0x7fffffff; } else { stat = pd_ConsUnsigned (pctxt, &ui, 0, OSUINTCONST(3)); if (stat != 0) return LOG_RTERR (pctxt, stat); switch (ui) { case 0: *pvalue = RUA_processing_overload; break; case 1: *pvalue = RUA_hardware_failure; break; case 2: *pvalue = RUA_o_and_m_intervention; break; case 3: *pvalue = RUA_unspecified_3; break; default: return LOG_RTERR (pctxt, RTERR_INVENUM); } } return (stat); }
EXTRTMETHOD int rtxStreamClose (OSCTXT* pctxt) { OSRTSTREAM *pStream = pctxt->pStream; int stat = 0, stat2 = 0; if (pStream == 0 || pStream->close == 0) return LOG_RTERRNEW (pctxt, RTERR_NOTINIT); if (pStream->flags & OSRTSTRMF_OUTPUT) { stat = rtxStreamFlush (pctxt); } else if (!(pStream->flags & OSRTSTRMF_INPUT)) return LOG_RTERRNEW (pctxt, RTERR_NOTINIT); stat2 = pStream->close (pStream); pStream->flags = 0; rtxMemFreePtr (pctxt, pctxt->pStream); pctxt->pStream = 0; if ( stat != 0 ) return LOG_RTERR (pctxt, stat); else if ( stat2 != 0 ) return LOG_RTERR (pctxt, stat2); else return 0; }
EXTERN int asn1PD_RUA_TypeOfError (OSCTXT* pctxt, RUA_TypeOfError* pvalue) { int stat = 0; OSUINT32 ui; OSBOOL extbit = FALSE; /* extension bit */ stat = PD_BIT (pctxt, &extbit); if (stat != 0) return LOG_RTERR (pctxt, stat); if (extbit) { stat = pd_SmallNonNegWholeNumber (pctxt, &ui); if (stat != 0) return LOG_RTERR (pctxt, stat); *pvalue = 0x7fffffff; } else { stat = pd_ConsUnsigned (pctxt, &ui, 0, OSUINTCONST(1)); if (stat != 0) return LOG_RTERR (pctxt, stat); switch (ui) { case 0: *pvalue = RUA_not_understood; break; case 1: *pvalue = RUA_missing; break; default: return LOG_RTERR (pctxt, RTERR_INVENUM); } } return (stat); }
int berDecStrmLength (OSCTXT *pctxt, int *len_p) { int i, j, stat; OSOCTET b, lbuf[8]; stat = rtxStreamRead (pctxt, &b, 1); if (stat < 0) return LOG_RTERR (pctxt, stat); else stat = b; if (stat > 0x80) { *len_p = 0; i = stat & 0x7F; if (i > 4) return LOG_RTERR (pctxt, ASN_E_INVLEN); stat = rtxStreamRead (pctxt, lbuf, i); if (stat < 0) return LOG_RTERR (pctxt, stat); for (j = 0, *len_p = 0; j < i; j++) { *len_p = (*len_p * 256) + lbuf[j]; } } else if (stat == 0x80) *len_p = ASN_K_INDEFLEN; else *len_p = stat; /* Length is not indefinite length */ if (*len_p != ASN_K_INDEFLEN) { if (*len_p < 0) return LOG_RTERR (pctxt, ASN_E_INVLEN); } return (0); }