示例#1
0
int getCities(int pid, char *password)
{
    pOutbound request = malloc(sizeof(Outbound));
    pInboundExtended response;
    
    request->len = 0;
    request->pid = pid;
    request->userLevel = 1;
    request->jobRef = 13;
    strcpy(request->pw,password);
    
    response = startCommunicationExtended(request,pid);
    
    free(request);
    request = NULL;
    
    if(response->valid == 1)
    {
        if(response->len > 0)
            responseText(response);
        else
            printf("Cities's list is empty.\n");
        return 1;
    }
    return 0;
}
示例#2
0
int getInfo(int pid, char *password)
{
    pOutbound request = malloc(sizeof(Outbound));
    pInboundExtended response;
    
    request->len = 0;
    request->pid = pid;
    request->userLevel = 1;
    request->jobRef = 10;
    strcpy(request->pw,password);
    
    response = startCommunicationExtended(request,pid);
    
    free(request);
    request = NULL;
    
    if(response->valid == 1)
    {
        if(response->len > 0)
        {
            responseText(response);
        }
        else
            printf("No information available!\n");
        return 1;
    }
    return 0;
}
JSValue JSXMLHttpRequest::response(ExecState* exec) const
{
    switch (impl().responseTypeCode()) {
    case XMLHttpRequest::ResponseTypeDefault:
    case XMLHttpRequest::ResponseTypeText:
        return responseText(exec);

    case XMLHttpRequest::ResponseTypeJSON:
        {
            // FIXME: Use CachedAttribute for other types as well.
            if (m_response && impl().responseCacheIsValid())
                return m_response.get();

            if (!impl().doneWithoutErrors())
                return jsNull();

            JSValue value = JSONParse(exec, impl().responseTextIgnoringResponseType());
            if (!value)
                value = jsNull();
            JSXMLHttpRequest* jsRequest = const_cast<JSXMLHttpRequest*>(this);
            jsRequest->m_response.set(exec->vm(), jsRequest, value);

            impl().didCacheResponseJSON();

            return value;
        }

    case XMLHttpRequest::ResponseTypeDocument:
        {
            ExceptionCode ec = 0;
            Document* document = impl().responseXML(ec);
            if (ec) {
                setDOMException(exec, ec);
                return jsUndefined();
            }
            return toJS(exec, globalObject(), document);
        }

    case XMLHttpRequest::ResponseTypeBlob:
        return toJS(exec, globalObject(), impl().responseBlob());

    case XMLHttpRequest::ResponseTypeArrayBuffer:
        return toJS(exec, globalObject(), impl().responseArrayBuffer());
    }

    return jsUndefined();
}
JSValue JSXMLHttpRequest::response(ExecState* exec) const
{
    switch (impl()->responseTypeCode()) {
    case XMLHttpRequest::ResponseTypeDefault:
    case XMLHttpRequest::ResponseTypeText:
        return responseText(exec);

    case XMLHttpRequest::ResponseTypeDocument:
        {
            ExceptionCode ec = 0;
            Document* document = impl()->responseXML(ec);
            if (ec) {
                setDOMException(exec, ec);
                return jsUndefined();
            }
            return toJS(exec, globalObject(), document);
        }

    case XMLHttpRequest::ResponseTypeBlob:
#if ENABLE(XHR_RESPONSE_BLOB)
        {
            ExceptionCode ec = 0;
            Blob* blob = impl()->responseBlob(ec);
            if (ec) {
                setDOMException(exec, ec);
                return jsUndefined();
            }
            return toJS(exec, globalObject(), blob);
        }
#else
        return jsUndefined();
#endif

    case XMLHttpRequest::ResponseTypeArrayBuffer:
        {
            ExceptionCode ec = 0;
            ArrayBuffer* arrayBuffer = impl()->responseArrayBuffer(ec);
            if (ec) {
                setDOMException(exec, ec);
                return jsUndefined();
            }
            return toJS(exec, globalObject(), arrayBuffer);
        }
    }

    return jsUndefined();
}
JSValue JSXMLHttpRequest::retrieveResponse(ExecState& state)
{
    auto type = wrapped().responseType();

    switch (type) {
    case XMLHttpRequest::ResponseType::EmptyString:
    case XMLHttpRequest::ResponseType::Text:
        return responseText(state);
    default:
        break;
    }

    if (!wrapped().doneWithoutErrors())
        return jsNull();

    JSValue value;
    switch (type) {
    case XMLHttpRequest::ResponseType::EmptyString:
    case XMLHttpRequest::ResponseType::Text:
        ASSERT_NOT_REACHED();
        return jsUndefined();

    case XMLHttpRequest::ResponseType::Json:
        value = JSONParse(&state, wrapped().responseTextIgnoringResponseType());
        if (!value)
            value = jsNull();
        break;

    case XMLHttpRequest::ResponseType::Document: {
        ExceptionCode ec = 0;
        auto document = wrapped().responseXML(ec);
        ASSERT(!ec);
        value = toJS(&state, globalObject(), document);
        break;
    }
    case XMLHttpRequest::ResponseType::Blob:
        value = toJSNewlyCreated(&state, globalObject(), wrapped().createResponseBlob());
        break;

    case XMLHttpRequest::ResponseType::Arraybuffer:
        value = toJS(&state, globalObject(), wrapped().createResponseArrayBuffer());
        break;
    }
    wrapped().didCacheResponse();
    return value;
}
JSValue JSXMLHttpRequest::response(ExecState& state) const
{
    // FIXME: Use CachedAttribute for other types than JSON as well.
    if (m_response && wrapped().responseCacheIsValid())
        return m_response.get();

    if (!wrapped().doneWithoutErrors() && wrapped().responseTypeCode() > XMLHttpRequest::ResponseTypeText)
        return jsNull();

    switch (wrapped().responseTypeCode()) {
    case XMLHttpRequest::ResponseTypeDefault:
    case XMLHttpRequest::ResponseTypeText:
        return responseText(state);

    case XMLHttpRequest::ResponseTypeJSON:
        {
            JSValue value = JSONParse(&state, wrapped().responseTextIgnoringResponseType());
            if (!value)
                value = jsNull();
            m_response.set(state.vm(), this, value);

            wrapped().didCacheResponseJSON();

            return value;
        }

    case XMLHttpRequest::ResponseTypeDocument:
        {
            ExceptionCode ec = 0;
            Document* document = wrapped().responseXML(ec);
            if (ec) {
                setDOMException(&state, ec);
                return jsUndefined();
            }
            return toJS(&state, globalObject(), document);
        }

    case XMLHttpRequest::ResponseTypeBlob:
        return toJS(&state, globalObject(), wrapped().responseBlob());

    case XMLHttpRequest::ResponseTypeArrayBuffer:
        return toJS(&state, globalObject(), wrapped().responseArrayBuffer());
    }

    return jsUndefined();
}
示例#7
0
bool AddExtension::execute(const HttpRequestContext& requestContext,
                           UtlSList& params,
                           void* userData,
                           XmlRpcResponse& response,
                           XmlRpcMethod::ExecutionStatus& status)
{
   bool result = false;
   
   int totalParams = params.entries();
   if (totalParams > 2)
   {
      response.setFault(TOO_MANY_PARAMS_FAULT_CODE, TOO_MANY_PARAMS_FAULT_STRING);
      result = false;
   }
   else
   {
      UtlString groupName;
      UtlString extension;
      for (int index = 0; index < totalParams; index++)
      {
               
         UtlContainable *value = params.at(index);
         if (index == 0 || index == 1)
         {
            UtlString paramType(value->getContainableType());
            if (paramType.compareTo("UtlString") == 0)
            {
               if (index == 0)
               {
                  groupName = *((UtlString *)value);
               }
               else
               {
                  extension = *((UtlString *)value);
               }
               
               result = true;
            }
            else
            {
               response.setFault(ILLEGAL_PARAM_FAULT_CODE, ILLEGAL_PARAM_FAULT_STRING);
               result = false;
            }  
         }
      }
      
      if (result)
      {
         SipDialogMonitor* dialogMonitor = (SipDialogMonitor *) userData;
         
         Url extensionUrl(extension);
             
         dialogMonitor->addExtension(groupName, extensionUrl);
         
         status = XmlRpcMethod::OK;
         
         // Construct the response
         UtlString responseText("method call \"addExtension\" successful");
         response.setResponse(&responseText);
      }
   }
   
   return true;
}