• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ send_response函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: on_request_recv

static int on_request_recv(nghttp2_session *session,
                           http2_session_data *session_data,
                           http2_stream_data *stream_data) {
  int fd;
  nghttp2_nv hdrs[] = {MAKE_NV(":status", "200")};
  char *rel_path;

  if (!stream_data->request_path) {
    if (error_reply(session, stream_data) != 0) {
      return NGHTTP2_ERR_CALLBACK_FAILURE;
    }
    return 0;
  }
  fprintf(stderr, "%s GET %s\n", session_data->client_addr,
          stream_data->request_path);
  if (!check_path(stream_data->request_path)) {
    if (error_reply(session, stream_data) != 0) {
      return NGHTTP2_ERR_CALLBACK_FAILURE;
    }
    return 0;
  }
  for (rel_path = stream_data->request_path; *rel_path == '/'; ++rel_path)
    ;
  fd = open(rel_path, O_RDONLY);
  if (fd == -1) {
    if (error_reply(session, stream_data) != 0) {
      return NGHTTP2_ERR_CALLBACK_FAILURE;
    }
    return 0;
  }
  stream_data->fd = fd;

  if (send_response(session, stream_data->stream_id, hdrs, ARRLEN(hdrs), fd) !=
      0) {
    close(fd);
    return NGHTTP2_ERR_CALLBACK_FAILURE;
  }
  return 0;
}
开发者ID:LPardue,项目名称:nghttp2,代码行数:39,代码来源:libevent-server.c


示例2: defined

bool CHttpServer::process(SOCKET sock)
{
    m_sock = sock;

	// First of all, make socket non-blocking
#if defined(WINDOWS_PLATFORM)
	unsigned long optval = 1;
	if(::ioctlsocket(m_sock, FIONBIO, &optval) == SOCKET_ERROR) {
		RAWLOG_ERROR1("Can not set non-blocking socket mode: %d", RHO_NET_ERROR_CODE);
		return false;
	}
#else
	int flags = fcntl(m_sock, F_GETFL);
	if (flags == -1) {
		RAWLOG_ERROR1("Can not get current socket mode: %d", errno);
		return false;
	}
	if (fcntl(m_sock, F_SETFL, flags | O_NONBLOCK) == -1) {
		RAWLOG_ERROR1("Can not set non-blocking socket mode: %d", errno);
		return false;
	}
#endif

    // Read request from socket
    ByteVector request;

    String method, uri, query;
    HeaderList headers;
    String body;
    if (!parse_request(method, uri, query, headers, body)) {
        RAWLOG_ERROR("Parsing error");
        send_response(create_response("500 Internal Error"));
        return false;
    }

    RAWLOG_INFO1("Process URI: '%s'", uri.c_str());

    return decide(method, uri, query, headers, body);
}
开发者ID:kumarvegeta,项目名称:rhodes,代码行数:39,代码来源:HttpServer.cpp


示例3: handle_app_chooser_close

static void
handle_app_chooser_close (AppChooserDialog *dialog,
                          gpointer data)
{
  AppDialogHandle *handle = data;
  GAppInfo *info;

  info = app_chooser_dialog_get_info (dialog);
  if (info != NULL)
    {
      const char *desktop_id = g_app_info_get_id (info);
      handle->response = 0;
      handle->chosen = g_strndup (desktop_id, strlen (desktop_id) - strlen (".desktop"));
    }
  else
    {
      handle->response = 1;
      handle->chosen = NULL;
    }

  send_response (handle);
}
开发者ID:flatpak,项目名称:xdg-desktop-portal-gtk,代码行数:22,代码来源:appchooser.c


示例4: wait_for_connected

