コード例 #1
0
ファイル: WsHandler.cpp プロジェクト: edkit/edkit-agent
/**
* @date     2011/12/21
*
*  Handler of a request. The WebService request si built from the request, and
*  forwarded to the correct WsInterface.
*
******************************************************************************/
int32_t  WsHandler::RequestReceived(const HttpdRequest &Request,
                                    HttpdRequest *Answer)
{
   int32_t i_Ret = -1;
   ListIterator<AList<WsInterface*>, WsInterface*>  Iterator;
   WsInterface    *p_Interface = NULL;
   const String   *RequestInterface;

   if(HandleCors(Request, Answer) == 0)
      return(0);

   DynObject   Params;
   const uint8_t *Payload;
   uint32_t i_Length;
   i_Ret = Request.GetPayload(&Payload, &i_Length);
   if(i_Ret == 0)
   {
      JsonFlattener Flattener;
      const String PayloadString((const char*)(Payload), i_Length);

      i_Ret = Flattener.UnFlatten(&PayloadString, &Params);
      if(i_Ret == 0)
      {
         i_Ret = Params.FindString("InterfaceName", &RequestInterface);
      }
   }
   if(i_Ret != 0)
      return(-1);

   Iterator.SetTo(&InterfaceList);
   Iterator.First();
   while(Iterator.IsDone() == false)
   {
      if( (Iterator.GetItem(&p_Interface) == 0) && (p_Interface != NULL) )
      {
         if(p_Interface->GetName() == *RequestInterface)
         {
            String   AnswerString;
            i_Ret = p_Interface->Call(Params, &AnswerString);
            if(i_Ret == 0)
            {
               i_Ret = Answer->SetPayload((const uint8_t*)AnswerString.GetString(),
                                          AnswerString.GetSize());
            }
            break;
         }
      }
      Iterator.Next();
   }

   return(i_Ret);
}
コード例 #2
0
void main() {
    Recipe myRecipe1 =  Recipe("Fish Filets in Hot Chili Oil");
    Recipe myRecipe2 =  Recipe("Boiled Fish with Pickled Cabbage and Chili ");
    Recipe myRecipe3 =  Recipe("Coke Chicken");
    Recipe myRecipe4 =  Recipe("Fish ball soup");
    List<Recipe>* myRecipeList = new List<Recipe>();
    myRecipeList->Append(myRecipe1);
    myRecipeList->Append(myRecipe2);
    myRecipeList->Append(myRecipe3);
    myRecipeList->Append(myRecipe4);
    ListIterator<Recipe> myIterator = ListIterator<Recipe>(myRecipeList);
    for(myIterator.First(); !myIterator.IsDone(); myIterator.Next()) {
        myIterator.CurrentItem().Print();
    }
    while(1) {
        ;
    }
}
コード例 #3
0
ファイル: HttpdRequest1.cpp プロジェクト: edkit/edkit-agent
TEST(HttpdRequestTestGroup, Basic)
{
   String   SetPath(PATH1 );
   HttpdRequest Obj1;

   /* Path */
   const String   &GetPath1 = Obj1.GetPath();
   CHECK(GetPath1 == "");
   CHECK(Obj1.SetPath(SetPath) == 0);

   const String   &GetPath2 = Obj1.GetPath();
   CHECK(GetPath2 == SetPath);

   /* Status */
   CHECK(Obj1.GetStatus() == 200);
   Obj1.SetStatus(404);
   CHECK(Obj1.GetStatus() == 404);

   /* Method */
   CHECK(Obj1.GetMethod() == HttpdRequest::NONE);
   Obj1.SetMethod(HttpdRequest::POST);
   CHECK(Obj1.GetMethod() == HttpdRequest::POST);

   /* payload */
   uint8_t SetPayload[326];
   const uint8_t *GetPayload;
   uint32_t i_Length;
   CHECK(Obj1.SetPayload(SetPayload, 326) == 0);
   CHECK(Obj1.GetPayload(&GetPayload, &i_Length) == 0);
   CHECK(i_Length == 326);
   CHECK(memcmp(GetPayload, SetPayload, i_Length) == 0);


   /* Header */
   String Header1Name(HEADER1), Header2Name(HEADER2);
   String Header1Val(HEADER1VAL), Header2Val(HEADER2VAL);
   String HeaderVal;

   CHECK(Obj1.GetHeader(Header1Name, &HeaderVal) == -1);
   CHECK(Obj1.SetHeader(Header1Name, Header1Val) == 0);
   CHECK(Obj1.GetHeader(Header1Name, &HeaderVal) == 0);
   CHECK(HeaderVal == Header1Val);

   CHECK(Obj1.SetHeader(Header2Name, Header2Val) == 0);
   CHECK(Obj1.GetHeader(Header2Name, &HeaderVal) == 0);
   CHECK(HeaderVal == Header2Val);

   CHECK(Obj1.SetHeader(Header1Name, Header2Val) == 0);
   CHECK(Obj1.GetHeader(Header1Name, &HeaderVal) == 0);
   CHECK(HeaderVal == Header2Val);

   /* Header list */
   const AList<HttpdRequest::Header*> &HeaderList = Obj1.GetHeaderList();
   ListIterator<AList<HttpdRequest::Header*>, HttpdRequest::Header*> Iterator;
   HttpdRequest::Header  *p_CurHeader;
   uint32_t i_Index = 0;

   Iterator.SetTo(&HeaderList);
   Iterator.First();
   while(Iterator.IsDone() == false)
   {
      CHECK(Iterator.GetItem(&p_CurHeader) == 0);
      CHECK(p_CurHeader != NULL);

      CHECK(i_Index <= 1);
      switch(i_Index)
      {
         case 0:
            CHECK(p_CurHeader->Name == Header1Name);
            CHECK(p_CurHeader->Value == Header2Val);
         break;
         case 1:
            CHECK(p_CurHeader->Name == Header2Name);
            CHECK(p_CurHeader->Value == Header2Val);
         break;
      }
      i_Index++;
      Iterator.Next();
   }

};