예제 #1
0
파일: post.c 프로젝트: ppslinux/esp
/*
    Update an existing resource in the database
    If "id" is not defined, this is the same as a create
    Also we tunnel delete here if the user clicked delete
 */
static void updatePost() { 
    if (smatch(param("submit"), "Delete")) {
        removePost();
    } else {
        if (updateFields("post", params())) {
            flash("inform", "Post Updated Successfully");
            redirect("list");
        } else {
            flash("error", "Cannot Update Post");
            renderView("post/post-edit");
        }
    }
}
예제 #2
0
/**
   [ server interface ]
   The RpcServer will call this function to
   return a response to a request
*/
void
RpcHttpTransport::sendResponse(
    const unsigned long sessionId,
    const StringUtils::StringMap &headers,
    const String &response )
{
    // this function is called to respond to a request
    // in the context of an inbound request
    PendingPostReference post = removePost( sessionId );
    if ( post.first != NULL )
    {
        bool hasBody = response.length() > 0;

        HttpContent content;
        content.setHttpMsgType( HttpContent::HTTP_MSG_TYPE_RESPONSE );
        content.setHeaders( headers );
        content.setErrorCode( hasBody ? HttpUtils::keCodeOk : HttpUtils::keCodeNoContent);

        // this has to be performed after the setHeaders on the content
        // to make sure that the accept types have been set to
        // check agains
        if ( post.second->doesAcceptType(HttpUtils::HTTP_MIME_XMLTEXT) )
        {
            content.setMimeType(HttpUtils::HTTP_MIME_XMLTEXT);
        }
        else
        {
            content.setMimeType(HttpUtils::HTTP_MIME_PLAINTEXT);
        }

        content.setMimeEncoding( HttpUtils::HTTP_ENC_UTF8 );

        if ( hasBody )
        {
            content.setResponseBody( response );
        }

        if ( !post.first->sendResponse( content ) )
        {
            CBLOGERR( _logger, NTEXT("HttpTransport::respond - Unable to repond to client") );
        }
    }
    else
    {
        CBLOGERR(_logger, NTEXT("HttpTransport::respond - Post not found with the sessionId") );
    }
}