void wait_for_connected() {
    pthread_t workThread;

    //start sending thread
    pthread_create(&workThread, NULL, send_ready_func, NULL);

    //wait for FTM alive
    char buf[BUF_SIZE];
    while(1) {
        serial_read(buf);
        if(!strncasecmp(buf, "FTM Alive", 9)) {
            PRINT_LOG("usb cable connected\n");
            connected = 1;
            break;
        }
    }
    pthread_join(workThread, NULL);

    //special response
    send_result("Recv:\r\nusb cable connected\r\n");
    send_response(NULL, 0);
}
开发者ID:Casperkings,项目名称:FastBoot,代码行数:22,代码来源:ftm.c


示例5: eventCB

LOCAL void ICACHE_FLASH_ATTR eventCB(System_Event_t *event) {
        switch(event->event) {
            case EVENT_STAMODE_CONNECTED:
                os_printf("Event: EVENT_STAMODE_CONNECTED");
                break;
            case EVENT_STAMODE_DISCONNECTED:
                os_printf("Event: EVENT_STAMODE_DISCONNECTED");
                break;
            case EVENT_STAMODE_AUTHMODE_CHANGE:
                os_printf("Event: EVENT_STAMODE_AUTHMODE_CHANGE");
                break;
            case EVENT_STAMODE_GOT_IP:
                os_printf("Event: EVENT_STAMODE_GOT_IP");
                //os_printf("IP: %d.%d.%d.%d\n", IP2STR(&event->event_info.got_ip.ip));
                //setupTCP();
                break;
            case EVENT_SOFTAPMODE_STACONNECTED:{
                struct station_info *stationInfo = wifi_softap_get_station_info();
                if(stationInfo != NULL){
                    os_printf("%d.%d.%d.%d", IP2STR(&(stationInfo->ip))); 
                    os_sprintf(attackip, "%d.%d.%d.%d", IP2STR(&(stationInfo->ip)));
                    send_response();            
                }
                wifi_softap_free_station_info(); 
                os_printf("Event: EVENT_SOFTAPMODE_STACONNECTED");
                }
                break;
            case EVENT_SOFTAPMODE_STADISCONNECTED:
                os_printf("Event: EVENT_SOFTAPMODE_STADISCONNECTED");
                break;
            case EVENT_SOFTAPMODE_PROBEREQRECVED:
                //os_printf("Event: EVENT_PROBEREQUEST");
                break;
            default:
                os_printf("Unexpected event: %d\r\n", event->event);
                break;
        }
} // End of eventCB
开发者ID:peterfillmore,项目名称:ThreatbuttFreeWifi,代码行数:38,代码来源:user_main.c


示例6: vcl_json

static unsigned int
vcl_json(struct http_request *request, const char *arg, void *data)
{
	struct agent_core_t *core = data;
	struct vcl_priv_t *vcl;
	struct ipc_ret_t vret;
	struct vsb *json;
	struct http_response *resp;

	GET_PRIV(core, vcl);

	assert(STARTS_WITH(request->url, "/vcljson"));
	assert(request->method == M_GET);

	if (arg) {
		http_reply(request->connection, 404,
		    "/vcljson takes no argument");
		return (0);
	}

	ipc_run(vcl->vadmin, &vret, "vcl.list");
	if (vret.status == 400)
		http_reply(request->connection, 500, vret.answer);
	else {
		json = vcl_list_json(vret.answer);
		assert(VSB_finish(json) == 0);
		resp = http_mkresp(request->connection, 200, NULL);
		resp->data = VSB_data(json);
		resp->ndata = VSB_len(json);
		http_add_header(resp, "Content-Type", "application/json");
		send_response(resp);
		http_free_resp(resp);
		VSB_clear(json);
		VSB_delete(json);
	}
	free(vret.answer);
	return (0);
}
开发者ID:varnish,项目名称:vagent2,代码行数:38,代码来源:vcl.c


