Пример #1
0
void network_status(){
	dhcp_pair *pair = NULL;
	pair = (dhcp_pair *) malloc(sizeof(dhcp_pair));
	memset(pair, 0, sizeof(dhcp_pair));
	
	// Read from /tmp/wista.txt or from command to get mac link to server
	read_wlan_client(pair);
	
	// Form json to get ip
	char *json = form_request_json(pair);
	
	// Send Request
	char response[4096];
	int resp_len;
	memset(response, 0, sizeof(response));
	
	//send_request("192.168.48.1", PORT, "/dhcplease", json, strlen(json), response, resp_len);
	send_request("127.0.0.1", PORT, "/dhcplease", json, strlen(json), response, resp_len);
	
	//printf("response[%d]=[%s]\n", resp_len, response);
	char *p = strstr(response, "\r\n\r\n");
	if (p) {
		parse_response_json(p+strlen("\r\n\r\n"), pair);
	}
	
	result_array ret[64];
	memset(&ret, 0, sizeof(ret));
	
	int i=0;
	for(i=0; i<pair->length; i++) {
		//printf("mac[%d]=%s\n", i, pair->value[i].mac);
		//printf(" ip[%d]=%s\n", i, pair->value[i].ip);
		ret[i] = network_delay(pair->value[i].ip);
		int j=0;
		for (j=0; j< PKT_LEN; j++)
		printf("ip[%s]-max[%f]-min[%f]-avg[%f]\n", pair->value[i].ip,
			ret[i].icmp[j].max, ret[i].icmp[j].min, ret[i].icmp[j].avg);
	}
	
	//TODO: No json defined
	//Form json post to magicwifi
	//Send request to magicwifi
}
Пример #2
0
/*
 * Interpret - Read and pass GET request for client
 */
int interpret(int client) {
  struct HTTP_Request req;
  char buf[BUFSIZE];
  char current[BUFSIZE];
  char 	resp[BUFSIZE];

  int read_len = 0;
  int len = 0;
  int rv;
  
  fd_set set;
  FD_ZERO(&set);
  FD_SET(client, &set);
  
  struct timeval timeout;
  timeout.tv_sec = 10;
  
    while ((rv = select(client + 1, &set, NULL, NULL, &timeout)) > 0) {
      /* Read input from user */
      read_len = recv(client, &buf[len], (BUFSIZE-len), 0);
      /* Finish request if buf is empty */
      if (strlen(buf) == 0) {
	  printf("BUF IS EMPTY\n");
	  break;
      }
    
    /* Overwrite trailing new line */
    buf[read_len-1] = '\0';
          
    strcpy(req.site, "192.168.2.1");
    printf("'%s'\n", buf);
    strcpy(req.full_req, buf);
    req.port = 22;
	if (send_request(client, req) < 0) {
	    errexit("echo write: %s\n", strerror(errno));
	}
    
    }
  
  printf("Exiting\n");

  return 0;
}
Пример #3
0
/*
 * Fetch the specified header fields, ie. BODY[HEADER.FIELDS (<fields>)], of
 * the messages.
 */
int
request_fetchfields(session *ssn, const char *mesg, const char *headerfields,
    char **fields, size_t *len)
{
	int t, r;

	{
		int n = strlen("BODY.PEEK[HEADER.FIELDS ()]") +
		    strlen(headerfields) + 1;
		char f[n];

		snprintf(f, n, "%s%s%s", "BODY.PEEK[HEADER.FIELDS (",
		    headerfields, ")]");
		TRY(t = send_request(ssn, "UID FETCH %s %s", mesg, f));
	}
	TRY(r = response_fetchbody(ssn, t, fields, len));

	return r;
}
Пример #4
0
static void music_button_toggled (GtkWidget *widget, gpointer data)
{
	MMConversation *mmconv = mmconv_from_conv(((MMConversation *) data)->conv);
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
    {
		if (((MMConversation *) data)->requested)
		{
			start_session(mmconv);
			send_request_confirmed(mmconv);
		}
		else
		{
			((MMConversation *) data)->originator = TRUE;
			send_request((MMConversation *) data);
		}
    } else {
		session_end((MMConversation *)data);
    }
}
Пример #5
0
/* connects to a host on a specified port, sends a string, and gets a
   response */
int
process_request (const char *server_address, int server_port, int proto,
	const char *send_buffer, char *recv_buffer, int recv_size)
{
	int result;
	int sd;

	result = STATE_OK;

	result = np_net_connect (server_address, server_port, &sd, proto);
	if (result != STATE_OK)
		return STATE_CRITICAL;

	result = send_request (sd, proto, send_buffer, recv_buffer, recv_size);

	close (sd);

	return result;
}
Пример #6
0
static int
dlbindreq(int fd, bpf_u_int32 sap, char *ebuf)
{

	dl_bind_req_t	req;

	memset((char *)&req, 0, sizeof(req));
	req.dl_primitive = DL_BIND_REQ;
	/* XXX - what if neither of these are defined? */
#if defined(DL_HP_RAWDLS)
	req.dl_max_conind = 1;			/* XXX magic number */
	req.dl_service_mode = DL_HP_RAWDLS;
#elif defined(DL_CLDLS)
	req.dl_service_mode = DL_CLDLS;
#endif
	req.dl_sap = sap;

	return (send_request(fd, (char *)&req, sizeof(req), "bind", ebuf));
}
Пример #7
0
void ClientParser::read(std::vector<std::string> commands) {

  if( commands.size() != 2 ) {
    std::cout << "Error: Bad read params" << std::endl;
    return;
  }

  // Get User
  auto user = commands.front();

  // Get Index
  int index = safe_stoi( commands.at(1) );

  if( index < 1 ) {
    std::cout << "Error: Bad read params" << std::endl;
    return;
  }


  // Send Request
  auto client = Client::get_instance();

  bool status = client->send_request( Request::get( user, index ) );

  if( !status ) {
    std::cout << "Error: Request could not send to the server!";
  }

  // Read Request
  auto response = client->read_until('\n');

  if( is_error(response) ) {
    std::cout << response;
    return;
  }

  std::cout << utils::split( response ).at(1) << std::endl;

  int byte_count = std::stoi( utils::split( response ).back() );

  std::cout << client->read_for( byte_count ) << std::endl;

}
Пример #8
0
JsonArray *
gs_snapd_list (const gchar *macaroon, gchar **discharges,
               GCancellable *cancellable, GError **error)
{
    guint status_code;
    g_autofree gchar *reason_phrase = NULL;
    g_autofree gchar *response_type = NULL;
    g_autofree gchar *response = NULL;
    g_autoptr(JsonParser) parser = NULL;
    JsonObject *root;
    JsonArray *result;

    if (!send_request ("GET", "/v2/snaps", NULL,
                       macaroon, discharges,
                       &status_code, &reason_phrase,
                       &response_type, &response, NULL,
                       cancellable, error))
        return NULL;

    if (status_code != SOUP_STATUS_OK) {
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_FAILED,
                     "snapd returned status code %u: %s",
                     status_code, reason_phrase);
        return NULL;
    }

    parser = parse_result (response, response_type, error);
    if (parser == NULL)
        return NULL;
    root = json_node_get_object (json_parser_get_root (parser));
    result = json_object_get_array_member (root, "result");
    if (result == NULL) {
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_FAILED,
                     "snapd returned no result");
        return NULL;
    }

    return json_array_ref (result);
}
void send_hostsstartendupdate(connection_t *c, int start) {
	char rawhost[MAX_STRING_SIZE];
	char rawdgst[MAX_STRING_SIZE], b64dgst[MAX_STRING_SIZE];
	size_t slen, dlen, rlen;
	bool choice = false;

	/* test if we're are authorized to broadcast the data */
	if(!get_config_bool(lookup_config(config_tree, "HostsFilesMaster"), &choice)) return;
	if(!choice) return;

	/* bootstrapped node? If we're already sent him updates, do not do that again */
	if(c->node && c->node->sentupdates) return;

	/* Start update session */
	dlen = RSA_size(myself->connection->rsa_key);
	if (dlen > sizeof(rawdgst)/2) {
		logger(LOG_ERR, "Could not %s hosts update session due to digest overflow",
		start ? "start" : "end");

		return;
	}

	snprintf(rawhost, sizeof(rawhost), "%s %s %s 0 %zd",
		myself->name, myself->name, start ? "START" : "END", dlen);
	rlen = strlen(rawhost);
	if (!EVP_sign(myself->connection->rsa_key, rawhost, rlen, rawdgst, &dlen)) {
		logger(LOG_ERR,
		"Could not %s hosts update session due to signing error (probably OOM)",
		start ? "start" : "end");

		return;
	}
	if (base64_enclen(dlen) >= MAX_STRING_SIZE) {
		logger(LOG_ERR,
		"Could not %s hosts update session, base64 digest overflow",
		start ? "start" : "end");

		return;
	}
	base64_encode(rawdgst, dlen, b64dgst, sizeof(b64dgst)-1);
	send_request(c, "%d %s %s", HOSTUPDATE, rawhost, b64dgst);
}
Пример #10
0
void
check_interfaces(void)
{
    struct interface *ifp;
    int rc, ifindex_changed = 0;
    unsigned int ifindex;

    FOR_ALL_INTERFACES(ifp) {
        ifindex = if_nametoindex(ifp->name);
        if(ifindex != ifp->ifindex) {
            debugf("Noticed ifindex change for %s.\n", ifp->name);
            ifp->ifindex = 0;
            interface_up(ifp, 0);
            ifp->ifindex = ifindex;
            ifindex_changed = 1;
        }

        if(ifp->ifindex > 0)
            rc = kernel_interface_operational(ifp->name, ifp->ifindex);
        else
            rc = 0;
        if((rc > 0) != if_up(ifp)) {
            debugf("Noticed status change for %s.\n", ifp->name);
            interface_up(ifp, rc > 0);
        }

        if(if_up(ifp)) {
            /* Bother, said Pooh.  We should probably check for a change
               in IPv4 addresses at this point. */
            check_link_local_addresses(ifp);
            check_interface_channel(ifp);
            rc = check_interface_ipv4(ifp);
            if(rc > 0) {
                send_request(ifp, NULL, 0, NULL, 0);
                send_update(ifp, 0, NULL, 0, NULL, 0);
            }
        }
    }

    if(ifindex_changed)
        renumber_filters();
}
Пример #11
0
Файл: epoll.c Проект: DevL/ponyc
void asio_event_unsubscribe(asio_event_t* ev)
{
  if((ev == NULL) ||
    (ev->flags == ASIO_DISPOSABLE) ||
    (ev->flags == ASIO_DESTROYED))
    return;

  asio_backend_t* b = asio_get_backend();

  if(ev->noisy)
  {
    asio_noisy_remove();
    ev->noisy = false;
  }

  epoll_ctl(b->epfd, EPOLL_CTL_DEL, ev->fd, NULL);

  if(ev->flags & ASIO_TIMER)
  {
    if(ev->fd != -1)
    {
      close(ev->fd);
      ev->fd = -1;
    }
  }

  if(ev->flags & ASIO_SIGNAL)
  {
    int sig = (int)ev->nsec;
    asio_event_t* prev = ev;

    if((sig < MAX_SIGNAL) && _atomic_cas(&b->sighandlers[sig], &prev, NULL))
    {
      signal(sig, SIG_DFL);
      close(ev->fd);
      ev->fd = -1;
    }
  }

  ev->flags = ASIO_DISPOSABLE;
  send_request(ev, ASIO_DISPOSABLE);
}
Пример #12
0
/**
 * This method is called from the client to start an RPC call.
 * @param transport Transport implementation
 * @param client Client
 * @param method_desc Method descriptor
 * @return Returns LWPB_ERR_OK if successful.
 */
static lwpb_err_t transport_call(lwpb_transport_t transport,
                                 struct lwpb_client *client,
                                 const struct lwpb_method_desc *method_desc)
{
    struct lwpb_transport_socket_client *socket_client =
        (struct lwpb_transport_socket_client *) transport;
    lwpb_err_t ret = LWPB_ERR_OK;
    void *req_buf = NULL;
    size_t req_len;
    
    // Only continue if connected to server
    if (socket_client->socket == -1) {
        client->done_handler(client, method_desc,
                             LWPB_RPC_NOT_CONNECTED, client->arg);
        goto out;
    }
    
    // Allocate a buffer for the request message
    ret = lwpb_transport_alloc_buf(transport, &req_buf, &req_len);
    if (ret != LWPB_ERR_OK)
        goto out;
    
    // Encode the request message
    ret = client->request_handler(client, method_desc, method_desc->req_desc,
                                  req_buf, &req_len, client->arg);
    if (ret != LWPB_ERR_OK)
        goto out;

    
    socket_client->last_method = method_desc;
    
    // Send the request to the server
    // TODO check result
    send_request(socket_client->socket, method_desc, req_buf, req_len);
    
out:
    // Free allocated requiest message buffer
    if (req_buf)
        lwpb_transport_free_buf(transport, req_buf);
    
    return ret;
}
Пример #13
0
static int
authenticate_with_cookie(IPC_Channel *chan, cl_uuid_t *cookie) 
{
	struct ha_msg *	request;
	struct ha_msg * reply;

	assert(chan != NULL);
	assert(cookie != NULL);

	if (!(request = create_basic_reqmsg_fields(ST_SIGNON))) {
		return ST_FAIL;
	}
	if (ha_msg_adduuid(request, F_STONITHD_COOKIE, cookie) != HA_OK) {
		stdlib_log(LOG_ERR, "cannot add field to ha_msg.");
		ZAPMSG(request);
		return ST_FAIL;
	}

	/* Send request/read response */
	if (send_request(chan, request, DEFAULT_TIMEOUT) != ST_OK) {
		ZAPMSG(request);
		return ST_FAIL;
	}
	ZAPMSG(request);

	if (!(reply = recv_response(chan, DEFAULT_TIMEOUT))) {
		return ST_FAIL;
	}
	
	/* Are we signed on this time? */
	if ( TRUE == is_expected_msg(reply, F_STONITHD_TYPE, ST_APIRPL, 
			     F_STONITHD_APIRPL, ST_RSIGNON, TRUE) ) {
		if ( !STRNCMP_CONST(
			cl_get_string(reply,F_STONITHD_APIRET), ST_APIOK) ) {
			ZAPMSG(reply);
			return ST_OK;
		}
	}

	ZAPMSG(reply);
	return ST_FAIL;
}
Пример #14
0
int main()
{
	fd_set rfds;
	struct timeval tv;
	int sock;
	uint32_t xid;

	sock = init_socket();
	xid = send_request(sock);

	FD_ZERO(&rfds);
	FD_SET(sock, &rfds);
	tv.tv_sec = 5;
	tv.tv_usec = 0;
	if (select(sock + 1, &rfds, NULL, NULL, &tv) == 1 && FD_ISSET(sock, &rfds))
		get_reply(sock, xid);

	close(sock);
	exit(1);
}
Пример #15
0
int 
socket_server_listen(struct socket_server *ss, const char * addr, int port, int backlog) {
	struct request_package request;
	int len = (addr!=NULL) ? strlen(addr) : 0;
	if (len + sizeof(request.u.listen) > sizeof(request.u)) {
		fprintf(stderr, "socket-server : Invalid listen addr %s.\n",addr);
		return 0;
	}
	int session = allocsession(ss);
	request.u.listen.session = session;
	request.u.listen.port = port;
	request.u.listen.backlog = backlog;
	if (len == 0) {
		request.u.listen.host[0] = '\0';
	} else {
		strcpy(request.u.listen.host, addr);
	}
	send_request(ss, &request, 'L', sizeof(request.u.listen) + len);
	return session;
}
Пример #16
0
Файл: main.c Проект: naaf/Master
void *run_chat(void *arg) {
	char entree[512];
	memset(entree, 0, sizeof(entree));

	/*--------------Blocquer les signaux------------------*/
	sigset_t mask;
	sigfillset(&mask);
	pthread_sigmask(SIG_SETMASK, &mask, NULL);

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	while (TRUE) {
		printf("entrez votre msg : ");
		fflush(stdout);
		read_response(STDIN_FILENO, entree);
//		printf("envois : %s", entree);
		send_request(sc, 3, CHAT, myName, entree);
		memset(entree, 0, strlen(entree) + 2);
	}
	return NULL;
}
Пример #17
0
static void
write_buf_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
  GOutputStream *output = G_OUTPUT_STREAM (object);
  GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (user_data);
  GVfsAfpConnectionPrivate *priv = afp_conn->priv;

  RequestData *req_data;

  req_data = g_queue_peek_head (priv->request_queue);
  
  HANDLE_RES ();

  g_hash_table_insert (priv->request_hash,
                       GUINT_TO_POINTER ((guint)GUINT16_FROM_BE (priv->write_dsi_header.requestID)),
                       req_data);
  g_queue_pop_head (priv->request_queue);

  send_request (afp_conn);
}
Пример #18
0
HTTPCode HttpConnection::send_delete(const std::string& path,
                                     std::map<std::string, std::string>& headers,
                                     std::string& response,
                                     SAS::TrailId trail,
                                     const std::string& body,
                                     const std::string& username)
{
  CURL *curl = get_curl_handle();
  struct curl_slist *slist = NULL;
  slist = curl_slist_append(slist, "Expect:");

  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");

  HTTPCode status = send_request(path, body, response, username, trail, "DELETE", curl);

  curl_slist_free_all(slist);

  return status;
}
Пример #19
0
static void test_msg (flux_t h)
{
    flux_msg_handler_t *w;
    int i;

    ok ((w = flux_msg_handler_create (h, FLUX_MATCH_ANY, msgreader, NULL))
        != NULL,
        "msg: created handler for any message");
    flux_msg_handler_start (w);
    for (i = 0; i < msgwatcher_count; i++) {
        if (send_request (h, "foo") < 0)
            break;
    }
    ok (i == msgwatcher_count,
        "msg: sent %d requests", i);
    ok (flux_reactor_run (flux_get_reactor (h), 0) == 0,
        "msg: reactor ran to completion after %d requests", msgwatcher_count);
    flux_msg_handler_stop (w);
    flux_msg_handler_destroy (w);
}
Пример #20
0
struct p9stat *object_stat(Worker *worker, u64 oid, char *filename) {
    int i;
    Transaction *trans;
    struct Rsstat *res;
    struct p9stat *info;

    /* handle it from the cache if it exists */
    if (object_cache_isvalid(oid)) {
        info = disk_stat(worker, oid);
        info->name = filename;
        return info;
    }

    i = randInt(storage_server_count);
    trans = trans_new(storage_servers[i], NULL, message_new());

    trans->out->tag = ALLOCTAG;
    trans->out->id = TSSTAT;
    set_tsstat(trans->out, oid);

    /* send the request to one randomly chosen storage server */
    send_request(trans);

    assert(trans->in != NULL && trans->in->id == RSSTAT);
    res = &trans->in->msg.rsstat;

    /* insert the filename supplied by the caller */
    res->stat->name = filename;

    /* check if we have a cache entry with matching stats */
    if (objectroot != NULL && (info = disk_stat(worker, oid)) != NULL) {
        info->name = filename;
        info->atime = res->stat->atime;

        /* if it's up-to-date, note it as a valid entry */
        if (!p9stat_cmp(info, res->stat))
            object_cache_validate(oid);
    }

    return res->stat;
}
Пример #21
0
/* Perform a ndsctl action, with server response Yes or No.
 * Action given by cmd, followed by config.param.
 * Responses printed to stdout, as formatted by ifyes or ifno.
 * config.param interpolated in format with %s directive if desired.
 */
static void
ndsctl_action(char * cmd, char * ifyes, char * ifno) {
  int	sock;
  char	buffer[4096];
  char	request[128];
  int	len,
    rlen;

  sock = connect_to_server(config.socket);
		
  snprintf(request, sizeof(request)-strlen(NDSCTL_TERMINATOR),
	   "%s %s", cmd, config.param);
  strcat(request, NDSCTL_TERMINATOR);

  len = send_request(sock, request);
	
  len = 0;
  memset(buffer, 0, sizeof(buffer));
  while ((len < sizeof(buffer)) && ((rlen = read(sock, (buffer + len),
						 (sizeof(buffer) - len))) > 0)){
    len += rlen;
  }

  if(rlen<0) {
    fprintf(stderr, "ndsctl: Error reading socket: %s", strerror(errno));
  }


  if (strcmp(buffer, "Yes") == 0) {
    printf(ifyes, config.param);
  } else if (strcmp(buffer, "No") == 0) {
    printf(ifno, config.param);
  } else {
    fprintf(stderr, "ndsctl: Error: nodogsplash sent an abnormal "
	    "reply.\n");
  }

  shutdown(sock, 2);
  close(sock);

}
Пример #22
0
/// Mangelwurzel receives an in dialog request. It will strip off all the Via
/// headers and send the request on. It can also change the request in various
/// ways depending on the configuration in its Route header.
/// - It can mangle the dialog identifiers using its mangalgorithm.
/// - It can mangle the Request URI and Contact URI using its mangalgorithm.
/// - It can mangle the To URI using its mangalgorithm.
/// - It can edit the S-CSCF Route header to turn the request into either an
///   originating or terminating request.
/// - It can edit the S-CSCF Route header to turn the request into an out of
///   the blue request.
/// - It can mangle the Record-Route headers URIs.
void MangelwurzelTsx::on_rx_in_dialog_request(pjsip_msg* req)
{
  pj_pool_t* pool = get_pool(req);

  // Get the URI from the Route header. We use it in the SAS event logging that
  // we've received an in dialog request.
  const pjsip_route_hdr* mangelwurzel_route_hdr = route_hdr();
  pjsip_uri* mangelwurzel_uri = mangelwurzel_route_hdr->name_addr.uri;

  SAS::Event event(trail(), SASEvent::MANGELWURZEL_IN_DIALOG_REQ, 0);
  event.add_var_param(PJUtils::uri_to_string(PJSIP_URI_IN_ROUTING_HDR,
                                             mangelwurzel_uri));
  SAS::report_event(event);

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

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

  if (_config.to)
  {
    mangle_to(req, pool);
  }

  edit_scscf_route_hdr(req, pool);

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

  strip_via_hdrs(req);

  send_request(req);
}
Пример #23
0
static int make_dump_request(debugger_action_t action, pid_t tid) {
  const char* socket_name;
  debugger_msg_t msg;
  size_t msg_len;
  void* msg_ptr;

#if defined(__LP64__)
  debugger32_msg_t msg32;
  if (is32bit(tid)) {
    msg_len = sizeof(debugger32_msg_t);
    memset(&msg32, 0, msg_len);
    msg32.tid = tid;
    msg32.action = action;
    msg_ptr = &msg32;

    socket_name = DEBUGGER32_SOCKET_NAME;
  } else
#endif
  {
    msg_len = sizeof(debugger_msg_t);
    memset(&msg, 0, msg_len);
    msg.tid = tid;
    msg.action = action;
    msg_ptr = &msg;

    socket_name = DEBUGGER_SOCKET_NAME;
  }

  int sock_fd = socket_local_client(socket_name, ANDROID_SOCKET_NAMESPACE_ABSTRACT,
      SOCK_STREAM | SOCK_CLOEXEC);
  if (sock_fd < 0) {
    return -1;
  }

  if (send_request(sock_fd, msg_ptr, msg_len) < 0) {
    TEMP_FAILURE_RETRY(close(sock_fd));
    return -1;
  }

  return sock_fd;
}
Пример #24
0
static int keepalive_start (CcnetProcessor *processor, 
                            int argc, char **argv)
{
    CcnetKeepaliveProcPriv *priv = GET_PRIV (processor);

    if (IS_SLAVE(processor)) {
        char buf[16];
        int v, len;

        if (argc == 0) {
            priv->used_version = 0;
            ccnet_processor_send_response (processor,
                  SC_VERSION_MISMATCH, SS_VERSION_MISMATCH, NULL, 0);
            ccnet_processor_done (processor, FALSE);
            return 0;
        } else {
            v = get_version(argv[0]);
            if ((priv->used_version = get_used_version(v)) == -1) {
                ccnet_processor_send_response (processor,
                  SC_VERSION_MISMATCH, SS_VERSION_MISMATCH, NULL, 0);
                ccnet_processor_done (processor, FALSE);
                return 0;
            }

            len = snprintf (buf, 16, "v%d", priv->used_version);
            ccnet_processor_send_response (processor, 
                                    SC_OK, SS_OK, buf, len + 1);
            return 0;
        }
    }

    /* master */
    g_assert (processor->peer->keepalive_sending == 0);
    priv->count = 0;
    processor->state = INIT;
    processor->peer->keepalive_sending = 1;
    send_request (processor);
    reset_timeout (processor);

    return 0;
}
Пример #25
0
/* make call */
void make_call(char *uri, pj_bool_t with_offer)
{
    pj_str_t local = pj_str("sip:localhost" PORT_STR);
    pj_str_t remote = pj_str(uri);
    pj_status_t status;

    status = pjsip_dlg_create_uac(pjsip_ua_instance(),
				  &local, &local, &remote, &remote, &dlg);
    pj_assert(status == PJ_SUCCESS);

    pjsip_dlg_inc_lock(dlg);

    status = pjsip_dlg_add_usage(dlg, &mod_app, NULL);
    pj_assert(status == PJ_SUCCESS);

    pjsip_dlg_inc_session(dlg, &mod_app);

    send_request(&pjsip_invite_method, -1, NULL, with_offer);

    pjsip_dlg_dec_lock(dlg);
}
Пример #26
0
int runbasictest(char *hostname, char *username, char *password)
{
	int session_id = -1;
	char *batchid = "batchid";
	char *requests[] = { "req1", "req2", "req3"};
	char *userdata[] = { "userdata1", "userdata2", "userdata3" };

	init_client(hostname, username, password);
	session_id = create_session();
	if(session_id < 0)
	{
		fprintf(stderr, "create_session() failed\n");
		return -1;
	}
	send_request(session_id, batchid, &requests[0], &userdata[0], 3, true);
	get_response(session_id, batchid, "", "", -1, true);
	get_batchstatus(session_id, batchid);
	close_session(session_id);
	printf("BasicTest passed\n");
	return 0;
}
Пример #27
0
int socket_server::server_listen(uintptr_t opaque, const char *addr, int port, int backlog)
{
    int fd = do_listen(addr, port, backlog);
    if (fd < 0) {
        printf("do listen failed\n");
        return -1;
    }
    printf("run listen success!\n");

    struct request_package request;
    int id = reserve_id();
    if (id < 0) {
        close(fd);
        return id;
    }
    request.u.listen.opaque = opaque;
    request.u.listen.id = id;
    request.u.listen.fd = fd;
    send_request(&request, 'L', sizeof(request.u.listen));
    return id;
}
Пример #28
0
static void
connect_handler(struct ev_loop *loop, struct ev_io *watcher, int events) {

    domain_t * domain = (domain_t *) watcher;
    ev_io_stop(loop, &domain->io);
    ev_timer_stop(loop, &domain->tw);

    debug("-- connected %s", domain->domain);


    int error;
    socklen_t len = sizeof (error);
    if (getsockopt(domain->io.fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
        free_domain(domain);
        errno = error;

    } else {
        send_request(loop, domain);
    }

}
Пример #29
0
int
logout(int argc, char **argv)
{
	iscsid_sym_id_t req;
	iscsid_response_t *rsp;

	if (!cl_get_id('I', &req, argc, argv)) {
		arg_missing("Session");
	}
	check_extra_args(argc, argv);

	send_request(ISCSID_LOGOUT, sizeof(req), &req);
	rsp = get_response(FALSE);
	if (rsp->status) {
		status_error(rsp->status);
	}
	free_response(rsp);

	printf("OK\n");
	return 0;
}
    virtual bool shutdown(bool &result)
    {
        fb::FlatBufferBuilder builder;

        // Create request
        auto request = v3::CreateShutdownRequest(builder,
                                                 v3::ShutdownType_DIRECT);

        // Send request
        std::vector<unsigned char> buf;
        const v3::ShutdownResponse *response;
        if (!send_request(buf, builder, request.Union(),
                          v3::RequestType_ShutdownRequest,
                          v3::ResponseType_ShutdownResponse,
                          response)) {
            return false;
        }

        result = response->success();
        return true;
    }