Exemplo n.º 1
0
Arquivo: reader.cpp Projeto: AmkG/hl
// read a sequence of bytecodes in a list left on the stack
void read_sequence(Process & proc, std::istream & in) {
  char c;
  proc.stack.push(Object::nil()); // head
  proc.stack.push(Object::nil()); // tail
  while (1) {
    skip_seps(in);
    c = in.peek();
    if (!in.eof() && c == bc_start) {
      read_bytecode(proc, in);
      Object::ref c2 = Object::to_ref(proc.create<Cons>());
      if (proc.stack.top(3)==Object::nil()) // test the head
        proc.stack.top(3) = c2; // new head
      else
        scdr(proc.stack.top(2), c2); // cdr of the tail
      scar(c2, proc.stack.top()); proc.stack.pop();
      proc.stack.top() = c2; // new tail
    }
    else 
      break;
  }
  proc.stack.pop(); // remove tail and leave head
}
Exemplo n.º 2
0
/* ****************************************************************************
*
* restErrorReplyGet - 
*
* This function renders an error reply depending on the 'request' type.
* Many responses have different syntax and especially the tag in the reply
* differs (registerContextResponse, discoverContextAvailabilityResponse etc).
*
* Also, the function is called from more than one place, especially from 
* restErrorReply, but also from where the payload type is matched against the request URL.
* Where the payload type is matched against the request URL, the incoming 'request' is a
* request and not a response.
*/
std::string restErrorReplyGet(ConnectionInfo* ciP, Format format, std::string indent, std::string request, HttpStatusCode code, std::string details)
{
   std::string   tag = tagGet(request);
   StatusCode    errorCode(code, details, "errorCode");
   std::string   reply;

   ciP->httpStatusCode = SccOk;

   if (tag == "registerContextResponse")
   {
      RegisterContextResponse rcr("000000000000000000000000", errorCode);
      reply =  rcr.render(RegisterContext, format, indent);
   }
   else if (tag == "discoverContextAvailabilityResponse")
   {
      DiscoverContextAvailabilityResponse dcar(errorCode);
      reply =  dcar.render(DiscoverContextAvailability, format, indent);
   }
   else if (tag == "subscribeContextAvailabilityResponse")
   {
      SubscribeContextAvailabilityResponse scar("000000000000000000000000", errorCode);
      reply =  scar.render(SubscribeContextAvailability, format, indent);
   }
   else if (tag == "updateContextAvailabilitySubscriptionResponse")
   {
      UpdateContextAvailabilitySubscriptionResponse ucas(errorCode);
      reply =  ucas.render(UpdateContextAvailabilitySubscription, format, indent, 0);
   }
   else if (tag == "unsubscribeContextAvailabilityResponse")
   {
      UnsubscribeContextAvailabilityResponse ucar(errorCode);
      reply =  ucar.render(UnsubscribeContextAvailability, format, indent);
   }
   else if (tag == "notifyContextAvailabilityResponse")
   {
      NotifyContextAvailabilityResponse ncar(errorCode);
      reply =  ncar.render(NotifyContextAvailability, format, indent);
   }

   else if (tag == "queryContextResponse")
   {
      QueryContextResponse qcr(errorCode);
      reply =  qcr.render(QueryContext, format, indent);
   }
   else if (tag == "subscribeContextResponse")
   {
      SubscribeContextResponse scr(errorCode);
      reply =  scr.render(SubscribeContext, format, indent);
   }
   else if (tag == "updateContextSubscriptionResponse")
   {
      UpdateContextSubscriptionResponse ucsr(errorCode);
      reply =  ucsr.render(UpdateContextSubscription, format, indent);
   }
   else if (tag == "unsubscribeContextResponse")
   {
      UnsubscribeContextResponse uncr(errorCode);
      reply =  uncr.render(UnsubscribeContext, format, indent);
   }
   else if (tag == "updateContextResponse")
   {
      UpdateContextResponse ucr(errorCode);
      reply = ucr.render(UpdateContext, format, indent);
   }
   else if (tag == "notifyContextResponse")
   {
      NotifyContextResponse ncr(errorCode);
      reply =  ncr.render(NotifyContext, format, indent);
   }
   else if (tag == "StatusCode")
   {
     StatusCode sc(code, details);
     reply = sc.render(format, indent);
   }
   else
   {
      OrionError orionError(errorCode);

      LM_E(("Unknown tag: '%s', request == '%s'", tag.c_str(), request.c_str()));
      
      reply = orionError.render(format, indent);
   }

   return reply;
}