Skip to content

Commit

Permalink
fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrain2012 committed Jun 29, 2019
1 parent bf6c9c6 commit 24d7601
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions mars/proto/src/shortlink_packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,37 @@ namespace mars { namespace stn {
}
}

std::string GetEncodedCid() {
return getEncodedId(false);
}

std::string GetEncodeData(std::string pbData) {
unsigned int tmpLen = 0;
unsigned char *ptmp = encrypt_data((const unsigned char*)pbData.c_str(), (unsigned int)pbData.length(), &tmpLen, false);

int dstlen = modp_b64_encode_len(tmpLen);

unsigned char* dstbuf = (unsigned char*)malloc(dstlen);
memset(dstbuf, 0, dstlen);

int retsize = Comm::EncodeBase64(ptmp, (unsigned char*)dstbuf, tmpLen);
dstbuf[retsize] = '\0';

free(ptmp);
ptmp = NULL;
tmpLen = 0;

tmpLen = retsize;
ptmp = dstbuf;

std::string out((char*)ptmp, tmpLen);

free(ptmp);
ptmp = NULL;
tmpLen = 0;
return out;
}

std::map<std::string, std::string> stringToMap(std::string &str)
{
std::map<std::string, std::string> out;
Expand Down Expand Up @@ -124,47 +155,26 @@ void (*shortlink_pack)(const std::string& _url, const std::map<std::string, std:
req_builder.Fields().HeaderFiled("cid", getEncodedId(false).c_str());
if(_url == "/route") {
encodedUserId.clear();
req_builder.Fields().HeaderFiled("uid", getEncodedId(true).c_str());
}
req_builder.Fields().HeaderFiled("uid", getEncodedId(true).c_str());

for (std::map<std::string, std::string>::const_iterator iter = _headers.begin(); iter != _headers.end(); ++iter) {
req_builder.Fields().HeaderFiled(iter->first.c_str(), iter->second.c_str());
}
std::string pbData = wrapper.serializeToPBData();

unsigned int tmpLen = 0;
unsigned char *ptmp = encrypt_data((const unsigned char*)pbData.c_str(), (unsigned int)pbData.length(), &tmpLen, false);
std::string encodedData = GetEncodeData(pbData);

char buffer[9];
memset(buffer, 0, 9);
sprintf(buffer, "%d", (int)encodedData.length());


int dstlen = modp_b64_encode_len(tmpLen);

unsigned char* dstbuf = (unsigned char*)malloc(dstlen);
memset(dstbuf, 0, dstlen);

int retsize = Comm::EncodeBase64(ptmp, (unsigned char*)dstbuf, tmpLen);
dstbuf[retsize] = '\0';

free(ptmp);
ptmp = NULL;
tmpLen = 0;

tmpLen = retsize;
ptmp = dstbuf;

char buffer[9];
memset(buffer, 0, 9);
sprintf(buffer, "%d", (int)tmpLen);
req_builder.Fields().HeaderFiled(http::HeaderFields::KStringContentLength, buffer);
req_builder.Fields().HeaderFiled(http::HeaderFields::KStringContentType, "application/octet-stream");

req_builder.Request().Url(_url);
req_builder.HeaderToBuffer(_out_buff);
_out_buff.Write(ptmp, tmpLen);

free(ptmp);
ptmp = NULL;
tmpLen = 0;
_out_buff.Write(encodedData.c_str(), encodedData.length());
} else {
std::map<std::string, std::string> parsedMap = stringToMap(strMap);
std::string method = parsedMap["method"];
Expand Down

0 comments on commit 24d7601

Please sign in to comment.