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


C++ MHD_destroy_response函数代码示例

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


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

示例1: serve_file

/**
 * @brief serve_file try to serve a request via filesystem. Using webroot as root.
 * @param connection
 * @param client
 * @return
 */
static int serve_file(struct MHD_Connection *connection, t_client *client, const char *url)
{
	struct stat stat_buf;
	s_config *config = config_get_config();
	struct MHD_Response *response;
	char filename[PATH_MAX];
	int ret = MHD_NO;
	const char *mimetype = NULL;
	off_t size;

	snprintf(filename, PATH_MAX, "%s/%s", config->webroot, url);

	/* check if file exists and is not a directory */
	ret = stat(filename, &stat_buf);
	if (ret) {
		/* stat failed */
		return send_error(connection, 404);
	}

	if (!S_ISREG(stat_buf.st_mode)) {
#ifdef S_ISLNK
		/* ignore links */
		if (!S_ISLNK(stat_buf.st_mode))
#endif /* S_ISLNK */
		return send_error(connection, 404);
	}

	int fd = open(filename, O_RDONLY);
	if (fd < 0)
		return send_error(connection, 404);

	mimetype = lookup_mimetype(filename);

	/* serving file and creating response */
	size = lseek(fd, 0, SEEK_END);
	if (size < 0)
		return send_error(connection, 404);

	response = MHD_create_response_from_fd(size, fd);
	if (!response)
		return send_error(connection, 503);

	MHD_add_response_header(response, "Content-Type", mimetype);
	ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
	MHD_destroy_response(response);

	return ret;
}
开发者ID:lynxis,项目名称:nodogsplash,代码行数:54,代码来源:http_microhttpd.c

示例2: test_http_server_ok_handler

int test_http_server_ok_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) {

	test_http_server * handle = cls;
	struct MHD_Response * response;
	int ret;
	int * c_count;
	if (*ptr == NULL) {
		handle->log = apr_hash_make(handle->pool);
	  	/* The first time only the headers are valid,
		 do not respond in the first round... */
	  	*ptr = cls; //just to flag its not null....
	  	int * c_count = apr_palloc(handle->pool, sizeof(int));
		*c_count = 0;
		*ptr = c_count;
	  	return MHD_YES;
	}
	c_count = *ptr;
	if(*c_count == 0) {
		//log the request....
		apr_hash_set(handle->log,  apr_pstrdup(handle->pool, "METHOD"), APR_HASH_KEY_STRING, apr_pstrdup(handle->pool, method));
		apr_hash_set(handle->log,  apr_pstrdup(handle->pool, "URL"), APR_HASH_KEY_STRING, apr_pstrdup(handle->pool, url));
		apr_hash_set(handle->log,  apr_pstrdup(handle->pool, "VERSION"), APR_HASH_KEY_STRING, apr_pstrdup(handle->pool, version));
		apr_hash_set(handle->log,  apr_pstrdup(handle->pool, "DATA_LENGTH"), APR_HASH_KEY_STRING, apr_pmemdup (handle->pool, upload_data_size, sizeof(size_t)));
		apr_hash_set(handle->log,  apr_pstrdup(handle->pool, "DATA"), APR_HASH_KEY_STRING, apr_pmemdup (handle->pool, upload_data, *upload_data_size));
	}
	*c_count = *c_count+1;
	if(*upload_data_size == 0) {
		response = MHD_create_response_from_data(strlen(handle->response),
						   (void*) handle->response,
						   MHD_NO,
						   MHD_NO);
		ret = MHD_queue_response(connection,
				   handle->response_code,
				   response);
		MHD_destroy_response(response);
		return ret;
	} else {
		*upload_data_size = 0; //we processed everything?
		return MHD_YES;
	}
}
开发者ID:markpent,项目名称:lib_mogilefs,代码行数:48,代码来源:test_http_server.c

