| 103 | } |
| 104 | |
| 105 | ParseResult ParseRpcMessage(butil::IOBuf* source, Socket* socket, |
| 106 | bool /*read_eof*/, const void*) { |
| 107 | char header_buf[12]; |
| 108 | const size_t n = source->copy_to(header_buf, sizeof(header_buf)); |
| 109 | if (n >= 4) { |
| 110 | void* dummy = header_buf; |
| 111 | if (*(const uint32_t*)dummy != *(const uint32_t*)"PRPC") { |
| 112 | return MakeParseError(PARSE_ERROR_TRY_OTHERS); |
| 113 | } |
| 114 | } else { |
| 115 | if (memcmp(header_buf, "PRPC", n) != 0) { |
| 116 | return MakeParseError(PARSE_ERROR_TRY_OTHERS); |
| 117 | } |
| 118 | } |
| 119 | if (n < sizeof(header_buf)) { |
| 120 | return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA); |
| 121 | } |
| 122 | uint32_t body_size; |
| 123 | uint32_t meta_size; |
| 124 | butil::RawUnpacker(header_buf + 4).unpack32(body_size).unpack32(meta_size); |
| 125 | if (body_size > FLAGS_max_body_size) { |
| 126 | // We need this log to report the body_size to give users some clues |
| 127 | // which is not printed in InputMessenger. |
| 128 | LOG(ERROR) << "body_size=" << body_size << " from " |
| 129 | << socket->remote_side() << " is too large"; |
| 130 | return MakeParseError(PARSE_ERROR_TOO_BIG_DATA); |
| 131 | } else if (source->length() < sizeof(header_buf) + body_size) { |
| 132 | return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA); |
| 133 | } |
| 134 | if (meta_size > body_size) { |
| 135 | LOG(ERROR) << "meta_size=" << meta_size << " is bigger than body_size=" |
| 136 | << body_size; |
| 137 | // Pop the message |
| 138 | source->pop_front(sizeof(header_buf) + body_size); |
| 139 | return MakeParseError(PARSE_ERROR_TRY_OTHERS); |
| 140 | } |
| 141 | source->pop_front(sizeof(header_buf)); |
| 142 | MostCommonMessage* msg = MostCommonMessage::Get(); |
| 143 | source->cutn(&msg->meta, meta_size); |
| 144 | source->cutn(&msg->payload, body_size - meta_size); |
| 145 | return MakeMessage(msg); |
| 146 | } |
| 147 | |
| 148 | bool SerializeRpcMessage(const google::protobuf::Message& message, |
| 149 | Controller& cntl, ContentType content_type, |
no test coverage detected