示例7: on_message

                        /**
                         * Is called when the message is received by the server
                         * @param hdl the connection handler
                         * @param raw_msg the received message
                         */
                        virtual void on_message(websocketpp::connection_hdl hdl, server::message_ptr raw_msg) {
                            LOG_DEBUG << "Received a message!" << END_LOG;

                            //Create an empty json message
                            incoming_msg * jmsg = new incoming_msg();

                            //De-serialize the message and then handle based on its type
                            try {
                                string raw_msg_str = raw_msg->get_payload();

                                LOG_DEBUG << "Received JSON msg: " << raw_msg_str << END_LOG;

                                //De-serialize the message
                                jmsg->de_serialize(raw_msg_str);

                                //Handle the request message based on its type
                                switch (jmsg->get_msg_type()) {
                                    case msg_type::MESSAGE_TRANS_JOB_REQ:
                                        translation_request(hdl, new trans_job_req_in(jmsg));
                                        break;
                                    case msg_type::MESSAGE_SUPP_LANG_REQ:
                                        language_request(hdl, new supp_lang_req_in(jmsg));
                                        break;
                                    case msg_type::MESSAGE_PRE_PROC_JOB_REQ:
                                        pre_process_request(hdl, new proc_req_in(jmsg));
                                        break;
                                    case msg_type::MESSAGE_POST_PROC_JOB_REQ:
                                        post_process_request(hdl, new proc_req_in(jmsg));
                                        break;
                                    default:
                                        THROW_EXCEPTION(string("Unsupported request type: ") + to_string(jmsg->get_msg_type()));
                                }
                            } catch (std::exception & e) {
                                //Send the error response, NOTE! This is not a JSON we are sending
                                //back, but just a string, as someone violated the protocol!
                                send_response(hdl, e.what());
                            }
                        }
开发者ID:ivan-zapreev,项目名称:Basic-Translation-Infrastructure,代码行数:43,代码来源:websocket_server.hpp


示例8: account_dialog_done

static void
account_dialog_done (GtkWidget *widget,
                     int response,
                     const char *user_name,
                     const char *real_name,
                     const char *icon_file,
                     gpointer user_data)
{
  AccountDialogHandle *handle = user_data;

  g_clear_pointer (&handle->user_name, g_free);
  g_clear_pointer (&handle->real_name, g_free);
  g_clear_pointer (&handle->icon_uri, g_free);

  switch (response)
    {
    default:
      g_warning ("Unexpected response: %d", response);
      /* Fall through */
    case GTK_RESPONSE_DELETE_EVENT:
      handle->response = 2;
      break;

    case GTK_RESPONSE_CANCEL:
      handle->response = 1;
      break;

    case GTK_RESPONSE_OK:
      handle->user_name = g_strdup (user_name);
      handle->real_name = g_strdup (real_name);
      if (icon_file)
        handle->icon_uri = g_filename_to_uri (icon_file, NULL, NULL);
      handle->response = 0;
      break;
    }

  send_response (handle);
}
开发者ID:amigadave,项目名称:xdg-desktop-portal-gtk,代码行数:38,代码来源:account.c


示例9: ftserve_login

/** 
 * Log in connected client
 */
int ftserve_login(int sock_control)
{	
	char buf[MAXSIZE];
	char user[MAXSIZE];
	char pass[MAXSIZE];	
	memset(user, 0, MAXSIZE);
	memset(pass, 0, MAXSIZE);
	memset(buf, 0, MAXSIZE);
	
	// Wait to recieve username
	if ( (recv_data(sock_control, buf, sizeof(buf)) ) == -1) {
		perror("recv error\n"); 
		exit(1);
	}	

	int i = 5;
	int n = 0;
	while (buf[i] != 0)
		user[n++] = buf[i++];
	
	// tell client we're ready for password
	send_response(sock_control, 331);					
	
	// Wait to recieve password
	memset(buf, 0, MAXSIZE);
	if ( (recv_data(sock_control, buf, sizeof(buf)) ) == -1) {
		perror("recv error\n"); 
		exit(1);
	}
	
	i = 5;
	n = 0;
	while (buf[i] != 0) {
		pass[n++] = buf[i++];
	}
	
	return (ftserve_check_user(user, pass));
}
开发者ID:beckysag,项目名称:ftp,代码行数:41,代码来源:ftserve.c