示例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 **ptr)
{
  static int aptr;
  const char *me = cls;
  struct MHD_Response *response;
  int ret;
  char *user;
  char *pass;
  int fail;

  if (0 != strcmp (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 */

  /* require: "Aladdin" with password "open sesame" */
  pass = NULL;
  user = MHD_basic_auth_get_username_password (connection, &pass);
  fail = ( (user == NULL) || (0 != strcmp (user, "Aladdin")) || (0 != strcmp (pass, "open sesame") ) );
  if (fail)
  {
      response = MHD_create_response_from_buffer (strlen (DENIED),
						  (void *) DENIED, 
						  MHD_RESPMEM_PERSISTENT);
      ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response);
    }
  else
    {
      response = MHD_create_response_from_buffer (strlen (me),
						  (void *) me, 
						  MHD_RESPMEM_PERSISTENT);
      ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
    }

  MHD_destroy_response (response);
  return ret;
}
开发者ID:Chris112,项目名称:sep,代码行数:48,代码来源:authorization_example.c

示例4: answer_to_connection

static int
answer_to_connection (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)
{
  char *user;
  char *pass;
  int fail;
  int ret;
  struct MHD_Response *response;

  if (0 != strcmp (method, "GET"))
    return MHD_NO;
  if (NULL == *con_cls)
    {
      *con_cls = connection;
      return MHD_YES;
    }
  pass = NULL;
  user = MHD_basic_auth_get_username_password (connection, &pass);
  fail = ( (user == NULL) ||
	   (0 != strcmp (user, "root")) ||
	   (0 != strcmp (pass, "pa$$w0rd") ) );  
  if (user != NULL) free (user);
  if (pass != NULL) free (pass);
  if (fail)
    {
      const char *page = "<html><body>Go away.</body></html>";
      response =
	MHD_create_response_from_buffer (strlen (page), (void *) page,
					 MHD_RESPMEM_PERSISTENT);
      ret = MHD_queue_basic_auth_fail_response (connection,
						"my realm",
						response);
    }
  else
    {
      const char *page = "<html><body>A secret.</body></html>";
      response =
	MHD_create_response_from_buffer (strlen (page), (void *) page,
					 MHD_RESPMEM_PERSISTENT);
      ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
    }
  MHD_destroy_response (response);
  return ret;
}
开发者ID:AlgoPeek,项目名称:libmicrohttpd,代码行数:47,代码来源:basicauthentication.c

示例5: ahc_echo

int ahc_echo(void* servctx, MHD_Connection* connection, const char* url, const char* method, const char* version, const char* upload_data, size_t* upload_data_size, void** reqctx)
{
	static int dummy;
	if (reqctx == NULL)
	{
		// The first time only the headers are valid, do not respond in the first round.
		*reqctx = &dummy;
		return MHD_YES;
	}

	ServerContext* pServCtx = (ServerContext*)servctx;	// Not used yet
	printf("%s %s %s\n", method, url, version);

	if (strcmp(method, "GET") == 0)
	{
		if (*upload_data_size != 0)
			return MHD_NO;	// No upload data expected in HTTP GET method
 
		// Parse headers
		puts("[HEADERS]");
		MHD_get_connection_values(connection, MHD_HEADER_KIND, &print_out_key, NULL);

		// Parse GET parameters
		puts("[GET PARAMS]");
		StringPairList spl;
		MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, &print_out_key, &spl);

		std::string text = "<html><body>\n";
		text += "<p>URL="; text += url; 
		text += "</p>\n<p>Parameters</p>\n<ul>\n";
		for (StringPairList::iterator it = spl.begin(); it != spl.end(); ++it)
		{
			text += "<li>"; text += it->first; text += '='; text += it->second; text += "</li>\n";
		}
		text += "</body></html>\n";

		MHD_Response* response = MHD_create_response_from_buffer(text.size(), (void*)text.c_str(), MHD_RESPMEM_MUST_COPY);
		MHD_add_response_header(response, "Content-Type", "text/html");
		int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
		MHD_destroy_response(response);

		*reqctx = NULL; // clear context pointer
		return ret;
	}
	else
		return MHD_NO;	// Not supported yet
}
开发者ID:Jerryang,项目名称:cdec,代码行数:47,代码来源:02.cpp

示例6: ServeMainPage

/**
 * Handler that adds the 'v1' value to the given HTML code.
 *
 * @param cls unused
 * @param mime mime type to use
 * @param session session handle
 * @param connection connection to use
 */
static int
ServeMainPage (const void *cls,
	      const char *mime,
	      struct Session *session,
	      struct MHD_Connection *connection)
{
  int ret;
  char *reply;
  struct MHD_Response *response;
  
  reply = malloc(MAXTEXTFILELENGTH);
  if (NULL == reply)
    return MHD_NO;  
  if ( !ReadTextFileIntoString(reply, "data/MainPage.html") )
    return MHD_NO;  

/*    
  // Open the MainPage html file
  FILE *fp = fopen("data/MainPage.html", "rb");
  if (NULL == fp)
	  return MHD_NO;
  fseek(fp, 0L, SEEK_END);
  long sz = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  reply = malloc (sz+1);
  if (NULL == reply)
    return MHD_NO;
  fread (reply, 1, sz, fp);
  fclose (fp);
 */

  /* return static form */
  response = MHD_create_response_from_buffer (strlen (reply),
					      (void *) reply,
					      MHD_RESPMEM_MUST_FREE);
  if (NULL == response)
    return MHD_NO;
  add_session_cookie (session, response);
  MHD_add_response_header (response,
			   MHD_HTTP_HEADER_CONTENT_ENCODING,
			   mime);
  ret = MHD_queue_response (connection,
			    MHD_HTTP_OK,
			    response);
  MHD_destroy_response (response);
  return ret;
}
开发者ID:riccardoventrella,项目名称:HIDWebServer,代码行数:55,代码来源:WebServer.c

