当前位置: 首页>>代码示例>>C++>>正文


C++ MHD_create_response_from_data函数代码示例

本文整理汇总了C++中MHD_create_response_from_data函数的典型用法代码示例。如果您正苦于以下问题:C++ MHD_create_response_from_data函数的具体用法?C++ MHD_create_response_from_data怎么用?C++ MHD_create_response_from_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MHD_create_response_from_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send_error

/**
 * Add an error response to the queue of the server
 *
 * @param connection The client connection which will receive the response
 * 
 * @param http_error_code The http error code to send
 *
 * @return MHD return value, MHD_NO if the response failed to be created, 
 *		   return code of MHD_queue_response otherwise
 */
static int 
send_error( struct MHD_Connection *connection, int http_error_code )
{
	int ret;
	struct MHD_Response *response;

	switch( http_error_code )
	{
		case MHD_HTTP_NOT_FOUND :
			response = MHD_create_response_from_data( strlen("Not Found"), (void *) "Not Found", MHD_NO, MHD_NO );
			break;

		case MHD_HTTP_BAD_REQUEST :
			response = MHD_create_response_from_data( strlen("Bad Request"), (void *) "Bad Request", MHD_NO, MHD_NO );
			break;
		case MHD_HTTP_INTERNAL_SERVER_ERROR :
			response = MHD_create_response_from_data( strlen("Internal Server Error"), (void *) "Internal Server Error", MHD_NO, MHD_NO );
			break;
		default :
			response = MHD_create_response_from_data( strlen("Unknown error"), (void *) "Unknown error", MHD_NO, MHD_NO );
			break;
	} 

	if( !response )
		return MHD_NO;
	ret = MHD_queue_response ( connection, http_error_code, response );
	MHD_destroy_response( response );

	return ret;
}
开发者ID:Rustor,项目名称:HomeAutomationBridgeZ,代码行数:40,代码来源:hpd_http_web_server.c

示例2: restReply

/* ****************************************************************************
*
* restReply - 
*/
void restReply(ConnectionInfo* ciP, std::string answer)
{
  MHD_Response*  response;

  ++replyIx;
  LM_T(LmtServiceOutPayload, ("Response %d: responding with %d bytes, Status Code %d", replyIx, answer.length(), ciP->httpStatusCode));
  LM_T(LmtServiceOutPayload, ("Response payload: '%s'", answer.c_str()));

  if (answer == "")
    response = MHD_create_response_from_data(answer.length(), (void*) answer.c_str(), MHD_NO, MHD_NO);
  else
    response = MHD_create_response_from_data(answer.length(), (void*) answer.c_str(), MHD_YES, MHD_YES);

  if (!response)
    LM_RVE(("MHD_create_response_from_buffer FAILED"));

  if (ciP->httpHeader.size() != 0)
  {
     for (unsigned int hIx = 0; hIx < ciP->httpHeader.size(); ++hIx)
        MHD_add_response_header(response, ciP->httpHeader[hIx].c_str(), ciP->httpHeaderValue[hIx].c_str());
  }

  if (answer != "")
  {
    if (ciP->outFormat == XML)
      MHD_add_response_header(response, "Content-Type", "application/xml");
    else if (ciP->outFormat == JSON)
      MHD_add_response_header(response, "Content-Type", "application/json");
  }

  MHD_queue_response(ciP->connection, ciP->httpStatusCode, response);
  MHD_destroy_response(response);
}
开发者ID:Aeronbroker,项目名称:fiware-orion,代码行数:37,代码来源:restReply.cpp

示例3: ahc_echo

static int
ahc_echo (void *cls,
          struct MHD_Connection *connection,
          const char *url,
          const char *method,
          const char *version,
          const char *upload_data, size_t *upload_data_size,
          void **unused)
{
  struct MHD_Response *response;
  char *username;
  const char *password = "testpass";
  const char *realm = "[email protected]";
  int ret;

  username = MHD_digest_auth_get_username(connection);
  if ( (username == NULL) ||
       (0 != strcmp (username, "testuser")) )
    {
      response = MHD_create_response_from_data(strlen (DENIED), 
					       DENIED,
					       MHD_NO, MHD_NO);  
      ret = MHD_queue_auth_fail_response(connection, realm,
					 OPAQUE,
					 response,
					 MHD_NO);    
      MHD_destroy_response(response);  
      return ret;
    }
  ret = MHD_digest_auth_check(connection, realm,
			      username, 
			      password, 
			      300);
  free(username);
  if ( (ret == MHD_INVALID_NONCE) ||
       (ret == MHD_NO) )
    {
      response = MHD_create_response_from_data(strlen (DENIED), 
					       DENIED,
					       MHD_NO, MHD_NO);  
      if (NULL == response) 
	return MHD_NO;
      ret = MHD_queue_auth_fail_response(connection, realm,
					 OPAQUE,
					 response,
					 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);  
      MHD_destroy_response(response);  
      return ret;
    }
  response = MHD_create_response_from_data(strlen(PAGE), PAGE,
					   MHD_NO, MHD_NO);
  ret = MHD_queue_response(connection, MHD_HTTP_OK, response);  
  MHD_destroy_response(response);
  return ret;
}
开发者ID:morria,项目名称:CoffeeD,代码行数:55,代码来源:daemontest_digestauth.c