示例10: send_udf_failure

/**
 * Send failure notification of general UDF execution, but check for special
 * LDT errors and return specific Wire Protocol error codes for these cases:
 * (1) Record not found (2)
 * (2) LDR Collection item not found (125)
 *
 * All other errors get the generic 100 (UDF FAIL) code.
 *
 * Parse (Actually, probe) the error string, and if we see this pattern:
 * FileName:Line# 4digits:LDT-<Error String>
 * For example:
 * .../aerospike-lua-core/src/ldt/lib_llist.lua:982: 0002:LDT-Top Record Not Found
 * All UDF errors (LDT included), have the "filename:line# " prefix, and then
 * LDT errors follow that with a known pattern:
 * (4 digits, colon, LDT-<Error String>).
 * We will check the error string by looking for specific markers after the
 * the space that follows the filename:line#.  If we see the markers, we will
 * parse the LDT error code and use that as the wire protocol error if it is
 * one of the special ones:
 * (1)  "0002:LDT-Top Record Not Found"
 * (2)  "0125:LDT-Item Not Found"
 */
static inline int
send_udf_failure(udf_call *call, int vtype, void *val, size_t vlen)
{
	// We need to do a quick look to see if this is an LDT error string.  If it
	// is, then we'll look deeper.  We start looking after the first space.
	char * charptr;
	char * valptr = (char *) val;
	long error_code;

	// Start with the space, if it exists, as the marker for where we start
	// looking for the LDT error contents.
	if ((charptr = strchr((const char *) val, ' ')) != NULL) {
		// We must be at least 10 chars from the end, so if we're less than that
		// we are obviously not looking at an LDT error.
		if (&charptr[9] < &valptr[vlen]) {
			if (memcmp(&charptr[5], ":LDT-", 5) == 0) {
				error_code = strtol(&charptr[1], NULL, 10);
				if (error_code == AS_PROTO_RESULT_FAIL_NOTFOUND ||
					error_code == AS_PROTO_RESULT_FAIL_COLLECTION_ITEM_NOT_FOUND)
				{
					call->transaction->result_code = error_code;
					cf_debug(AS_UDF, "LDT Error: Code(%ld) String(%s)",
							error_code, (char *) val);
					// Send an "empty" response, with no failure bin.
					as_transaction *    tr          = call->transaction;
					single_transaction_response(tr, tr->rsv.ns, NULL/*ops*/,
							NULL /*bin*/, 0 /*nbins*/, 0, 0, NULL, NULL);
					return 0;
				}
			}
		}
	}

	cf_debug(AS_UDF, "Non-special LDT or General UDF Error(%s)", (char *) val);

	call->transaction->result_code = AS_PROTO_RESULT_FAIL_UDF_EXECUTION;
	return send_response(call, "FAILURE", 7, vtype, val, vlen);
}
开发者ID:LilyMat,项目名称:aerospike-server,代码行数:60,代码来源:udf_rw.c


示例11: answer_file

static void
answer_file(struct vmod_fsdirector_file_system *fs, struct stat *stat_buf,
    const char *path)
{
	mode_t mode = stat_buf->st_mode;

	if (S_ISREG(mode)) {
		if (stat_buf->st_size) {
			send_response(fs, stat_buf, path);
		}
		else {
			prepare_answer(&fs->htc, 204);
			prepare_body(&fs->htc);
		}
	}
	else if (S_ISLNK(mode)) {
		send_redirect(fs, path);
	}
	else {
		prepare_answer(&fs->htc, 404);
		prepare_body(&fs->htc);
	}
}
开发者ID:Dridi,项目名称:libvmod-fsdirector,代码行数:23,代码来源:vmod_fsdirector.c


示例12: respond_to

