Skip to content

Commit

Permalink
fixed buddy reply routing at daemon for /cli endpoint; fixed #2269
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatolog committed Nov 5, 2024
1 parent f01a478 commit e10e482
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/searchdbuddy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,28 +608,30 @@ bool IsBuddyQuery ( const OptionsHash_t & hOptions )

struct BuddyReply_t
{
JsonObj_c m_tRoot;

CSphString m_sType;
JsonObj_c m_tMessage;
int m_iReplyHttpCode = 0;
};

static bool ParseReply ( char * sReplyRaw, BuddyReply_t & tParsed, CSphString & sError )
{
JsonObj_c tRoot = JsonObj_c ( sReplyRaw );
if ( !tRoot )
tParsed.m_tRoot = JsonObj_c ( sReplyRaw );
if ( !tParsed.m_tRoot )
{
sError.SetSprintf ( "unable to parse: %s", tRoot.GetErrorPtr() );
sError.SetSprintf ( "unable to parse: %s", tParsed.m_tRoot.GetErrorPtr() );
return false;
}

if ( !tRoot.IsObj() )
if ( !tParsed.m_tRoot.IsObj() )
{
sError.SetSprintf ( "wrong reply format - not object" );
return false;
}

int iVer = 0;
if ( !tRoot.FetchIntItem ( iVer, "version", sError, false ) )
if ( !tParsed.m_tRoot.FetchIntItem ( iVer, "version", sError, false ) )
return false;
if ( iVer>g_iBuddyVersion )
{
Expand All @@ -642,15 +644,14 @@ static bool ParseReply ( char * sReplyRaw, BuddyReply_t & tParsed, CSphString &
return false;
}

if ( !tRoot.FetchStrItem ( tParsed.m_sType, "type", sError, false ) )
if ( !tParsed.m_tRoot.FetchStrItem ( tParsed.m_sType, "type", sError, false ) )
return false;

JsonObj_c tMessage = tRoot.GetItem ( "message" );
if ( tMessage.Empty() )
tParsed.m_tMessage = tParsed.m_tRoot.GetItem ( "message" );
if ( tParsed.m_tMessage.Empty() )
return false;
tParsed.m_tMessage = tMessage.Clone();

if ( !tRoot.FetchIntItem ( tParsed.m_iReplyHttpCode, "error_code", sError, false ) )
if ( !tParsed.m_tRoot.FetchIntItem ( tParsed.m_iReplyHttpCode, "error_code", sError, false ) )
return false;

return true;
Expand Down Expand Up @@ -724,7 +725,11 @@ bool ProcessHttpQueryBuddy ( HttpProcessResult_t & tRes, Str_t sSrcQuery, Option
return tRes.m_bOk;
}

CSphString sDump = tReplyParsed.m_tMessage.AsString();
CSphVector<BYTE> dBson;
bson::JsonObjToBson ( tReplyParsed.m_tMessage, dBson, true, false );
CSphString sDump;
bson::Bson_c ( dBson ).BsonToJson ( sDump, false );

EHTTP_STATUS eHttpStatus = GetHttpStatusCode ( tReplyParsed.m_iReplyHttpCode, tRes.m_eReplyHttpCode );

dResult.Resize ( 0 );
Expand Down

0 comments on commit e10e482

Please sign in to comment.