Browse Source

Version "(12) Kreuz Köln-Süd": Support for attachments

refactor-result-recursion
Roker 6 years ago
parent
commit
b77b838dad
7 changed files with 74 additions and 11 deletions
  1. +1
    -1
      html/index.html
  2. +1
    -1
      html/interactive.js
  3. +1
    -1
      server/Makefile
  4. +14
    -0
      server/function_map.cc
  5. +12
    -3
      server/mt-server.cc
  6. +38
    -2
      server/pep-types.cc
  7. +7
    -3
      server/security-token.cc

+ 1
- 1
html/index.html View File

@ -27,7 +27,7 @@
<form id="frm" name="frm">
<table class="bigtable" id="bigtable">
<tr><td>Server's Address</td><td> <input type="text" id="server" size="50" maxlength="200" value="http://10.0.0.88:4223/ja/0.1/" </td></tr>
<tr><td>Server's Address</td><td> <input type="text" id="server" size="50" maxlength="200" value="http://10.0.0.89:4223/ja/0.1/" </td></tr>
<tr><td></td><td><input type="button" id="crSess" value="Create Session!" onClick="createSession()"></tr></td>
<tr><td>Open sessions:</td>
<td>


+ 1
- 1
html/interactive.js View File

@ -332,7 +332,7 @@ function button_click()
})
.fail(function( hdr, txt, err) {
var emsg =
"\nAjax POST request returns an: \n"
"\nAjax POST request failed: \n"
+ "Header: " + JSON.stringify(hdr, null, 2) + "\n"
+ "Text: " + JSON.stringify(txt, null, 2) + "\n"
+ "Error:" + JSON.stringify(err, null, 2) + "\n";


+ 1
- 1
server/Makefile View File

@ -1,6 +1,6 @@
.PHONY: all clear
CXXFLAGS = -Wall -O0 -std=c++11 -g -I/home/deb/local/include/ -Ijson_spirit
CXXFLAGS = -Wall -O0 -std=c++11 -g -I/home/deb/local/include/ -Ijson_spirit -fstack-protector-all
LDFLAGS = -L/home/deb/local/lib -lpthread -levent -lpEpEngine -lgpgme-pthread -letpan -lboost_system -lboost_filesystem
all: mt-server


+ 14
- 0
server/function_map.cc View File

@ -171,6 +171,20 @@ std::size_t from_json<std::size_t>(const js::Value& v)
return v.get_uint64();
}
template<>
js::Value to_json<struct tm*>(struct tm* const& t)
{
if(t==nullptr)
{
return js::Value{};
}
char s[32] = "YYYY-MM-DDThh:mm:ss";
snprintf(s,31, "%04u-%02u-%02uT%02u:%02u:%02u", t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
return js::Value{s};
}
template<>
bool from_json<bool>(const js::Value& v)
{


+ 12
- 3
server/mt-server.cc View File

@ -53,7 +53,8 @@ const std::string server_version =
// "(8a) Kreuz Kerpen"; // remove own_key_add() because pEpEngine doesn't have it anymore.
// "(9a) Frechen-Königsdorf"; // add security-token
// "(10) Kreuz Köln-West"; // More fields in JavaScript for "message", 1-element identity list to support message->to attribute
"(11) Köln-Klettenberg"; // support for identity_list as output parameter, as needed by import_key() now. Fix some issue with identity.lang
// "(11) Köln-Klettenberg"; // support for identity_list as output parameter, as needed by import_key() now. Fix some issue with identity.lang
"(12) Kreuz Köln Süd"; // support for attachments, so encrypt_message() works now! :-) but we have memory corruption, hence the FIXME in pep-types.cc :-(
template<>
@ -202,8 +203,16 @@ void sendReplyString(evhttp_request* req, const char* contentType, const std::st
{
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", contentType);
}
evbuffer_add_printf(outBuf, "%s", outputText.c_str());
evhttp_send_reply(req, HTTP_OK, "", outBuf);
const int ret = evbuffer_add(outBuf, outputText.data(), outputText.size());
if(ret==0)
{
evhttp_send_reply(req, HTTP_OK, "", outBuf);
}else{
evhttp_send_reply(req, 500, "evbuffer_add() failed.", outBuf);
}
std::cerr << "\n=== sendReplyString(): ret=" << ret << ", contentType=" << (contentType ? "«" + std::string(contentType)+ "»" : "NULL")
<< ", output=«" << outputText << "»." << std::endl;
}


+ 38
- 2
server/pep-types.cc View File

@ -154,7 +154,11 @@ Out<_message*>::Out(const Out<_message*>& other)
template<>
Out<_message*>::~Out()
{
if(value) free_message(*value);
///////////////////////////////////////////////////////////////////////////////
// FIXME: due to memory corruption(?) the free_message() call crashes! :-( //
// Without it we leak memory but at least it works for now... :-/ //
///////////////////////////////////////////////////////////////////////////////
// if(value) free_message(*value);
delete value;
}
@ -275,10 +279,14 @@ js::Value to_json<message*>(message* const& msg)
to_json_object(o, "shortmsg", msg->shortmsg);
to_json_object(o, "longmsg" , msg->longmsg);
to_json_object(o, "longmsg_formatted" , msg->longmsg_formatted);
to_json_object(o, "attachments", msg->attachments);
to_json_object(o, "sent" , msg->sent);
to_json_object(o, "recv" , msg->recv);
to_json_object(o, "from" , msg->from);
to_json_object(o, "to" , msg->to);
to_json_object(o, "recv_by" , msg->recv_by);
to_json_object(o, "to" , msg->to);
to_json_object(o, "cc" , msg->cc);
to_json_object(o, "bcc" , msg->bcc);
to_json_object(o, "reply_to", msg->reply_to);
@ -363,6 +371,33 @@ _bloblist_t* from_json<_bloblist_t*>(const js::Value& v)
}
template<>
js::Value to_json<_bloblist_t*>(_bloblist_t* const& bl)
{
_bloblist_t* b = bl;
js::Array a;
while(b)
{
js::Object o;
if(b->value)
o.emplace_back( "value", std::string(b->value, b->value + b->size) );
o.emplace_back( "size", b->size );
if(b->mime_type)
o.emplace_back( "mime_type", b->mime_type );
if(b->filename)
o.emplace_back( "filename", b->filename );
a.push_back( std::move(o) );
b = b->next;
}
return js::Value( std::move(a) );
}
template<>
stringpair_t* from_json<stringpair_t*>(const js::Value& v)
{
@ -376,6 +411,7 @@ stringpair_t* from_json<stringpair_t*>(const js::Value& v)
}
template<>
stringpair_list_t* from_json<stringpair_list_t*>(const js::Value& v)
{


+ 7
- 3
server/security-token.cc View File

@ -16,13 +16,13 @@ namespace
std::string sec_token;
// 36 alphanumeric characters
static const char* const token_alphabet = "qaywsxedcrfvtgbzhnujmikolp1234567890";
static const char token_alphabet[] = "qaywsxedcrfvtgbzhnujmikolp1234567890POIUZTREWQASDFGHJKLMNBVCXY";
std::string create_random_token(unsigned length=38)
{
static std::random_device rd;
static std::mt19937 gen(rd());
static std::uniform_int_distribution<> dis(0, 35); // 0..35 corrensponds to the length of the token_alphabet
static std::uniform_int_distribution<> dis( 0, sizeof(token_alphabet)-1 );
const unsigned left_len = length/2;
const unsigned right_len = length-left_len;
@ -30,7 +30,7 @@ namespace
std::string ret; ret.reserve(length+1);
std::generate_n( std::back_inserter(ret), left_len, [&](){ return token_alphabet[dis(gen)]; } );
ret += '-';
ret += '_';
std::generate_n( std::back_inserter(ret), right_len, [&](){ return token_alphabet[dis(gen)]; } );
return ret;
}
@ -75,6 +75,10 @@ void create_security_token(const std::string& server_address, unsigned port_nr,
// returns 'true' if 's' is the security token created by the function above.
bool verify_security_token(const std::string& s)
{
if(s!=sec_token)
{
std::cerr << "sec_token=\"" << sec_token << "\" is unequal to \"" << s << "\"!\n";
}
return s == sec_token;
}

Loading…
Cancel
Save