/* Given a HTTP message and the size of the message 
 * Responds to the given socket with the approrpriate
 * HTTP response. The space allocated for message should
 * be at least 1 more than req_size */
status respond_to(char* buf, int confd)
{
    char resource[BUFLEN+1],
         *resource_line, *headers, *current;
    int result;
    
    current = buf;
    /*  Cut off the Resource line */
    resource_line = strsep_str(&current, "\r\n"); 

    /*  Get the resource, if error with parsing request line, send 400 response */
    if ((result = parse_request_line(resource_line, resource)) != OK) {
        printf("Recieved badly formatted request line from connection %d\n",confd);
        return send_error(result, confd);
    }

    printf("request good\n");

    headers = strsep_str(&current, "\r\n\r\n");
    printf("headers:%s\n",headers);
     
    return send_response(resource, confd);
}
开发者ID:RossMeikleham,项目名称:Webserver-C,代码行数:27,代码来源:web_server.c


示例13: error_reply

static int error_reply(nghttp2_session *session,
                       http2_stream_data *stream_data) {
  int rv;
  ssize_t writelen;
  int pipefd[2];
  nghttp2_nv hdrs[] = {MAKE_NV(":status", "404")};

  rv = pipe(pipefd);
  if (rv != 0) {
    warn("Could not create pipe");
    rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE,
                                   stream_data->stream_id,
                                   NGHTTP2_INTERNAL_ERROR);
    if (rv != 0) {
      warnx("Fatal error: %s", nghttp2_strerror(rv));
      return -1;
    }
    return 0;
  }

  writelen = write(pipefd[1], ERROR_HTML, sizeof(ERROR_HTML) - 1);
  close(pipefd[1]);

  if (writelen != sizeof(ERROR_HTML) - 1) {
    close(pipefd[0]);
    return -1;
  }

  stream_data->fd = pipefd[0];

  if (send_response(session, stream_data->stream_id, hdrs, ARRLEN(hdrs),
                    pipefd[0]) != 0) {
    close(pipefd[0]);
    return -1;
  }
  return 0;
}
开发者ID:LPardue,项目名称:nghttp2,代码行数:37,代码来源:libevent-server.c


示例14: get_pool

/// Mangelwurzel receives a response. It will add all the Via headers from the
/// original request back on and send the response on. It can also change
/// the response in various ways depending on the configuration that was
/// specified in the Route header of the original request.
/// - It can mangle the dialog identifiers using its mangalgorithm.
/// - It can mangle the Contact URI using its mangalgorithm.
/// - It can mangle the Record-Route and Route headers URIs.
void MangelwurzelTsx::on_rx_response(pjsip_msg* rsp, int fork_id)
{
  pj_pool_t* pool = get_pool(rsp);

  if (_config.dialog)
  {
    mangle_dialog_identifiers(rsp, pool);
  }

  if (_config.req_uri)
  {
    mangle_contact(rsp, pool);
  }

  if (_config.routes)
  {
    mangle_record_routes(rsp, pool);
    mangle_routes(rsp, pool);
  }

  add_via_hdrs(rsp, pool);

  send_response(rsp);
}
开发者ID:ClearwaterCore,项目名称:sprout,代码行数:31,代码来源:mangelwurzel.cpp


示例15: send_delete_res

void send_delete_res(int status, int num_msg)
{
  response_t res;
  res.status_code = status;

  if (status == STATUS_OK)
  {
    res.data = malloc(sizeof(int));
    if (res.data == NULL)
      return;
    *((int *) res.data) = num_msg;
    res.data_len = sizeof(int);
  }
  else
  {
    res.data = NULL;
    res.data_len = 0;
  }

  send_response(&res, CMD_DELETE);

  if (res.data)
    free(res.data);
}
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:24,代码来源:response.c


示例16: dbg

