utility::stream::size_type body::getGeneratedSize(const generationContext& ctx) { // MIME-Multipart if (getPartCount() != 0) { utility::stream::size_type size = 0; // Size of parts and boundaries for (size_t p = 0 ; p < getPartCount() ; ++p) { size += 100; // boundary, CRLF... size += getPartAt(p)->getGeneratedSize(ctx); } // Size of prolog/epilog text const text prologText = getActualPrologText(ctx); if (!prologText.isEmpty()) { std::ostringstream oss; utility::outputStreamAdapter osa(oss); prologText.encodeAndFold(ctx, osa, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); size += oss.str().size(); } const text epilogText = getActualEpilogText(ctx); if (!epilogText.isEmpty()) { std::ostringstream oss; utility::outputStreamAdapter osa(oss); epilogText.encodeAndFold(ctx, osa, 0, NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE); size += oss.str().size(); } return size; } // Simple body else { ref <utility::encoder::encoder> srcEncoder = m_contents->getEncoding().getEncoder(); ref <utility::encoder::encoder> dstEncoder = getEncoding().getEncoder(); return dstEncoder->getEncodedSize(srcEncoder->getDecodedSize(m_contents->getLength())); } }
// Using 'bufferedStreamCopy' void testStreamCopy() { for (unsigned int i = 0 ; i < charsetTestSuitesCount ; ++i) { const charsetTestSuiteStruct& entry = charsetTestSuites[i]; std::ostringstream testName; testName << i << ": " << entry.fromCharset << " -> " << entry.toCharset; const unsigned long inLength = (entry.fromLength == 0 ? strlen(entry.fromBytes) : entry.fromLength); vmime::string in(entry.fromBytes, entry.fromBytes + inLength); const unsigned long outLength = (entry.toLength == 0 ? strlen(entry.toBytes) : entry.toLength); vmime::string expectedOut(entry.toBytes, entry.toBytes + outLength); vmime::string actualOut; vmime::utility::outputStreamStringAdapter osa(actualOut); vmime::ref <vmime::charsetConverter> conv = vmime::charsetConverter::create(entry.fromCharset, entry.toCharset); vmime::ref <vmime::utility::charsetFilteredOutputStream> os = conv->getFilteredOutputStream(osa); VASSERT_NOT_NULL("filteredOutputStream availability", os); vmime::utility::inputStreamStringAdapter is(in); vmime::utility::bufferedStreamCopy(is, *os); os->flush(); VASSERT_EQ(testName.str(), toHex(expectedOut), toHex(actualOut)); } }
void testInvalidInput1() { vmime::string in("foo\xab\xcd\xef bar"); vmime::string expectedOut("foo??? bar"); vmime::string actualOut; vmime::utility::outputStreamStringAdapter osa(actualOut); vmime::ref <vmime::charsetConverter> conv = vmime::charsetConverter::create (vmime::charset("utf-8"), vmime::charset("iso-8859-1")); vmime::ref <vmime::utility::charsetFilteredOutputStream> os = conv->getFilteredOutputStream(osa); VASSERT_NOT_NULL("filteredOutputStream availability", os); vmime::utility::inputStreamStringAdapter is(in); vmime::utility::stream::value_type buffer[16]; for (int i = 0 ; !is.eof() ; ++i) os->write(buffer, is.read(buffer, 1)); os->flush(); VASSERT_EQ("1", toHex(expectedOut), toHex(actualOut)); }
size_t headerFieldValue::getGeneratedSize(const generationContext& ctx) { std::ostringstream oss; utility::outputStreamAdapter osa(oss); generate(ctx, osa); return oss.str().length(); }
void testGenerate() { vmime::emptyContentHandler cth; std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.generate(osa, vmime::encoding("base64")); VASSERT_EQ("generate", "", oss.str()); }
void testExtractRaw() { vmime::emptyContentHandler cth; std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.extractRaw(osa); VASSERT_EQ("extractRaw", "", oss.str()); }
int main(int argc,char *argv[]) { int orig,flags=SDL_OPENGL|SDL_FULLSCREEN; SDL_Event e; SDL_AudioSpec w; if(argc>1) if(!strcmp(argv[1],"-w")) flags-=SDL_FULLSCREEN; if(argv[0][strlen(argv[0])-1]=='w') flags-=SDL_FULLSCREEN; SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER); w.freq=44100; w.format=AUDIO_S16SYS; w.channels=2; #ifdef BLKSIZE w.samples=BLKSIZE; #else w.samples=1024; #endif w.callback=pakki; w.userdata=NULL; SDL_OpenAudio(&w,NULL); syna_init(44100); if(syna_get(biisi)<0) return(EXIT_FAILURE); SDL_SetVideoMode(1024,768,32,flags); SDL_WM_SetCaption("Yellow Rose of Texas",0); SDL_ShowCursor(0); SDL_PauseAudio(0); orig=SDL_GetTicks(); while(!quit) { if(osa(SDL_GetTicks()-orig)==0) SDL_GL_SwapBuffers(); while(SDL_PollEvent(&e)>0) { if(e.type==SDL_MOUSEBUTTONDOWN) quit=1; if(e.type==SDL_KEYDOWN) quit=1; } } SDL_Quit(); return(0); }
void testExtract() { vmime::fileContentHandler cth(testFile, vmime::encoding("base64")); std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.extract(osa); // Data should be decoded from B64 VASSERT_EQ("extract", testDataDecoded, oss.str()); }
void testGenerate() { vmime::fileContentHandler cth(testFile, vmime::encoding("base64")); std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.generate(osa, vmime::encoding("quoted-printable")); // Data should be reencoded from B64 to QP VASSERT_EQ("generate", "ABCDEFGHIJKLMNOPQRSTUVWXYZ =124Vx=90 abcdefghijklmnopqrstuvwxyz0123456789", oss.str()); }
VMIME_TEST_LIST_END static const vmime::string extractContent (vmime::shared_ptr <const vmime::contentHandler> cth) { std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth->extract(osa); return oss.str(); }
void testExtract() { vmime::string data("Test Data"); vmime::shared_ptr <vmime::utility::inputStream> stream = vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data); vmime::streamContentHandler cth(stream, data.length()); std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.extract(osa); VASSERT_EQ("extract", "Test Data", oss.str()); }
void testGenerate_Encoded() { vmime::string data("foo=12=34=56bar"); vmime::shared_ptr <vmime::utility::inputStream> stream = vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data); vmime::streamContentHandler cth(stream, data.length(), vmime::encoding("quoted-printable")); std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.generate(osa, vmime::encoding("base64")); // Data should be reencoded from QP to B64 VASSERT_EQ("generate", "Zm9vEjRWYmFy", oss.str()); }
void testGenerate() { vmime::string data("foo\x12\x34\x56 bar"); vmime::shared_ptr <vmime::utility::inputStream> stream = vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data); vmime::streamContentHandler cth(stream, data.length()); std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.generate(osa, vmime::encoding("base64")); // Data should be encoded to B64 VASSERT_EQ("generate", "Zm9vEjRWIGJhcg==", oss.str()); }
void testExtractRaw_Encoded() { vmime::string data ("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODk="); vmime::shared_ptr <vmime::utility::inputStream> stream = vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data); vmime::streamContentHandler cth(stream, data.length(), vmime::encoding("base64")); std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.extractRaw(osa); // Data should not be decoded VASSERT_EQ("extractRaw", "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODk=", oss.str()); }
void testExtract_Encoded() { vmime::string data ("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODk="); vmime::shared_ptr <vmime::utility::inputStream> stream = vmime::make_shared <vmime::utility::inputStreamStringAdapter>(data); vmime::streamContentHandler cth(stream, data.length(), vmime::encoding("base64")); std::ostringstream oss; vmime::utility::outputStreamAdapter osa(oss); cth.extract(osa); // Data should be decoded from B64 VASSERT_EQ("extract", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", oss.str()); }
void supply(struct sockaddr *dst, int flags, struct interface *ifp, int rtstate) { struct rt_entry *rt; struct netinfo *n = msg->rip_nets; struct rthash *rh; struct rthash *base = hosthash; int doinghost = 1, size; void (*output)(int,int,struct sockaddr *,int) = afswitch[dst->sa_family].af_output; int (*sendroute)(struct rt_entry *, struct sockaddr *) = afswitch[dst->sa_family].af_sendroute; int npackets = 0; msg->rip_cmd = RIPCMD_RESPONSE; msg->rip_vers = RIPVERSION; memset(&msg->rip_res1, 0, sizeof(msg->rip_res1)); again: for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { /* * Don't resend the information on the network * from which it was received (unless sending * in response to a query). */ if (ifp && rt->rt_ifp == ifp && (rt->rt_state & RTS_INTERFACE) == 0) continue; if (rt->rt_state & RTS_EXTERNAL) continue; /* * For dynamic updates, limit update to routes * with the specified state. */ if (rtstate && (rt->rt_state & rtstate) == 0) continue; /* * Limit the spread of subnet information * to those who are interested. */ if (doinghost == 0 && rt->rt_state & RTS_SUBNET) { if (rt->rt_dst.sa_family != dst->sa_family) continue; if ((*sendroute)(rt, dst) == 0) continue; } size = (char *)n - packet; if (size > MAXPACKETSIZE - (int)sizeof (struct netinfo)) { TRACE_OUTPUT(ifp, dst, size); (*output)(sock, flags, dst, size); /* * If only sending to ourselves, * one packet is enough to monitor interface. */ if (ifp && (ifp->int_flags & (IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0) return; n = msg->rip_nets; npackets++; } n->rip_dst = rt->rt_dst; #if BSD < 198810 if (sizeof(n->rip_dst.sa_family) > 1) /* XXX */ n->rip_dst.sa_family = htons(n->rip_dst.sa_family); #else #define osa(x) ((struct osockaddr *)(&(x))) osa(n->rip_dst)->sa_family = htons(n->rip_dst.sa_family); #endif n->rip_metric = htonl(rt->rt_metric); n++; } if (doinghost) { doinghost = 0; base = nethash; goto again; } if (n != msg->rip_nets || (npackets == 0 && rtstate == 0)) { size = (char *)n - packet; TRACE_OUTPUT(ifp, dst, size); (*output)(sock, flags, dst, size); } }