/** * Create a DerGeneralizedTime with the given milliseconds since 1970. * @param msSince1970 The timestamp as milliseconds since Jan 1, 1970. */ DerGeneralizedTime(MillisecondsSince1970 msSince1970) : DerNode(DerNodeType_GeneralizedTime) { std::string derTime = toDerTimeString(msSince1970); payloadAppend((const uint8_t*)&derTime[0], derTime.size()); encodeHeader(payloadPosition_); }
/** *Create a new DerBoolean for the value. * @param value The value to encode. */ DerBoolean(bool value) : DerNode(DerNodeType_Boolean) { uint8_t val = value ? 0xff : 0x00; payloadAppend(&val, 1); encodeHeader(1); }
/** * Create a DerBitString with the given padding and inputBuf. * @param inputBuf An input buffer containing the bit octets to encode. * @param inputBufLength The number of bytes in inputBuf. * @param paddingLength The number of bits of padding at the end of the bit * string. Should be less than 8. */ DerBitString(const uint8_t* inputBuf, size_t inputBufLength, int paddingLength) : DerNode(DerNodeType_BitString) { uint8_t pad = paddingLength & 0xff; payloadAppend(&pad, 1); payloadAppend(inputBuf, inputBufLength); encodeHeader(payloadPosition_); }
/** * Create a DerByteString with the given inputData and nodeType. This is a * protected constructor used by one of the public subclasses such as * DerOctetString or DerPrintableString. * @param inputData An input buffer containing the string to encode. * @param inputDataLength The length of inputData. * @param nodeType The specific DER node type. */ DerByteString (const uint8_t* inputData, size_t inputDataLength, DerNodeType nodeType) : DerNode(nodeType) { if (inputData) { payloadAppend(inputData, inputDataLength); encodeHeader(inputDataLength); } }
unique_ptr<IOBuf> HPACKEncoder::encode(const vector<HPACKHeader>& headers, uint32_t headroom) { table_.clearSkippedReferences(); if (headroom) { buffer_.addHeadroom(headroom); } encodeDelta(headers); for (const auto& header : headers) { if (willBeAdded(header)) { encodeEvictedReferences(header); } encodeHeader(header); } return buffer_.release(); }
/** * Create a DerNull. */ DerNull() : DerNode(DerNodeType_Null) { encodeHeader(0); }
/** * Format a mailmessage in a RFC2822 string */ char * MailMessage::format() { // If the message is empty, return null if ( empty() ) { LOG.debug("MailMessage::format: empty message."); return 0; } StringBuffer ret; LOG.debug("MailMessage::format START"); if ( contentType.empty() ) { if ( attachments.size() ) { contentType = "multipart/mixed"; } else { contentType = body.getMimeType(); if (headers.size() > 0) { StringBuffer *line; int j = 0; for (line=(StringBuffer *)headers.front(); line; line=(StringBuffer *)headers.next() ) { if (strstr(line->c_str(), "format=") != 0 || strstr(line->c_str(),"reply-type=") != 0 ) { contentType.append("; "); line->replaceAll(";", " "); contentType.append(line->c_str()); headers.removeElementAt(j); j--; } j++; } } } } if ( mimeVersion.empty() ) { mimeVersion = "1.0"; } // Add generics headers ret.join((ArrayList &)headers, NL); // Add parsed headers ret += MIMEVERS; ret += mimeVersion; ret += NL; ret += MESSAGEID; ret += messageId; ret += NL; LOG.debug("MailMessage: From: %s\n", from.c_str()); ret += FROM; ret += from; ret += NL; ret += TO; ret += to; ret += NL; if (cc.length() ) { ret += CC; ret += cc; ret += NL; } if (bcc.length() ) { ret += BCC; ret += bcc; ret += NL; } ret += DATE; ret += date.formatRfc822(); ret += NL; ret += SUBJECT; ret += encodeHeader(subject); ret += NL; // add priority ret += IMPORTANCE; ret += convertForImportance(importance); ret += NL; ret += X_PRIORITY; ret += convertForXPriority(importance); ret += NL; ret += MIMETYPE; ret += contentType; ret+= "; "; if (contentType.ifind(MULTIPART) != StringBuffer::npos ){ if ( boundary.empty() ) { generateBoundary(boundary); } ret += "\n boundary=\""; ret += boundary; ret += "\"\n\nThis is a multi-part message in MIME format.\n"; // Prepare a string with the boundary on a line alone StringBuffer bound = "\n--"; bound += boundary; // Body ret += bound; ret += NL; ret += formatBodyPart(body); ret += bound; // Attachments const BodyPart *part; for ( part=(const BodyPart *)attachments.front(); part; part=(BodyPart *)attachments.next() ) { ret += NL; ret += formatBodyPart(*part); ret += bound; } ret += "--\n"; } else { // Body if(body.getCharset()) ret += CT_CHARSET; ret += body.getCharset(); ret += NL; if( body.getEncoding() ) ret += ENCODING; ret += body.getEncoding(); // end of headers ret += NL; ret += NL; ret += body.getContent(); ret += NL; } LOG.debug("MailMessage::format END"); return stringdup(ret.c_str()); }
/// Returns false if the data cannot be written to file. // /// If there is no data, the file is removed and the function returns true. bool SharedObject_as::flush(int space) const { /// This is called on on destruction of the SharedObject, or (allegedly) /// on a call to SharedObject.data, so _data is not guaranteed to exist. // /// The function should never be called from SharedObject.flush() when /// _data is 0. if (!_data) return false; if (space > 0) { log_unimpl("SharedObject.flush() called with a minimum disk space " "argument (%d), which is currently ignored", space); } const std::string& filespec = getFilespec(); if (!mkdirRecursive(filespec)) { log_error("Couldn't create dir for flushing SharedObject %s", filespec); return false; } #ifdef USE_SOL_READONLY log_debug(_("SharedObject %s not flushed (compiled as read-only mode)"), filespec); return false; #endif if (rcfile.getSOLReadOnly()) { log_security("Attempting to write object %s when it's SOL " "Read Only is set! Refusing...", filespec); return false; } // Open file std::ofstream ofs(filespec.c_str(), std::ios::binary); if (!ofs) { log_error("SharedObject::flush(): Failed opening file '%s' in " "binary mode", filespec.c_str()); return false; } // Encode data part. SimpleBuffer buf; if (!encodeData(_name, *_data, buf)) { std::remove(filespec.c_str()); return true; } // Encode header part. SimpleBuffer header; encodeHeader(buf.size(), header); // Write header ofs.write(reinterpret_cast<const char*>(header.data()), header.size()); if (!ofs) { log_error("Error writing SOL header"); return false; } // Write AMF data ofs.write(reinterpret_cast<const char*>(buf.data()), buf.size()); if (!ofs) { log_error("Error writing %d bytes to output file %s", buf.size(), filespec.c_str()); return false; } ofs.close(); log_security("SharedObject '%s' written to filesystem.", filespec); return true; }