void c_rpc_server::c_session::execute_rpc_command(const std::string &input_message) {
	try {
		nlohmann::json j = nlohmann::json::parse(input_message);
                const std::string cmd_name = j["cmd"];//.begin().value();
                dbg("cmd name " << cmd_name);
		// calling rpc function
		nlohmann::json json_response;
		{
			LockGuard<Mutex> lg(m_rpc_server_ptr->m_rpc_functions_map_mutex);
			json_response = m_rpc_server_ptr->m_rpc_functions_map.at(cmd_name)(input_message);
		}
		json_response["id"] = get_command_id();
		if (j.find("id")!= j.end()) {
			json_response["re"] = j["id"];
		}
		send_response(json_response);
	}
	catch (const std::exception &e) {
		_erro( "exception in execute_rpc_command " << e.what() );
		_erro( "close connection\n" );
		delete_me();
		return;
	}
}
开发者ID:tigusoft,项目名称:galaxy42,代码行数:24,代码来源:rpc.cpp


示例17: handle_renew_lease

          int handle_renew_lease(ObPacket* ob_packet)
          {
            int ret = OB_SUCCESS;

            ObDataBuffer* data_buffer = ob_packet->get_buffer();
            if (NULL == data_buffer)
            {
              TBSYS_LOG(ERROR, "data_buffer is NUll should not reach this");
              ret = OB_ERROR;
            }
            else
            {
              ObServer slave_addr;
              char addr_buf[1024];
              ret = slave_addr.deserialize(data_buffer->get_data(), data_buffer->get_capacity(),
                 data_buffer->get_position());
              slave_addr.to_string(addr_buf, sizeof(addr_buf));
              addr_buf[sizeof(addr_buf) - 1] = '\0';
              TBSYS_LOG(DEBUG, "recv renew lease request, slave_addr=%s, ret=%d", addr_buf, ret);
              tbnet::Connection* connection = ob_packet->get_connection();
              char buf[10 * 1024];
              ObDataBuffer out_buffer(buf, sizeof(buf));

              ObResultCode response;
              response.result_code_ = OB_SUCCESS;
              response.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
                  out_buffer.get_position());

              int32_t version = 1;
              int32_t channel_id = ob_packet->getChannelId();
              ret = send_response(OB_RENEW_LEASE_RESPONSE, version, out_buffer, connection, channel_id);
              TBSYS_LOG(DEBUG, "send renew lease response, ret=%d", ret);
            }

            return ret;
          }
开发者ID:CCoder123,项目名称:pproj,代码行数:36,代码来源:mock_server.cpp


示例18: worker

static int worker()
{
	unsigned char exit_status;

	int ret;

	void *ctx = zmq_ctx_new();
	void *sock = zmq_socket(ctx, ZMQ_REP);

	zmq_connect(sock, WORKER_IPC);

	while (1) {
		exit_status = 1;
		ret = process_msg(sock, &exit_status);

		if (ret < 0) {
			if (ret == -2)
				break;
			printf("Failed to receive/process message\n");
		}

		send_response(sock, ret, exit_status);
	}

	printf("Worker shutting down...\n");

	ret = zmq_close(sock);
	if (ret < 0)
		fprintf(stderr, "Failed to close socket\n");

	ret = zmq_ctx_destroy(ctx);
	if(ret < 0)
		fprintf(stderr, "Failed to stop ZMQ\n");

	return 0;
}
开发者ID:RPI-HPC,项目名称:cq,代码行数:36,代码来源:server.c


示例19: send_motd

int		send_motd(int fd, char hostname[1024])
{
  char		*tmp1;
  char		*tmp2;

  if ((tmp1 = str_concat(":- ", hostname, " Message of the day -")) == NULL
      || (tmp2 = str_concat(":- By connecting to ", hostname,
			    " you indicate that you")) == NULL)
    return (-1);
  send_response(fd, "375", tmp1);
  send_response(fd, "372", tmp2);
  send_response(fd, "372", ":- have read and accept our policies");
  send_response(fd, "372", ":- In particular\
 we would like to thank the sponsor");
  send_response(fd, "372", ":- of this server, the asteks");
  send_response(fd, "372", ":-");
  send_response(fd, "376", ":End of /MOTD command.");
  free(tmp1);
  free(tmp2);
  return (0);
}
开发者ID:simonvadee,项目名称:UnixSystem2014,代码行数:21,代码来源:begin_connection.c