示例4: handle_request

static int
handle_request(void *cls, struct MHD_Connection *connection,
               const char *url, const char *method,
               const char *version, const char *upload_data,
               size_t *upload_data_size, void **con_cls)
{
    int ret;
    struct MHD_Response *response = NULL;
    struct brubeck_server *brubeck = cls;

    if (!strcmp(method, "GET")) {
        if (!strcmp(url, "/ping")) {
            char *jsonr;
            json_t *pong = json_pack("{s:s, s:i, s:s}",
                                     "version", "brubeck " GIT_SHA,
                                     "pid", (int)getpid(),
                                     "status", "OK");

            jsonr = json_dumps(pong, JSON_PRESERVE_ORDER);
            response = MHD_create_response_from_data(strlen(jsonr), jsonr, 1, 0);
            json_decref(pong);
        }

        else if (!strcmp(url, "/stats"))
            response = send_stats(brubeck);

        else if (starts_with(url, "/metric/"))
            response = send_metric(brubeck, url);
    }
    else if (!strcmp(method, "POST")) {
        if (starts_with(url, "/expire/"))
            response = expire_metric(brubeck, url);
    }

    if (!response) {
        static const char *NOT_FOUND = "404 not found";
        response = MHD_create_response_from_data(
                       strlen(NOT_FOUND), (void *)NOT_FOUND, 0, 0);
        MHD_add_response_header(response, "Connection", "close");
        ret = MHD_queue_response(connection, 404, response);
    } else {
        MHD_add_response_header(response, "Connection", "close");
        MHD_add_response_header(response, "Content-Type", "application/json");
        ret = MHD_queue_response(connection, 200, response);
    }

    MHD_destroy_response(response);
    return ret;
}
开发者ID:bwilber,项目名称:brubeck,代码行数:49,代码来源:http.c

示例5: sendMethodNotAllowedResponse

inline int sendMethodNotAllowedResponse(struct MHD_Connection* connection, bool allowGet) {
    struct MHD_Response* response;
    int ret;

#ifdef MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_data(
        strlen(XML_MWS_METHOD_NOT_ALLOWED), (void*)XML_MWS_METHOD_NOT_ALLOWED, false, false);
#else  // MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_buffer(
        strlen(XML_MWS_METHOD_NOT_ALLOWED), (void*)XML_MWS_METHOD_NOT_ALLOWED, MHD_RESPMEM_PERSISTENT);
#endif  // MICROHTTPD_DEPRECATED
    MHD_add_response_header(response, "Content-Type", "text/xml");
    MHD_add_response_header(response, "Allow",
                            allowGet ? "GET, POST, OPTIONS" : "POST, OPTIONS");
    MHD_add_response_header(response, "Access-Control-Allow-Origin", "*");
    MHD_add_response_header(response, "Allow",
                            allowGet ? "GET, POST, OPTIONS" : "POST, OPTIONS");
    MHD_add_response_header(response, "Access-Control-Allow-Headers",
                            "CONTENT-TYPE");
    MHD_add_response_header(response, "Access-Control-Max-Age", "1728000");
    ret = MHD_queue_response(connection, MHD_HTTP_METHOD_NOT_ALLOWED, response);
    MHD_destroy_response(response);

    return ret;
}
开发者ID:KWARC,项目名称:mws,代码行数:25,代码来源:GenericHttpResponses.hpp

示例6: see_other

static int see_other(MHD_Connection* connection, const std::string& new_location) {
  MHD_Response* response = MHD_create_response_from_data(0, 0, MHD_NO, MHD_NO);
  MHD_add_response_header(response, MHD_HTTP_HEADER_LOCATION, new_location.c_str());
  MHD_queue_response(connection, MHD_HTTP_SEE_OTHER, response);
  MHD_destroy_response(response);
  return MHD_YES;
}
开发者ID:JoeBargo,项目名称:enh,代码行数:7,代码来源:mp3d.cpp

示例7: connection_handler