示例7: http_create_response

void
http_create_response(struct Proxy* proxy,
                     char **nv)
{
  size_t i;
  
  if(!proxy->http_active)
    return;
  
  for(i = 0; nv[i]; i += 2) {
    if(0 == strcmp(":status", nv[i]))
    {
      char tmp[4];
      memcpy(&tmp,nv[i+1],3);
      tmp[3]=0;
      proxy->status = atoi(tmp);
      continue;
    }
    else if(0 == strcmp(":version", nv[i]))
    {
      proxy->version = nv[i+1];
      continue;
    }
    else if(0 == strcmp("content-length", nv[i]))
    {
      continue;
    }

    char *header = *(nv+i);
    if(MHD_NO == MHD_add_response_header (proxy->http_response,
                   header, nv[i+1]))
    {
      PRINT_INFO2("SPDY_name_value_add failed: '%s' '%s'", header, nv[i+1]);
    }
    PRINT_INFO2("adding '%s: %s'",header, nv[i+1]);
  }
  
  if(MHD_NO == MHD_queue_response (proxy->http_connection, proxy->status, proxy->http_response)){
    PRINT_INFO("No queue");
    //TODO
    //abort();
    proxy->http_error = true;
  }
  
  MHD_destroy_response (proxy->http_response);
  proxy->http_response = NULL;
}
开发者ID:Chris112,项目名称:sep,代码行数:47,代码来源:mhd2spdy_http.c

示例8: set_auth_cookie

inline void set_auth_cookie(struct MHD_Connection *connection)
{
	char response[64] = { 0 };
	char cookie[256] = { 0 };

	sprintf(response, "{\"login\": \"YES\"}");
	last_cookie = get_random_cookie();
	sprintf(cookie, AUTHENTICATE_COOKIE_FORAMT, AUTHENTICATE_COOKIE_NAME,
	        last_cookie, AUTHENTICATE_COOKIE_TIME);

	response = MHD_create_response_from_buffer (strlen(login),
	           (void *)(login), MHD_RESPMEM_PERSISTENT);
	MHD_add_response_header (response, MHD_HTTP_HEADER_SET_COOKIE,
	                         set_coockie);
	MHD_queue_response (connection, MHD_HTTP_OK, response);
	MHD_destroy_response (response);
}
开发者ID:caydyn-skd,项目名称:C_HTTP,代码行数:17,代码来源:http_server.c

示例9: MHD_create_response_from_buffer

int HTTPServer::send_page (struct MHD_Connection *connection, const char *page)
{
  int ret;
  struct MHD_Response *response;


  response =
    MHD_create_response_from_buffer (strlen (page), (void *) page,
				     MHD_RESPMEM_PERSISTENT);
  if (!response)
    return MHD_NO;

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

  return ret;
}
开发者ID:mnabaee,项目名称:bdcp,代码行数:17,代码来源:HTTPServer.cpp

示例10: handleRequest

    // return MHD_NO or MHD_YES
    virtual int handleRequest(  struct MHD_Connection *connection,
                                const char */*url*/, const char *method, const char */*version*/,
                                const char *upload_data, size_t *upload_data_size)
    {
        // new request
        if(mState == BEGIN)
        {
            if(strcmp(method, "POST") == 0)
            {
                mState = WAITING_DATA;
                // first time there is no data, do nothing and return
                return MHD_YES;
            }
        }
        if(mState == WAITING_DATA)
        {
            if(upload_data && *upload_data_size)
            {
                mRequesString += std::string(upload_data, *upload_data_size);
                *upload_data_size = 0;
                return MHD_YES;
            }
        }

        std::vector<uint8_t> bytes(mRequesString.begin(), mRequesString.end());

        int id = mApiServer->getTmpBlobStore()->storeBlob(bytes);

        resource_api::JsonStream responseStream;
        if(id)
            responseStream << makeKeyValue("ok", true);
        else
            responseStream << makeKeyValue("ok", false);

        responseStream << makeKeyValueReference("id", id);

        std::string result = responseStream.getJsonString();

        struct MHD_Response* resp = MHD_create_response_from_data(result.size(), (void*)result.data(), 0, 1);

        MHD_add_response_header(resp, "Content-Type", "application/json");

        secure_queue_response(connection, MHD_HTTP_OK, resp);
        MHD_destroy_response(resp);
        return MHD_YES;
    }
开发者ID:N00D13,项目名称:RetroShare,代码行数:47,代码来源:ApiServerMHD.cpp

示例11: send_bad_response