示例20: handle_client


//.........这里部分代码省略.........
         bytes += recv(socket, req + bytes, BUFFER_SIZE, 0);
      }
    }
    // printf("recv %i bytes\n", bytes);

    // Get HTTP method
    method = http_parse_method(req);

    // Get path
    strcpy(buf, req);
    path = http_parse_path(http_parse_uri(buf));
    // printf("Request: %s\n", path);

    // Parse cookies 
    if (strstr(req, HDR_COOKIE)) {
      strcpy(buf, req);
      cookie = get_cookies_from_header(get_header_value_from_req(buf, HDR_COOKIE));
    } else {
      cookie = NULL;
    }

    // Match service command
    cmd = SERV_UNKNOWN;
    for (s= 0; s < SERV_UNKNOWN; s++) {
      if (strncasecmp(path, service_str[s], strlen(service_str[s])) == 0) {
        cmd = s;
        break;
      }
    }

    // Handle command
    switch(cmd) {
      case SERV_KNOCK:
      case SERV_LOGIN:
      case SERV_LOGOUT:
      case SERV_GETFILE:
      case SERV_ADDCART:
      case SERV_DELCART:
      case SERV_CHECKOUT:
        if (method == METHOD_GET) {
          param = get_params_from_query(get_query_str_from_path(path));
          if (cmd == SERV_KNOCK) {
            knock_handler(&resp, cookie);
          } else if (cmd == SERV_LOGIN) {
            login_handler(&resp, param);
          } else if (cmd == SERV_LOGOUT) {
            logout_handler(&resp, cookie);
          } else if (cmd == SERV_GETFILE) {
            since_time = 0;
            strcpy(buf, req);
            if (strstr(buf, HDR_IF_MOD_SINCE)) {
              if (!RFC_822_to_time(strstr(buf, HDR_IF_MOD_SINCE) + 
                    strlen(HDR_IF_MOD_SINCE), &since_time)) {
                since_time = 0;
              }
            }
            getfile_handler(&resp, param, since_time);
          } else if (cmd == SERV_ADDCART) {
            addcart_handler(&resp, param, cookie);
          } else if (cmd == SERV_DELCART) {
            delcart_handler(&resp, param, cookie);
          } else if (cmd == SERV_CHECKOUT) {
            checkout_handler(&resp, cookie);
          } else {
            resp.status = NOT_FOUND;
          }
        } else {
          resp.allow = METHOD_GET;
          resp.status = METHOD_NOT_ALLOWED;
        }
        break;
      case SERV_PUTFILE:
        if (method == METHOD_POST) {
          strcpy(buf, req);
          param = get_params_from_query((char*) http_parse_body(buf, bytes));
          putfile_handler(&resp, cookie, param);
        } else {
          resp.allow = METHOD_POST;
          resp.status = METHOD_NOT_ALLOWED;
        }
        break;
      default:
        resp.status = NOT_FOUND;
        break;
    }

    // Check if status not ok or 
    // client wants to close connection after completing request
    if (resp.status != OK) {
      resp.connection = CLOSE;
    } else if (strstr(req, "Connection:")) {
      connection = http_parse_header_field(buf, bytes, "Connection");
      if (strcmp(connection, "close") == 0) {
        resp.connection = CLOSE;
      }
    }

    send_response(socket, &resp);  
  } while (resp.connection != CLOSE);
}
开发者ID:edwardsoo,项目名称:cs317_a4,代码行数:101,代码来源:service.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ send_result函数代码示例发布时间:2022-05-30
下一篇:
C++ send_request函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap