/** Parse a service registration. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] srvreg - The service registration object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseSrvReg(SLPBuffer buffer, SLPSrvReg * srvreg) { int result; /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | <URL-Entry> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of service type string | <service-type> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <scope-list> | <scope-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of attr-list string | <attr-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of AttrAuths |(if present) Attribute Authentication Blocks...\ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Parse the <URL-Entry>. */ result = v2ParseUrlEntry(buffer, &srvreg->urlentry); if (result != 0) return result; /* Parse the <service-type> string. */ srvreg->srvtypelen = GetUINT16(&buffer->curpos); srvreg->srvtype = GetStrPtr(&buffer->curpos, srvreg->srvtypelen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <scope-list> string. */ srvreg->scopelistlen = GetUINT16(&buffer->curpos); srvreg->scopelist = GetStrPtr(&buffer->curpos, srvreg->scopelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <attr-list> string. */ srvreg->attrlistlen = GetUINT16(&buffer->curpos); srvreg->attrlist = GetStrPtr(&buffer->curpos, srvreg->attrlistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse AttrAuth block list (if present). */ srvreg->authcount = *buffer->curpos++; if (srvreg->authcount) { int i; srvreg->autharray = xmalloc(srvreg->authcount * sizeof(SLPAuthBlock)); if (srvreg->autharray == 0) return SLP_ERROR_INTERNAL_ERROR; memset(srvreg->autharray, 0, srvreg->authcount * sizeof(SLPAuthBlock)); for (i = 0; i < srvreg->authcount; i++) { result = v2ParseAuthBlock(buffer, &srvreg->autharray[i]); if (result != 0) return result; } } return 0; }
/** Parse a service request. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] srvrqst - The service request object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseSrvRqst(SLPBuffer buffer, SLPSrvRqst * srvrqst) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <PRList> | <PRList> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <service-type> | <service-type> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <scope-list> | <scope-list> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of predicate string | Service Request <predicate> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <SLP SPI> string | <SLP SPI> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce v2 service request size limits. */ if (buffer->end - buffer->curpos < 10) return SLP_ERROR_PARSE_ERROR; /* Parse the <PRList> string. */ srvrqst->prlistlen = GetUINT16(&buffer->curpos); srvrqst->prlist = GetStrPtr(&buffer->curpos, srvrqst->prlistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <service-type> string. */ srvrqst->srvtypelen = GetUINT16(&buffer->curpos); srvrqst->srvtype = GetStrPtr(&buffer->curpos, srvrqst->srvtypelen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <scope-list> string. */ srvrqst->scopelistlen = GetUINT16(&buffer->curpos); srvrqst->scopelist = GetStrPtr(&buffer->curpos, srvrqst->scopelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <predicate> string. */ srvrqst->predicatever = 2; /* SLPv2 predicate (LDAPv3) */ srvrqst->predicatelen = GetUINT16(&buffer->curpos); srvrqst->predicate = GetStrPtr(&buffer->curpos, srvrqst->predicatelen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <SLP SPI> string. */ srvrqst->spistrlen = GetUINT16(&buffer->curpos); srvrqst->spistr = GetStrPtr(&buffer->curpos, srvrqst->spistrlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; return 0; }
/** Parse an attribute request. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] attrrqst - The attribute request object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseAttrRqst(SLPBuffer buffer, SLPAttrRqst * attrrqst) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of PRList | <PRList> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <scope-list> | <scope-list> string \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <tag-list> string | <tag-list> string \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <SLP SPI> string | <SLP SPI> string \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce v2 attribute request size limits. */ if (buffer->end - buffer->curpos < 10) return SLP_ERROR_PARSE_ERROR; /* Parse the <PRList> string. */ attrrqst->prlistlen = GetUINT16(&buffer->curpos); attrrqst->prlist = GetStrPtr(&buffer->curpos, attrrqst->prlistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the URL. */ attrrqst->urllen = GetUINT16(&buffer->curpos); attrrqst->url = GetStrPtr(&buffer->curpos, attrrqst->urllen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <scope-list> string. */ attrrqst->scopelistlen = GetUINT16(&buffer->curpos); attrrqst->scopelist = GetStrPtr(&buffer->curpos, attrrqst->scopelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <tag-list> string. */ attrrqst->taglistlen = GetUINT16(&buffer->curpos); attrrqst->taglist = GetStrPtr(&buffer->curpos, attrrqst->taglistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <SLP SPI> string. */ attrrqst->spistrlen = GetUINT16(&buffer->curpos); attrrqst->spistr = GetStrPtr(&buffer->curpos, attrrqst->spistrlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; return 0; }
CInetMsgPart::CInetMsgPart( PMessage Message, LPSTR lpData, DWORD dwSize ) : CMsgPartT( Message ) { LPSTR Last = lpData + dwSize; StrPtr sp = { NULL, 0, lpData }; while ( sp.Nxt ) { GetStrPtr( sp.Nxt, &sp, Last ); if ( sp.Len == 0 ) break; sp.Str[ sp.Len ] = '\0'; if ( ( *sp.Str == '\t' || *sp.Str == '\x20' ) && m_Kludges->Count() > 0 ) { *sp.Str = '\t'; // unfold strcat( m_Kludges->At( m_Kludges->Count() - 1 ), sp.Str ); } else { m_Kludges->Add( sp.Str ); } } m_Content->data = (PBYTE)sp.Nxt; m_Content->size = sp.Nxt? dwSize - ( sp.Nxt - lpData ) : 0; }
/** Parse an attribute reply. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] attrrply - The attribute reply object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseAttrRply(SLPBuffer buffer, SLPAttrRply * attrrply) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error Code | length of <attr-list> | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | <attr-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of AttrAuths | Attribute Authentication Block (if present) \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce SLPv2 attribute request size limits. */ if (buffer->end - buffer->curpos < 5) return SLP_ERROR_PARSE_ERROR; /* Parse the Error Code. */ attrrply->errorcode = GetUINT16(&buffer->curpos); if (attrrply->errorcode) { /* Don't trust the rest of the packet. */ int err = attrrply->errorcode; memset(attrrply, 0, sizeof(SLPAttrRply)); attrrply->errorcode = err; return 0; } /* Parse the <attr-list>. */ attrrply->attrlistlen = GetUINT16(&buffer->curpos); attrrply->attrlist = GetStrPtr(&buffer->curpos, attrrply->attrlistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the Attribute Authentication Block list (if present). */ attrrply->authcount = *buffer->curpos++; if (attrrply->authcount) { int i; attrrply->autharray = xmalloc(attrrply->authcount * sizeof(SLPAuthBlock)); if (attrrply->autharray == 0) return SLP_ERROR_INTERNAL_ERROR; memset(attrrply->autharray, 0, attrrply->authcount * sizeof(SLPAuthBlock)); for (i = 0; i < attrrply->authcount; i++) { int result = v2ParseAuthBlock(buffer, &attrrply->autharray[i]); if (result != 0) return result; } } /* Terminate the attr list for caller convenience - overwrites the * first byte of the "# of AttrAuths" field, but we've processed it. */ if(attrrply->attrlist) ((uint8_t *)attrrply->attrlist)[attrrply->attrlistlen] = 0; return 0; }
/** Parse a URL entry. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] urlentry - The URL entry object into which * @p buffer should be parsed. * * @return Zero on success, SLP_ERROR_INTERNAL_ERROR (out of memory) * or SLP_ERROR_PARSE_ERROR. * * @internal */ static int v2ParseUrlEntry(SLPBuffer buffer, SLPUrlEntry * urlentry) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reserved | Lifetime | URL Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |URL len, contd.| URL (variable length) \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of URL auths | Auth. blocks (if any) \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce SLPv2 URL entry size limits. */ if (buffer->end - buffer->curpos < 6) return SLP_ERROR_PARSE_ERROR; /* Save pointer to opaque URL entry block. */ urlentry->opaque = buffer->curpos; /* Parse individual URL entry fields. */ urlentry->reserved = *buffer->curpos++; urlentry->lifetime = GetUINT16(&buffer->curpos); urlentry->urllen = GetUINT16(&buffer->curpos); urlentry->url = GetStrPtr(&buffer->curpos, urlentry->urllen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse authentication block. */ urlentry->authcount = *buffer->curpos++; if (urlentry->authcount) { int i; urlentry->autharray = xmalloc(urlentry->authcount * sizeof(SLPAuthBlock)); if (urlentry->autharray == 0) return SLP_ERROR_INTERNAL_ERROR; memset(urlentry->autharray, 0, urlentry->authcount * sizeof(SLPAuthBlock)); for (i = 0; i < urlentry->authcount; i++) { int result = v2ParseAuthBlock(buffer, &urlentry->autharray[i]); if (result != 0) return result; } } urlentry->opaquelen = buffer->curpos - urlentry->opaque; /* Terminate the URL string for caller convenience - we're overwriting * the first byte of the "# of URL auths" field, but it's okay because * we've already read and stored it away. */ if(urlentry->url) ((uint8_t *)urlentry->url)[urlentry->urllen] = 0; return 0; }
/** Parse a service type request. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] srvtyperqst - The service type request object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseSrvTypeRqst(SLPBuffer buffer, SLPSrvTypeRqst * srvtyperqst) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of PRList | <PRList> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of Naming Authority | <Naming Authority String> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of <scope-list> | <scope-list> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce SLPv2 service type request size limits. */ if (buffer->end - buffer->curpos < 6) return SLP_ERROR_PARSE_ERROR; /* Parse the PRList. */ srvtyperqst->prlistlen = GetUINT16(&buffer->curpos); srvtyperqst->prlist = GetStrPtr(&buffer->curpos, srvtyperqst->prlistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the Naming Authority. */ srvtyperqst->namingauthlen = GetUINT16(&buffer->curpos); if (srvtyperqst->namingauthlen == 0 || srvtyperqst->namingauthlen == 0xffff) srvtyperqst->namingauth = 0; else srvtyperqst->namingauth = GetStrPtr(&buffer->curpos, srvtyperqst->namingauthlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <scope-list>. */ srvtyperqst->scopelistlen = GetUINT16(&buffer->curpos); srvtyperqst->scopelist = GetStrPtr(&buffer->curpos, srvtyperqst->scopelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; return 0; }
/** Parse a service deregistration. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] srvdereg - The service deregistration object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseSrvDeReg(SLPBuffer buffer, SLPSrvDeReg * srvdereg) { int result; /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of <scope-list> | <scope-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | URL Entry \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of <tag-list> | <tag-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce SLPv2 service deregister size limits. */ if (buffer->end - buffer->curpos < 4) return SLP_ERROR_PARSE_ERROR; /* Parse the <scope-list>. */ srvdereg->scopelistlen = GetUINT16(&buffer->curpos); srvdereg->scopelist = GetStrPtr(&buffer->curpos, srvdereg->scopelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the URL entry. */ result = v2ParseUrlEntry(buffer, &srvdereg->urlentry); if (result) return result; /* Parse the <tag-list>. */ srvdereg->taglistlen = GetUINT16(&buffer->curpos); srvdereg->taglist = GetStrPtr(&buffer->curpos, srvdereg->taglistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; return 0; }
/** Parse an SLPv2 message header. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] header - The address of a message header into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code, either * SLP_ERROR_VER_NOT_SUPPORTED or SLP_ERROR_PARSE_ERROR. */ int SLPv2MessageParseHeader(SLPBuffer buffer, SLPHeader * header) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Version | Function-ID | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length, contd.|O|F|R| reserved |Next Ext Offset| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next Extension Offset, contd.| XID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Language Tag Length | Language Tag \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Check for invalid length - 18 bytes is the smallest v2 message. */ if (buffer->end - buffer->start < 18) return SLP_ERROR_PARSE_ERROR; /* Parse header fields. */ header->version = *buffer->curpos++; header->functionid = *buffer->curpos++; header->length = GetUINT24(&buffer->curpos); header->flags = GetUINT16(&buffer->curpos); header->encoding = 0; /* not used for SLPv2 */ header->extoffset = GetUINT24(&buffer->curpos); header->xid = GetUINT16(&buffer->curpos); header->langtaglen = GetUINT16(&buffer->curpos); header->langtag = GetStrPtr(&buffer->curpos, header->langtaglen); /* Enforce language tag size limits. */ if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Enforce function id range. */ if (header->functionid < SLP_FUNCT_SRVRQST || header->functionid > SLP_FUNCT_SAADVERT) return SLP_ERROR_PARSE_ERROR; /* Enforce reserved flags constraint. */ if (header->flags & 0x1fff) return SLP_ERROR_PARSE_ERROR; /* Enforce extension offset limits. */ if (buffer->start + header->extoffset > buffer->end) return SLP_ERROR_PARSE_ERROR; return 0; }
void CMailViewTpl::processText( int len, IWriteSink & f ) { // TODO: check File FarFileName bodyFile = FarFileName::MakeTemp( "mvb" ); File::mkdirs( bodyFile.GetPath() ); PMsgPart TextPart = m_origMsg->GetTextPart(); if ( TextPart ) { long Encoding = GetMsgEncoding( m_origMsg, TextPart, m_defaultEncoding ); if ( len > 20 ) { FarStringArray Src; StrPtr sp = { NULL, 0, (LPSTR)TextPart->GetContentData() }; LPCSTR Last = sp.Nxt + TextPart->GetContentSize(); while ( sp.Nxt ) { GetStrPtr( sp.Nxt, &sp, Last ); Src.Add( ToOEMString( FarString( sp.Str, sp.Len ), Encoding ) ); } FarStringArray * Dst = WordWrapLines( Src, len, true ); for ( int i = 0; i < Dst->Count(); i ++ ) { f.write( Dst->At( i ), strlen( Dst->At( i ) ) ); f.write( "\r\n", 2 ); } delete Dst; } else { FarString s = (LPCSTR)TextPart->GetContentData(); s.SetLength( TextPart->GetContentSize() ); s = ToOEMString( s, Encoding ); f.write( s.c_str(), s.Length() ); } File::deleteit( bodyFile ); } }
/** Parse a service type reply. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] srvtyperply - The service type reply object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseSrvTypeRply(SLPBuffer buffer, SLPSrvTypeRply * srvtyperply) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error Code | length of <srvType-list> | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | <srvtype--list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce SLPv2 service type reply size limits. */ if (buffer->end - buffer->curpos < 4) return SLP_ERROR_PARSE_ERROR; /* Parse the Error Code. */ srvtyperply->errorcode = GetUINT16(&buffer->curpos); if (srvtyperply->errorcode) { /* Don't trust the rest of the packet. */ int err = srvtyperply->errorcode; memset(srvtyperply, 0, sizeof(SLPSrvTypeRply)); srvtyperply->errorcode = err; return 0; } /* Parse the <srvType-list>. */ srvtyperply->srvtypelistlen = GetUINT16(&buffer->curpos); srvtyperply->srvtypelist = GetStrPtr(&buffer->curpos, srvtyperply->srvtypelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Terminate the service type list string for caller convenience - while * it appears that we're writing one byte past the end of the buffer here, * it's not so - message buffers are always allocated one byte larger than * requested for just this reason. */ if(srvtyperply->srvtypelist) ((uint8_t *)srvtyperply->srvtypelist)[srvtyperply->srvtypelistlen] = 0; return 0; }
/** Parse an authentication block. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] authblock - The authentication block object into which * @p buffer should be parsed. * * @return Zero on success, SLP_ERROR_INTERNAL_ERROR (out of memory) * or SLP_ERROR_PARSE_ERROR. * * @internal */ static int v2ParseAuthBlock(SLPBuffer buffer, SLPAuthBlock * authblock) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Block Structure Descriptor | Authentication Block Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | SLP SPI String Length | SLP SPI String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Structured Authentication Block ... \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce v2 authentication block size limits. */ if (buffer->end - buffer->curpos < 10) return SLP_ERROR_PARSE_ERROR; /* Save pointer to opaque authentication block. */ authblock->opaque = buffer->curpos; /* Parse individual authentication block fields. */ authblock->bsd = GetUINT16(&buffer->curpos); authblock->length = GetUINT16(&buffer->curpos); authblock->timestamp = GetUINT32(&buffer->curpos); authblock->spistrlen = GetUINT16(&buffer->curpos); authblock->spistr = GetStrPtr(&buffer->curpos, authblock->spistrlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse structured authentication block. */ authblock->authstruct = (char *)buffer->curpos; authblock->opaquelen = authblock->length; buffer->curpos = authblock->opaque + authblock->length; if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; return 0; }
/** Parse an SA advertisement. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] saadvert - The SA advertisement object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseSAAdvert(SLPBuffer buffer, SLPSAAdvert * saadvert) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of <scope-list> | <scope-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of <attr-list> | <attr-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # auth blocks | authentication block (if any) \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce SLPv2 SA advertisement size limits. */ if (buffer->end - buffer->curpos < 7) return SLP_ERROR_PARSE_ERROR; /* Parse out the URL. */ saadvert->urllen = GetUINT16(&buffer->curpos); saadvert->url = GetStrPtr(&buffer->curpos, saadvert->urllen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <scope-list>. */ saadvert->scopelistlen = GetUINT16(&buffer->curpos); saadvert->scopelist = GetStrPtr(&buffer->curpos, saadvert->scopelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <attr-list>. */ saadvert->attrlistlen = GetUINT16(&buffer->curpos); saadvert->attrlist = GetStrPtr(&buffer->curpos, saadvert->attrlistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the authentication block list (if any). */ saadvert->authcount = *buffer->curpos++; if (saadvert->authcount) { int i; saadvert->autharray = xmalloc(saadvert->authcount * sizeof(SLPAuthBlock)); if (saadvert->autharray == 0) return SLP_ERROR_INTERNAL_ERROR; memset(saadvert->autharray, 0, saadvert->authcount * sizeof(SLPAuthBlock)); for (i = 0; i < saadvert->authcount; i++) { int result = v2ParseAuthBlock(buffer, &saadvert->autharray[i]); if (result != 0) return result; } } /* Terminate the URL string for caller convenience - we're overwriting * the first byte of the "Length of <scope-list>" field, but it's okay * because we've already read and stored it away. */ if(saadvert->url) ((uint8_t *)saadvert->url)[saadvert->urllen] = 0; return 0; }
/** Parse a DA advertisement. * * @param[in] buffer - The buffer from which data should be parsed. * @param[out] daadvert - The DA advertisement object into which * @p buffer should be parsed. * * @return Zero on success, or a non-zero error code. * * @internal */ static int v2ParseDAAdvert(SLPBuffer buffer, SLPDAAdvert * daadvert) { /* 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error Code | DA Stateless Boot Timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |DA Stateless Boot Time,, contd.| Length of URL | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \ URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of <scope-list> | <scope-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of <attr-list> | <attr-list> \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of <SLP SPI List> | <SLP SPI List> String \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # Auth Blocks | Authentication block (if any) \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ /* Enforce SLPv2 DA advertisement size limits. */ if (buffer->end - buffer->curpos < 15) return SLP_ERROR_PARSE_ERROR; /* Parse the Error Code. */ daadvert->errorcode = GetUINT16(&buffer->curpos); if (daadvert->errorcode) { /* Don't trust the rest of the packet. */ int err = daadvert->errorcode; memset(daadvert, 0, sizeof(SLPDAAdvert)); daadvert->errorcode = err; return 0; } /* Parse the DA Stateless Boot Timestamp. */ daadvert->bootstamp = GetUINT32(&buffer->curpos); /* Parse out the URL. */ daadvert->urllen = GetUINT16(&buffer->curpos); daadvert->url = GetStrPtr(&buffer->curpos, daadvert->urllen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <scope-list>. */ daadvert->scopelistlen = GetUINT16(&buffer->curpos); daadvert->scopelist = GetStrPtr(&buffer->curpos, daadvert->scopelistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <attr-list>. */ daadvert->attrlistlen = GetUINT16(&buffer->curpos); daadvert->attrlist = GetStrPtr(&buffer->curpos, daadvert->attrlistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the <SLP SPI List> String. */ daadvert->spilistlen = GetUINT16(&buffer->curpos); daadvert->spilist = GetStrPtr(&buffer->curpos, daadvert->spilistlen); if (buffer->curpos > buffer->end) return SLP_ERROR_PARSE_ERROR; /* Parse the authentication block list (if any). */ daadvert->authcount = *buffer->curpos++; if (daadvert->authcount) { int i; daadvert->autharray = xmalloc(sizeof(SLPAuthBlock) * daadvert->authcount); if (daadvert->autharray == 0) return SLP_ERROR_INTERNAL_ERROR; memset(daadvert->autharray, 0, sizeof(SLPAuthBlock) * daadvert->authcount); for (i = 0; i < daadvert->authcount; i++) { int result = v2ParseAuthBlock(buffer, &daadvert->autharray[i]); if (result != 0) return result; } } /* Terminate the URL string for caller convenience - we're overwriting * the first byte of the "Length of <scope-list>" field, but it's okay * because we've already read and stored it away. */ if(daadvert->url) ((uint8_t *)daadvert->url)[daadvert->urllen] = 0; return 0; }