static int
connection_handler (void *cls,
                    struct MHD_Connection *connection,
                    const char *url,
                    const char *method,
                    const char *version,
                    const char *upload_data, size_t * upload_data_size,
                    void **ptr)
{
  static int i;

  if (*ptr == NULL)
    {
      *ptr = &i;
      return MHD_YES;
    }

  if (*upload_data_size != 0)
    {
      (*upload_data_size) = 0;
      return MHD_YES;
    }

  struct MHD_Response *response =
    MHD_create_response_from_data (strlen ("Response"), "Response", 0, 0);
  int ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  MHD_destroy_response (response);

  return ret;
}
开发者ID:morria,项目名称:CoffeeD,代码行数:30,代码来源:daemontest_termination.c

示例8: send_response

int
send_response(struct http_response *resp)
{
	struct MHD_Response *response;
	struct http_header *hdr;
	char *origin;
	int ret;

	response = MHD_create_response_from_data(resp->ndata,
	    (void *)resp->data, MHD_NO, MHD_YES);
	assert(response);
	for (hdr = resp->headers; hdr; hdr = hdr->next)
		MHD_add_response_header(response, hdr->key, hdr->value);
	MHD_add_response_header(response, "Access-Control-Allow-Headers",
	    "Authorization, Origin");
	MHD_add_response_header(response, "Access-Control-Allow-Methods",
	    "GET, POST, PUT, DELETE, OPTIONS");
	origin = http_get_header(resp->connection, "Origin");
	MHD_add_response_header(response, "Access-Control-Allow-Origin",
	    origin ? origin : "*");
	free(origin);
	ret = MHD_queue_response(resp->connection, resp->status, response);
	MHD_destroy_response(response);
	return (ret);
}
开发者ID:biddyweb,项目名称:vagent2,代码行数:25,代码来源:http.c

示例9: http_ahc

/**
 *  HTTP access handler call back
 */
int
http_ahc (void *cls, struct MHD_Connection *connection,
          const char *url, const char *method, const char *upload_data,
          const char *version, size_t *upload_data_size, void **ptr)
{
  static int aptr;
  struct MHD_Response *response;
  int ret;

  if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
    return MHD_NO;              /* unexpected method */
  if (&aptr != *ptr)
    {
      /* do never respond on first call */
      *ptr = &aptr;
      return MHD_YES;
    }
  *ptr = NULL;                  /* reset when done */
  response = MHD_create_response_from_data (strlen (test_data),
					    (void *) test_data,
					    MHD_NO, MHD_NO);
  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  MHD_destroy_response (response);
  return ret;
}
开发者ID:morria,项目名称:CoffeeD,代码行数:28,代码来源:tls_test_common.c

示例10: sendOptionsResponse

inline int
sendOptionsResponse(struct MHD_Connection* connection)
{
    struct MHD_Response* response;
    int                  ret;

#ifdef MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_data(strlen(EMPTY_RESPONSE),
                                             (void*) EMPTY_RESPONSE,
                                             false,
                                             false);
#else // MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_buffer(strlen(EMPTY_RESPONSE),
                                               (void*) EMPTY_RESPONSE,
                                               MHD_RESPMEM_PERSISTENT);
#endif // MICROHTTPD_DEPRECATED
    MHD_add_response_header(response,
                            "Content-Type", "text/plain");
    MHD_add_response_header(response,
                            "Access-Control-Allow-Origin", "*");
    MHD_add_response_header(response,
                            "Access-Control-Allow-Methods", "POST, OPTIONS");
    MHD_add_response_header(response,
                            "Access-Control-Allow-Headers", "CONTENT-TYPE");
    MHD_add_response_header(response,
                            "Access-Control-Max-Age", "1728000");
    ret = MHD_queue_response(connection,
                             MHD_HTTP_OK,
                             response);
    MHD_destroy_response(response);

    return ret;
}
开发者ID:Zwackelmann,项目名称:mws,代码行数:33,代码来源:GenericResponses.hpp

示例11: sendXmlGenericResponse

inline int
sendXmlGenericResponse(struct MHD_Connection* connection,
                       const char*            xmlGenericResponse,
                       int                    statusCode)
{
    struct MHD_Response* response;
    int                  ret;

#ifdef MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_data(strlen(xmlGenericResponse),
                                             (void*) xmlGenericResponse,
                                             /* must_free = */ 0,
                                             /* must_copy = */ 0);
#else // MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_buffer(strlen(xmlGenericResponse),
                                               (void*) xmlGenericResponse,
                                               MHD_RESPMEM_PERSISTENT);
#endif // MICROHTTPD_DEPRECATED
    MHD_add_response_header(response,
                            "Content-Type", "text/xml");
    ret = MHD_queue_response(connection,
                             statusCode,
                             response);
    MHD_destroy_response(response);

    return ret;
}
开发者ID:Zwackelmann,项目名称:mws,代码行数:27,代码来源:GenericResponses.hpp

示例12: send_metric

static struct MHD_Response *
send_metric(struct brubeck_server *server, const char *url)
{
    static const char *metric_types[] = {
        "gauge", "meter", "counter", "histogram", "timer", "internal"
    };
    static const char *expire_status[] = {
        "disabled", "inactive", "active"
    };

    struct brubeck_metric *metric = safe_lookup_metric(
                                        server, url + strlen("/metric/"));

    if (metric) {
        json_t *mj = json_pack("{s:s, s:s, s:i, s:s}",
                               "key", metric->key,
                               "type", metric_types[metric->type],
#if METRIC_SHARD_SPECIFIER
                               "shard", (int)metric->shard,
#else
                               "shard", 0,
#endif
                               "expire", expire_status[metric->expire]
                              );

        char *jsonr = json_dumps(mj, JSON_INDENT(4) | JSON_PRESERVE_ORDER);
        json_decref(mj);
        return MHD_create_response_from_data(
                   strlen(jsonr), jsonr, 1, 0);
    }

    return NULL;
}
开发者ID:bwilber,项目名称:brubeck,代码行数:33,代码来源:http.c

示例13: MHD_create_response_from_data

int CWebServer::AskForAuthentication(struct MHD_Connection *connection)
{
  struct MHD_Response *response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO);
  if (!response)
  {
    CLog::Log(LOGERROR, "CWebServer: unable to create HTTP Unauthorized response");
    return MHD_NO;
  }

  int ret = AddHeader(response, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Basic realm=XBMC");
  ret |= AddHeader(response, MHD_HTTP_HEADER_CONNECTION, "close");
  if (!ret)
  {
    CLog::Log(LOGERROR, "CWebServer: unable to prepare HTTP Unauthorized response");
    MHD_destroy_response(response);
    return MHD_NO;
  }

#ifdef WEBSERVER_DEBUG
  std::multimap<std::string, std::string> headerValues;
  GetRequestHeaderValues(connection, MHD_RESPONSE_HEADER_KIND, headerValues);

  CLog::Log(LOGDEBUG, "webserver [OUT] HTTP %d", MHD_HTTP_UNAUTHORIZED);

  for (std::multimap<std::string, std::string>::const_iterator header = headerValues.begin(); header != headerValues.end(); ++header)
    CLog::Log(LOGDEBUG, "webserver [OUT] %s: %s", header->first.c_str(), header->second.c_str());
#endif

  ret = MHD_queue_response(connection, MHD_HTTP_UNAUTHORIZED, response);
  MHD_destroy_response(response);

  return ret;
}
开发者ID:Karlson2k,项目名称:xbmc,代码行数:33,代码来源:WebServer.cpp

示例14: list_all_nodes

int list_all_nodes(struct MHD_Connection *connection, struct system_data *sysdata, int uri_num)
{
  struct MHD_Response *response;
  int i, ret;

  DEBUG("\n");
  strcpy (pagebuff, "{\n");
  strcat (pagebuff, "  \"node\" : [\n");

  for (i=0; i < NUM_NODES; i++) {
    ret = print_node_json(pagebuff, &sysdata->nodes[i]);
    sprintf(&pagebuff[strlen(pagebuff)], "%c\n", i==NUM_NODES-1?' ':',');
    if (ret)
      return present_error(connection, "Error generating node #: %d\n", i+1);
  }
  strcat (pagebuff, "  ]\n}\n");
    
  response = MHD_create_response_from_data (strlen(pagebuff), (void *) pagebuff,
                                            MHD_NO, MHD_NO);

  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  MHD_destroy_response (response);

  return ret;
}
开发者ID:cj8scrambler,项目名称:pirelay,代码行数:25,代码来源:data_handlers.c

示例15: dispatch

int HttpServer::HandleRequest(void *cls,
                              struct MHD_Connection* connection,
                              const char* url,
                              const char* method,
                              const char* version,
                              const char* upload_data,
                              size_t* upload_data_size,
                              void** ptr) {
  Dispatcher& dispatch = *static_cast<Dispatcher*>(cls);
  static int dummy;
  struct MHD_Response * response;
  int ret;

  if (&dummy != *ptr) {
    /* The first time only the headers are valid,
       do not respond in the first round... */
    *ptr = &dummy;
    return MHD_YES;
  }
  *ptr = NULL; /* clear context pointer */

  std::string post_body;
  if (*upload_data_size > 0) {
    post_body = std::string(upload_data, *upload_data_size);
  }
  std::string page = dispatch(method, url, post_body);
  response = MHD_create_response_from_data(page.length(),
                                           (void*) page.c_str(),
                                           MHD_NO,
                                           MHD_YES);
  ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
  MHD_destroy_response(response);
  return ret;
}
开发者ID:flangner,项目名称:mesos-framework,代码行数:34,代码来源:http_server.cpp


注:本文中的MHD_create_response_from_data函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。