Browse Source

convert entry to json

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
dc36efaa1e
  1. 30
      src/twister.cpp

30
src/twister.cpp

@ -385,6 +385,30 @@ int getBestHeight()
return nBestHeight; return nBestHeight;
} }
Value entryToJson(const entry &e)
{
Array lst;
Object o;
switch( e.type() ) {
case entry::int_t:
return e.integer();
case entry::string_t:
return e.string();
case entry::list_t:
for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i) {
lst.push_back( entryToJson(*i) );
}
return lst;
case entry::dictionary_t:
for (entry::dictionary_type::const_iterator i = e.dict().begin(); i != e.dict().end(); ++i) {
o.push_back(Pair(i->first, entryToJson(i->second)));
}
return o;
default:
return string("<uninitialized>");
}
}
Value dhtput(const Array& params, bool fHelp) Value dhtput(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() < 5 || params.size() > 6) if (fHelp || params.size() < 5 || params.size() > 6)
@ -422,6 +446,7 @@ Value dhtput(const Array& params, bool fHelp)
int timeutc = time(NULL); int timeutc = time(NULL);
ses->dht_putData(strUsername, strResource, multi, value, strSigUser, timeutc, seq); ses->dht_putData(strUsername, strResource, multi, value, strSigUser, timeutc, seq);
return Value(); return Value();
} }
@ -454,10 +479,7 @@ Value dhtget(const Array& params, bool fHelp)
std::auto_ptr<alert> a(am.get()); std::auto_ptr<alert> a(am.get());
dht_reply_data_alert const* rd = alert_cast<dht_reply_data_alert>(&(*a)); dht_reply_data_alert const* rd = alert_cast<dht_reply_data_alert>(&(*a));
entry const *p = rd->m_lst.begin()->find_key("p"); ret = entryToJson(rd->m_lst);
// FIXME: temporary. implement proper parsing/conversion
ret = rd->m_lst.begin()->find_key("sig_p")->string();
} }
{ {

Loading…
Cancel
Save