示例#1
0
void client::promote(std::string const& username, std::string const& password)
{
	d->feed(handle_response(dl.fetch(basepath + "/create_sessionticket/" + username + formatstr)));

	auto st(deserialize<message::sessionticket>(d, "sessiontoken"));

	token const passphrase_salted(hash(password, st.salt));
	token const passphrase_hashed(hash(passphrase_salted, st.nonce));

	d->feed(handle_response(dl.post(basepath + "/login/" + boost::lexical_cast<std::string>(st.id.unseal()) + formatstr, {{"password_hashed", to_string(passphrase_hashed)}})));

	stok.reset(deserialize<message::sessiontoken>(d, "sessiontoken"));
}
示例#2
0
static void
CheckBarrierCommandStatus(PGXCNodeAllHandles *conn_handles, const char *id,
						  const char *command)
{
	int conn;
	int count = conn_handles->co_conn_count + conn_handles->dn_conn_count;

	elog(DEBUG2, "Check CREATE BARRIER <%s> %s command status", id, command);

	for (conn = 0; conn < count; conn++)
	{
		PGXCNodeHandle *handle;

		if (conn < conn_handles->co_conn_count)
			handle = conn_handles->coord_handles[conn];
		else
			handle = conn_handles->datanode_handles[conn - conn_handles->co_conn_count];

		if (pgxc_node_receive(1, &handle, NULL))
			ereport(ERROR,
					(errcode(ERRCODE_INTERNAL_ERROR),
					 errmsg("Failed to receive response from the remote side")));

		if (handle_response(handle, NULL) != RESPONSE_BARRIER_OK)
			ereport(ERROR,
					(errcode(ERRCODE_INTERNAL_ERROR),
					 errmsg("CREATE BARRIER PREPARE command failed "
						 	"with error %s", handle->error)));
	}

	elog(DEBUG2, "Successfully completed CREATE BARRIER <%s> %s command on "
				 "all nodes", id, command);
}
示例#3
0
void AuthTimeoutTask::run()
{
  if (_req.method() != htp_method_POST)
  {
    send_http_reply(HTTP_BADMETHOD);
    delete this;
    return;
  }

  SAS::Marker start_marker(trail(), MARKER_ID_START, 1u);
  SAS::report_marker(start_marker);

  HTTPCode rc = handle_response(_req.get_rx_body());

  SAS::Marker end_marker(trail(), MARKER_ID_END, 1u);
  SAS::report_marker(end_marker);

  if (rc != HTTP_OK)
  {
    LOG_DEBUG("Unable to handle callback from Chronos");
    send_http_reply(rc);
    delete this;
    return;
  }

  send_http_reply(HTTP_OK);
  delete this;
}
示例#4
0
void client::add_product_image_citation(id_t supermarket_id, std::string const& product_identifier, std::string const& original_uri, std::string const& source_uri, const datetime &retrieved_on, raw &&image)
{
	message::add_product_image_citation request({
		original_uri,
		source_uri,
		retrieved_on,
		std::move(image)
	});

	std::string response = handle_response(post(s, dl, basepath + "/add_product_image_citation/" + boost::lexical_cast<std::string>(supermarket_id) + "/" + product_identifier + formatstr, "add_product_image_citation", request, stok));
	try
	{
		d->feed(response);
		std::string result;
		d->read_object("response");
		d->read("status", result);

		if(result == "done")
			return;
	}
	catch( ... )
	{
		d.reset(new msgpack_deserializer()); // State uncertain; flush
	}

	std::cerr << response << std::endl;
	throw std::runtime_error("Did not receive valid response");
}
示例#5
0
static int do_read(struct userdata *u) {
    pa_assert(u);

    if (!pa_iochannel_is_readable(u->io))
        return 0;

    if (u->state == STATE_AUTH || u->state == STATE_LATENCY) {
        ssize_t r;

        if (!u->read_data)
            return 0;

        pa_assert(u->read_index < u->read_length);

        if ((r = pa_iochannel_read(u->io, (uint8_t*) u->read_data + u->read_index, u->read_length - u->read_index)) <= 0) {
            pa_log("read() failed: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
            return -1;
        }

        u->read_index += (size_t) r;
        pa_assert(u->read_index <= u->read_length);

        if (u->read_index == u->read_length)
            return handle_response(u);
    }

    return 0;
}
示例#6
0
int deleteascript(int version, struct protstream *pout,
                  struct protstream *pin, const char *name,
                  char **refer_to, char **errstrp)
{
  lexstate_t state;
  int res;
  int ret;
  char *errstr = NULL;

  prot_printf(pout,"DELETESCRIPT \"%s\"\r\n",name);
  prot_flush(pout);

  res=yylex(&state, pin);

  ret = handle_response(res,version,pin,refer_to,&errstr);

  if(ret == -2 && *refer_to) {
      return -2;
  } else if (ret!=0) {
      *errstrp = strconcat("Deleting script: ",
                           errstr,
                           (char *)NULL);
      return -1;
  }

  return 0;
}
示例#7
0
/*
 *  Expand argv vector
 *
 *  Values for how:
 *    EXP_WILDCARD	Perform wildcard expansion (DEPRECATED)
 *    EXP_RESPONSE	Handle response files (last argument @filename)
 */
void
expand_argv (int *argc, char ***argv, int how)
{
  char *element;
  int nargs;
  int i;
  
  glob_argc = 0;

  nargs = *argc;
  max_argv = nargs + REALLOC_AMOUNT;
  glob_argv = salloc (max_argv, char *);

  for (i = 0; i < nargs; i++)
    {
      element = (*argv)[i];
      if (*element == '@' && (how & EXP_RESPONSE) && i == nargs - 1)
	handle_response (element + 1);
      else
	add_argv (element);
    }

  *argc = glob_argc;
  *argv = glob_argv;
}
示例#8
0
int installdata(int version,struct protstream *pout, struct protstream *pin,
                char *scriptname, char *data, int len,
                char **refer_to, char **errstrp)
{
  int res;
  int ret;
  char *errstr=NULL;
  lexstate_t state;

  prot_printf(pout, "PUTSCRIPT \"%s\" ",scriptname);

  prot_printf(pout, "{%d+}\r\n",len);

  prot_write(pout, data, len);

  prot_printf(pout,"\r\n");
  prot_flush(pout);

  /* now let's see what the server said */
  res=yylex(&state,pin);

  ret = handle_response(res,version,pin,refer_to,&errstr);

  /* if command failed */
  if(ret == -2 && *refer_to) {
      return -2;
  } else if (ret!=0) {
      *errstrp = strconcat("Putting script: ",
                           errstr,
                           (char *)NULL);
      return -1;
  }

  return 0;
}
示例#9
0
int setscriptactive(int version, struct protstream *pout,
                    struct protstream *pin,char *name,
                    char **refer_to, char **errstrp)
{
  lexstate_t state;
  int res;
  int ret;
  char *errstr=NULL;

  /* tell server we want "name" to be the active script */
  prot_printf(pout, "SETACTIVE \"%s\"\r\n",name);
  prot_flush(pout);

  /* now let's see what the server said */
  res=yylex(&state, pin);

  ret = handle_response(res, version, pin, refer_to, &errstr);

  /* if command failed */
  if(ret == -2 && *refer_to) {
      return -2;
  } else if (ret != 0) {
      *errstrp = strconcat("Setting script active: ",
                           errstr,
                           (char *)NULL);
      return -1;
  }
  return 0;
}
示例#10
0
void handle_netstring(jsonrpc_server_t* server)
{
	unsigned int old_count = server->req_count;
	server->req_count--;
	if (server->hwm > 0
			&& old_count >= server->hwm
			&& server->req_count < server->hwm) {
		INFO("%.*s:%d in connection group %.*s is back to normal\n",
				STR(server->addr), server->port, STR(server->conn));
	}

	json_error_t error;

	json_t* res = json_loads(server->buffer->string, 0, &error);

	if (res) {
		if(handle_response(res)<0){
			ERR("Cannot handle jsonrpc response: %s\n", server->buffer->string);
		}
		json_decref(res);
	} else {
		ERR("Failed to parse json: %s\n", server->buffer->string);
		ERR("PARSE ERROR: %s at %d,%d\n",
				error.text, error.line, error.column);
	}
}
/**
 * Handle a request and send a response
 *
 * @param cls unused
 * @param other the sender
 * @param message the message
 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
 */
static int
core_receive_handler (void *cls,
		      const struct GNUNET_PeerIdentity *other,
		      const struct GNUNET_MessageHeader *message)
{
	if (ntohs (message->size) < sizeof (struct GNUNET_MessageHeader))
	{
			GNUNET_break (0);
			return GNUNET_SYSERR;
	}

	switch (ntohs (message->type)) {
		case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
			handle_request (other, message);
			break;
		case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
			handle_response (other, message);
			break;
		case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START:
			handle_start (other, message);
			break;
		case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_START_ACK:
			handle_start_ack (other, message);
			break;
		case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_STOP:
			handle_stop (other, message);
			break;
		default:
			break;
	}

	return GNUNET_OK;
}
示例#12
0
void AuthTimeoutHandler::run()
{
  if (_req.method() != htp_method_POST)
  {
    send_http_reply(HTTP_BADMETHOD);
    delete this;
    return;
  }

  SAS::Marker start_marker(trail(), MARKER_ID_START, 1u);
  SAS::report_marker(start_marker);
  SAS::Marker calling_dn(trail(), MARKER_ID_CALLING_DN, 1u);
  calling_dn.add_var_param(_impu);
  SAS::report_marker(calling_dn);

  HTTPCode rc = handle_response(_req.body());

  SAS::Marker end_marker(trail(), MARKER_ID_END, 1u);
  SAS::report_marker(end_marker);

  if (rc != HTTP_OK)
  {
    LOG_DEBUG("Unable to handle callback from Chronos");
    send_http_reply(rc);
    delete this;
    return;
  }

  send_http_reply(HTTP_OK);
  delete this;
}
示例#13
0
void client::update_tag_set_parent(reference<data::tag> tag_id, boost::optional<reference<data::tag>> parent_tag_id)
{
	std::string uri = basepath + "/update_tag_set_parent/" + boost::lexical_cast<std::string>(tag_id);
	if(parent_tag_id)
		uri += "/" + boost::lexical_cast<std::string>(*parent_tag_id) + formatstr;

	std::string response = handle_response(get(dl, uri, stok));
	try
	{
		d->feed(response);
		std::string result;
		d->read_object("response");
		d->read("status", result);

		if(result == "done")
			return;
	}
	catch( ... )
	{
		d.reset(new msgpack_deserializer()); // State uncertain; flush
	}

	std::cerr << response << std::endl;
	throw std::runtime_error("Did not receive valid response");
}
示例#14
0
/*
 * Here we have to update the buffer in case of keep-alive
 *
 * This is called only when the whole body has been read in!
 *
 * Read has been stopped for keep_alive == false.
 *
 * It can be, that the next request (keep_alive == true) will arrive before the
 * on_write_done_cb is called. That is why we have to allocate a new
 * write_req_t for every write request we do.
 */
static void
handle_http_request(Connection *conn)
{
  http_request *request = &conn->req;
  bool keep_alive = http_request_is_keep_alive(request);

  int content_length = request->content_length;
  if (content_length < 0) { content_length = 0; }

  write_req_t *req = new write_req_t();
  req->conn = conn;

  handle_response(request, req->out, keep_alive); 
  req->buf = uv_buf_init(req->out.data(), req->out.size());

  if (keep_alive) {
    // how many bytes in our buffer belong to the next request?
    size_t request_bytes = request->body_start + content_length;
    if (conn->read_buffer.size() > request_bytes) {
      conn->read_buffer.shift_left(request_bytes);
    }
    else {
      conn->read_buffer.reset();
    }
  }

  int err = uv_write((uv_write_t*) req, (uv_stream_t*)req->conn, &req->buf, 1, on_write_done_cb);
  assert(err == 0);
}
示例#15
0
static int getauthline(isieve_t *obj, char **line, unsigned int *linelen,
		       char **errstrp)
{
  lexstate_t state;
  int res;
  size_t len;
  char *errstr = NULL;
  char *last_send;
  int r;

  /* now let's see what the server said */
  res=yylex(&state, obj->pin);
  *line = NULL;
  if (res!=STRING)
  {
      (void)handle_response(res, obj->version,
			    obj->pin, &last_send, &errstr);
      
      if (res==TOKEN_OK) {
	  /* Was there a last send from the server? */
	  if(last_send) {
	      /* it's base64 encoded */
	      int last_send_len = strlen(last_send);

	      len = last_send_len*2+1;
	      *line = xmalloc(len);

	      r = sasl_decode64(last_send, last_send_len,
				*line, len, linelen);

	      free(last_send);
	      if (r != SASL_OK)
		return STAT_NO;
	  }
	  return STAT_OK;
      } else { /* server said no or bye*/
	  /* xxx handle referrals */
	  *errstrp = errstr;
	  return STAT_NO;
      }
  }

  len = strlen(state.str)*2+1;
  *line=(char *) xmalloc(len);

  r = sasl_decode64(state.str, strlen(state.str),
		    *line, len, linelen);
  if (r != SASL_OK)
      return STAT_NO;

  if (yylex(&state, obj->pin)!=EOL)
      return STAT_NO;

  return STAT_CONT;
}
示例#16
0
static void
handle_connection(connection_state_t* conn_state)
{
    if (conn_state->state == STATE_WAITING) {
        handle_request(conn_state);
    }

    if (conn_state->state == STATE_OUTPUT) {
        handle_response(conn_state);
    }
}
示例#17
0
int list_wcb(int version, struct protstream *pout,
             struct protstream *pin,isieve_listcb_t *cb ,void *rock,
             char **refer_to)
{
  lexstate_t state;
  int end=0;
  int res;
  int ret = 0;

  prot_printf(pout, "LISTSCRIPTS\r\n");
  prot_flush(pout);

  do {

    if ((res=yylex(&state, pin))==STRING)
    {
      char *str=state.str;

      if (yylex(&state, pin)==' ')
      {
          if (yylex(&state, pin)!=TOKEN_ACTIVE)
              printf("Expected ACTIVE\n");
          if (yylex(&state, pin)!=EOL)
              printf("Expected EOL\n");

          cb(str, 1, rock);
      } else {

          /* in old version we had that '*' means active script thing */
          if (version == OLD_VERSION) {

              if (str[strlen(str)-1]=='*') {
                  str[strlen(str)-1]='\0';
                  cb(str, 1, rock);
              } else {
                  cb(str, 0, rock);
              }

          } else { /* NEW_VERSION */
              /* assume it's a EOL */
              cb(str, 0, rock);
          }
      }

    } else {
        ret = handle_response(res,version,pin,refer_to,NULL);

        end=1;
    }
  } while (end==0);

  return ret;
}
示例#18
0
int post_url(char *path) {
  int result;
  HttpClient http(client);
  http.setHttpWaitForDataDelay(200);
  http.setHttpResponseTimeout(HTTP_TIMEOUT);
  http.beginRequest();

  log("POST ", path);
  wdog.feed();
  result = handle_response(http.post(acsettings.servername, acsettings.port, path, user_agent()), http);
  http.stop();
  log(result);
  return result;
}
示例#19
0
int 
main(
    int argc,
    char *argv[]) 
{
    axutil_env_t * env = NULL;
    axis2_char_t * client_home = NULL;
    axis2_char_t * endpoint_uri = NULL;
    axis2_stub_t * stub = NULL;
    axis2_char_t * symbol = NULL;
    adb_getStockQuote_t * req = NULL;
    adb_getStockQuoteResponse_t * res = NULL;
    if (argc > 1)
        
    {
        symbol = argv[1];
    }
    
    else
        
    {
        printf("\nEnter Symbol Name!");
        return -1;
    }
    endpoint_uri = "http://localhost:9090/axis2/services/StockQuoteService";
    env =
        axutil_env_create_all("codegen_sample_stock_quote.log",
                              AXIS2_LOG_LEVEL_TRACE);
    
        /* Set up deploy folder. */ 
        client_home = AXIS2_GETENV("AXIS2C_HOME");
    if (!client_home)
        client_home = "../../../deploy";
    stub =
        axis2_stub_create_StockQuoteService(env, client_home, endpoint_uri);
    
        /* Create the struct */ 
        req = adb_getStockQuote_create(env);
    adb_getStockQuote_set_symbol(req, env, symbol);
    res = axis2_stub_op_StockQuoteService_getStockQuote(stub, env, req);
    if (!res)
        
    {
        printf("Error: response NULL!\n");
        return -1;
    }
    handle_response(res, env);    /*Handle Response */
    return 0;
}
示例#20
0
/**
  * @brief  Tcp client disconnect success callback function.
  * @param  arg: contain the ip link information
  * @retval None
  */
void ICACHE_FLASH_ATTR
get_version_disconnect_cb(void *arg)
{
  struct espconn *pespconn = arg;
  INFO("FOTA Client: Disconnect\n");
  clear_espconn(pespconn);
  fota_client_t *fota_client = (fota_client_t *)pespconn->reverse;

  handle_response(fota_client);

  if (fota_client->status != FOTA_GETTING_FIRMWARE)
    fota_client->status = FOTA_IDLE;

  get_version_body_len = -1;
}
示例#21
0
message::product_summary client::get_product(id_t supermarket_id, const std::string &product_identifier)
{
	try
	{
		d->feed(handle_response(dl.fetch(basepath + "/get_product/" + boost::lexical_cast<std::string>(supermarket_id) + "/" + product_identifier + formatstr)));
		auto result(deserialize<message::product_summary>(d, "product_summary"));
		return result;
	}
	catch( ... )
	{
		d.reset(new msgpack_deserializer()); // State uncertain; flush
	}

	throw std::runtime_error("Did not receive valid response");
}
示例#22
0
int Write(char* msg,int size){
//	printf("Goes in write function\n");
	struct TCP_header * tcph = (struct TCP_header *) (datagram + sizeof(struct ip));
	char* data = datagram + sizeof(struct iphdr) + sizeof(struct TCP_header);	
	int sendbytes = 0;
	int rcvlen,count = 0;
	tcph->offset = 0;
	tcph->doff = 5;
	tcph->fin = 0;
	tcph->syn = 0;
	tcph->rst = 0;
	tcph->psh = 1;
	tcph->ack = 1;
	tcph->urg = 0;
	tcph->ece = 0;
	tcph->cwr = 0;
	tcph->urg_ptr = 0;
	memcpy(data,msg,size);
	sendbytes = strlen(data);
//	printf("data is \n%s\n,data size is %d\n",data,sendbytes);
	sendbytes = sizeof(struct TCP_header);
//	strcpy(data,buf);
	iph->tot_len = sizeof(struct iphdr) + sizeof(struct TCP_header)  + size;
	tcph->seq = seqNum;
	tcph->ack_seq = ackNum; 
	tcph->check = 0;
	tcph->check = tcp_csum(send_addr,tcph,size,srcaddr);
	do{
	count++;
	if(count > 5){
		perror("duplicate ACKs, program gonna quit\n");
		exit(0);
	}	
	if(sendto(sock2send,datagram,iph->tot_len, 0, (struct sockaddr *)&send_addr, sizeof(send_addr)) < 0) 
	{
		perror("sendto failed");
	}
	if((rcvlen = recv(sock2recv,buf,iph->tot_len,0)) < 0){
		perror("recv failed");
	} else 
	{
		handle_response();
//		printf("Write successfully\n"); 
	}
	}while(not_correct_seq(buf,ackNum) || !recv_flag_contains(ACK,buf));
	seqNum = htonl(ntohl(seqNum) + size);

}
示例#23
0
reference<data::tag> client::find_add_tag(message::tag const& tag)
{
	std::string response = handle_response(post(s, dl, basepath + "/find_add_tag" + formatstr, "tag", tag, stok));
	try
	{
		d->feed(response);
		return deserialize<reference<data::tag>>(d, "tag_id");
	}
	catch( ... )
	{
		d.reset(new msgpack_deserializer()); // State uncertain; flush
	}

	std::cerr << response << std::endl;
	throw std::runtime_error("Did not receive valid response");
}
示例#24
0
文件: msr.c 项目: 01org/ikgt-plugin
CALLBACK boolean_t ikgt_report_event_msr_write(const guest_vcpu_t *vcpu_id, uint32_t msr_id, boolean_t mon_handled)
{
	ikgt_cpu_event_info_t *cpu_event_info = NULL;
	ikgt_event_info_t *event_info = NULL;
	ikgt_guest_state_t *ikgt_guest = NULL;
	ikgt_enable_mtf_param_t handle_allow; /* pass necessary params to handle_response() */
	boolean_t status = FALSE;
	ikgt_guest_cpu_state_t *ikgt_guest_cpu = NULL;

	ikgt_guest = find_guest_state(vcpu_id->guest_id);
	MON_ASSERT(ikgt_guest);
	ikgt_guest_cpu = ikgt_guest->gcpu_state[vcpu_id->guest_cpu_id];
	MON_ASSERT(ikgt_guest_cpu);

	/* setup event info to call handler */
	event_info = &(ikgt_guest_cpu->p_event_info_handler);
	cpu_event_info = &(ikgt_guest_cpu->ikgt_event_specific_info.cpu_event_handler);

	build_event_info(vcpu_id,
		event_info,
		cpu_event_info,
		IKGT_CPU_EVENT_OP_MSR,
		IKGT_CPU_EVENT_DIRN_DST,
		IKGT_CPU_REG_MSR,
		(ikgt_cpu_reg_t)0,
		0,
		IKGT_EVENT_TYPE_CPU);
	/* Save original RIP before handler processing */
	save_old_guest_rip(vcpu_id);

	if (g_ikgt_event_handlers.cpu_event_handler)
		g_ikgt_event_handlers.cpu_event_handler(event_info);

	/* Expected valid responses */
	MON_ASSERT(IKGT_EVENT_RESPONSE_ALLOW == event_info->response ||
		IKGT_EVENT_RESPONSE_REDIRECT == event_info->response ||
		IKGT_EVENT_RESPONSE_EXCEPTION == event_info->response);


	handle_allow.mtf_type = IKGT_MTF_TYPE_MSR_ACCESS;
	handle_allow.msr_id = msr_id;

	status = handle_response(vcpu_id, event_info, &handle_allow);

	return !status;
}
示例#25
0
static int
blacklist_plugin(TSCont contp, TSEvent event, void *edata)
{
  TSHttpTxn txnp = (TSHttpTxn)edata;

  switch (event) {
  case TS_EVENT_HTTP_OS_DNS:
    handle_dns(txnp, contp);
    return 0;
  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
    handle_response(txnp);
    return 0;
  default:
    break;
  }
  return 0;
}
示例#26
0
int main(int argc, char *argv[]) {
    handle_ctrl_c();

    parse_arguments_and_flags(argc, argv);
    parseURL();

    printf("started with host: %s, page: %s ... \n", host,page);

    create_socket();

    connect_to_server();
    send_request();

    handle_response();

    close(sock);
    exit(EXIT_SUCCESS);
}
示例#27
0
enum crmd_fsa_input
handle_message(xmlNode * msg)
{
    const char *type = NULL;

    CRM_CHECK(msg != NULL, return I_NULL);

    type = crm_element_value(msg, F_CRM_MSG_TYPE);
    if (crm_str_eq(type, XML_ATTR_REQUEST, TRUE)) {
        return handle_request(msg);

    } else if (crm_str_eq(type, XML_ATTR_RESPONSE, TRUE)) {
        handle_response(msg);
        return I_NULL;
    }

    crm_err("Unknown message type: %s", type);
    return I_NULL;
}
示例#28
0
/*----------------------------------------------------------------------------*/
  void 
  handle_packet(packet_t* p)
  {
    
    if (p->info.rssi >= conf.rssi_min && p->header.net == conf.my_net){
      if (p->header.typ == BEACON){
        PRINTF("[PHD]: Beacon\n");
        handle_beacon(p);
      } else {
        if (is_my_address(&(p->header.nxh))){
          switch (p->header.typ){
            case DATA:
            PRINTF("[PHD]: Data\n");
            handle_data(p);
            break;

            case RESPONSE:
            PRINTF("[PHD]: Response\n");
            handle_response(p);
            break;

            case OPEN_PATH:
            PRINTF("[PHD]: Open Path\n");
            handle_open_path(p);
            break;

            case CONFIG:
            PRINTF("[PHD]: Config\n");
            handle_config(p);
            break;

            default:
            PRINTF("[PHD]: Request/Report\n");
            handle_report(p);
            break;
          }
        }
      }
    } else {
      packet_deallocate(p);
    }
  }
示例#29
0
文件: peer.c 项目: andrey-str/ccnet
static void
handle_packet (ccnet_packet *packet, CcnetPeer *peer)
{
    switch (packet->header.type) {
    case CCNET_MSG_REQUEST:
        handle_request (peer, packet->header.id, 
                       packet->data, packet->header.length);
        break;
    case CCNET_MSG_RESPONSE:
        handle_response (peer, packet->header.id, 
                        packet->data, packet->header.length);
        break;
    case CCNET_MSG_UPDATE:
        handle_update (peer, packet->header.id, 
                      packet->data, packet->header.length);
        break;
    default: 
        ccnet_warning ("Unknown header type %d\n", packet->header.type);
    };
}
示例#30
0
void client::bind_tag(reference<data::tag> tag_id, reference<data::supermarket> supermarket_id, std::string const& product_identifier)
{
	std::string response = handle_response(get(dl, basepath + "/bind_tag/" + boost::lexical_cast<std::string>(tag_id) + "/" + boost::lexical_cast<std::string>(supermarket_id) + "/" + product_identifier + formatstr, stok));
	try
	{
		d->feed(response);
		std::string result;
		d->read_object("response");
		d->read("status", result);

		if(result == "done")
			return;
	}
	catch( ... )
	{
		d.reset(new msgpack_deserializer()); // State uncertain; flush
	}

	std::cerr << response << std::endl;
	throw std::runtime_error("Did not receive valid response");
}