static int send_bad_response(struct MHD_Connection *connection)
{
    static char *bad_response = (char *) ERROR_PAGE;
    int bad_response_len = strlen(bad_response);
    int ret;
    struct MHD_Response *response;

    response = MHD_create_response_from_buffer(bad_response_len, bad_response,
            MHD_RESPMEM_PERSISTENT);
    if (response == 0)
    {
        return MHD_NO;
    }
    ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
    MHD_destroy_response(response);
    return ret;
}
开发者ID:nickerso,项目名称:web-service-demo,代码行数:17,代码来源:libhttpd-utils.cpp

示例12: answer_to_connection

int answer_to_connection (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) {
  const char *page = "<html><body>Hello!</body><html>";
  struct MHD_Response *response;
  int ret;

  response = MHD_create_response_from_buffer (strlen (page),
                                              (void*) page, MHD_RESPMEM_PERSISTENT);

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

  return ret;
}
开发者ID:kawakita,项目名称:3dprinting,代码行数:17,代码来源:hellobrowser.c

示例13: 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)
{
  int *done = cls;
  struct MHD_Response *response;
  int ret;
  int have;

  if (0 != strcmp ("PUT", method))
    return MHD_NO;              /* unexpected method */
  if ((*done) < 8)
    {
      have = *upload_data_size;
      if (have + *done > 8)
        {
          printf ("Invalid upload data `%8s'!\n", upload_data);
          return MHD_NO;
        }
      if (0 == memcmp (upload_data, &"Hello123"[*done], have))
        {
          *done += have;
          *upload_data_size = 0;
        }
      else
        {
          printf ("Invalid upload data `%8s'!\n", upload_data);
          return MHD_NO;
        }
#if 0
      fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
#endif
      return MHD_YES;
    }
  response = MHD_create_response_from_buffer (strlen (url),
					      (void *) url,
					      MHD_RESPMEM_MUST_COPY);
  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  MHD_destroy_response (response);
  return ret;
}
开发者ID:dcolish,项目名称:restpose,代码行数:46,代码来源:daemontest_put_chunked.c

示例14: 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)
{
  static int ptr;
  const char *me = cls;
  struct MHD_Response *response;
  int ret;
  const char *hdr;

  if (0 != strcmp (me, method))
    return MHD_NO;              /* unexpected method */
  if (&ptr != *unused)
    {
      *unused = &ptr;
      return MHD_YES;
    }
  *unused = NULL;
  ret = 0;

  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name1");
  if ((hdr == NULL) || (0 != strcmp (hdr, "var1")))
    abort ();
  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name2");
  if ((hdr == NULL) || (0 != strcmp (hdr, "var2")))
    abort ();
  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name3");
  if ((hdr == NULL) || (0 != strcmp (hdr, "")))
    abort ();
  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name4");
  if ((hdr == NULL) || (0 != strcmp (hdr, "var4 with spaces")))
    abort ();
  response = MHD_create_response_from_buffer (strlen (url),
					      (void *) url,
					      MHD_RESPMEM_PERSISTENT);
  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  MHD_destroy_response (response);
  if (ret == MHD_NO)
    abort ();
  return ret;
}
开发者ID:andreyuzunov,项目名称:libmicrohttpd,代码行数:46,代码来源:test_parse_cookies.c

示例15: query_session_ahc

/*
 * HTTP access handler call back
 * used to query negotiated security parameters
 */
static int
query_session_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)
{
  struct MHD_Response *response;
  int ret;
  
  if (NULL == *ptr)
    {
      *ptr = &query_session_ahc;
      return MHD_YES;
    }

  /* assert actual connection cipher is the one negotiated */
  if (GNUTLS_CIPHER_AES_256_CBC != 
      (ret = MHD_get_connection_info
       (connection,
	MHD_CONNECTION_INFO_CIPHER_ALGO)->cipher_algorithm))
    {
      fprintf (stderr, "Error: requested cipher mismatch (wanted %d, got %d)\n",
               GNUTLS_CIPHER_AES_256_CBC,
	       ret);
      return -1;
    }

  if (GNUTLS_SSL3 != 
      (ret = MHD_get_connection_info
       (connection,
	MHD_CONNECTION_INFO_PROTOCOL)->protocol))
    {
      fprintf (stderr, "Error: requested protocol mismatch (wanted %d, got %d)\n",
               GNUTLS_SSL3,
	       ret);
      return -1;
    }

  response = MHD_create_response_from_data (strlen (EMPTY_PAGE),
                                            (void *) EMPTY_PAGE,
                                            MHD_NO, MHD_NO);
  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  MHD_destroy_response (response);
  return ret;
}
开发者ID:morria,项目名称:CoffeeD,代码行数:49,代码来源:mhds_session_info_test.c


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