static gboolean
glib_main (gpointer data)
{
	xmlDoc *doc = NULL;
	xmlNode *root_element = NULL;
	struct connection conn;
	static struct start_network_data start_network_data;


	if (!(start_network_data.client = nm_client_new()))
	{
		network_status (NULL, "Unable to connect to NetworkManager");
		g_main_loop_quit (loop);
	        return FALSE;
	}

	g_timeout_add_seconds (2, do_timeout, &start_network_data);
	start_network_data.should_quit = TRUE;

	/*parse the file and get the DOM */
	if( NULL == (doc = xmlReadFile(NETWORK_CONFIG, NULL, 0))) {
		network_status (start_network_data.client, "error: Could not parse " NETWORK_CONFIG "\n");
		g_main_loop_quit (loop);
		return FALSE;
	}

	/*Get the root element node */
	root_element = xmlDocGetRootElement(doc);
	if (root_element->type == XML_ELEMENT_NODE && !strcmp((char *)root_element->name, "configuration")) {
		gchar *err = read_connection(&conn, root_element);
		if (err) {
			gchar err2[1024];
			g_snprintf(err2, sizeof(err2), "Unable to parse configuration data: %s", err);
			network_status (start_network_data.client, err2);
			g_main_loop_quit (loop);
			return FALSE;
		}
	}
	else {
		network_status (start_network_data.client, "error: Invalid " NETWORK_CONFIG " file: No <configuration/> root node\n");
		g_main_loop_quit (loop);
		return FALSE;
	}

	xmlFreeDoc(doc);
	xmlCleanupParser();

	/* Generate the UUID from the connection information */
	generate_uuid(&conn, start_network_data.uuid, sizeof(start_network_data.uuid));


	/* Hand control over to do_connection.  Execution will continue in callbacks. */
	do_connection(&start_network_data);


	return FALSE;
}
/**
 * Convert the network_configs file to NetworkManager's keyfile
 */
int
convert_network_configs(char *filename)
{

    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;
    xmlNode *cur_node;

    /*
     * this initialize the library and check potential ABI mismatches
     * between the version it was compiled for and the actual shared
     * library used.
     */
    LIBXML_TEST_VERSION

    /*parse the file and get the DOM */
    doc = xmlReadFile(filename, NULL, 0);

    if (doc == NULL) {
        printf("error: could not parse file %s\n", filename);
        return 1;
    }

    /*Get the root element node */
    root_element = xmlDocGetRootElement(doc);
    for (cur_node = root_element->children; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE && !strcmp((char *)cur_node->name, "configuration")) {
            struct connection conn;
            read_connection(&conn, cur_node);
            write_config_file(&conn);
        }
    }


    /*free the document */
    xmlFreeDoc(doc);

    /*
     *Free the global variables that may
     *have been allocated by the parser.
     */
    xmlCleanupParser();

    return 0;
}
Esempio n. 3
0
std::vector<connection> hydrator::read_connections() {
    validate_current_element(dia_connections);
    reader_.read();

    std::vector<connection> r;
    do {
        if (!is_start_element(dia_connection)) {
            BOOST_LOG_SEV(lg, error) << unexpected_connection_type
                                     << reader_.name();
            BOOST_THROW_EXCEPTION(hydration_error(unexpected_connection_type +
                reader_.name()));
        }
        r.push_back(read_connection());
    } while (!is_end_element(dia_connections));
    reader_.read();

    BOOST_LOG_SEV(lg, debug) << "Object has " << r.size() << " connections";
    return r;
}
Esempio n. 4
0
static void run_rconnection(struct connection *cn)
{
	int n;
	short r;

	n = cn->pollno;
	if (n == -1)
		return;
	r = pollfds[n].revents;
	if (r & POLLERR || r == POLLHUP) {
		close_connection(cn);
		return;
	}
	if (r & POLLIN) {
		if (read_connection(cn) == -1 || scan_request(cn) == -1)
			return;
		r &= ~POLLIN;
		if (cn->connection_state == HC_WRITING)
			r |= POLLOUT;
		pollfds[n].revents = r;
	}
}
Esempio n. 5
0
void read_essid(DBusMessageIter * args, char *name)
{
	DBusMessageIter dict_iter, subiter;
	char str_ptr[50];
	int type = dbus_message_iter_get_arg_type(args);
	if (type != DBUS_TYPE_ARRAY) {
		return;
	}
	dbus_message_iter_recurse(args, &subiter);
	do {
		int sub_type = dbus_message_iter_get_arg_type(&subiter);
		if (sub_type != DBUS_TYPE_DICT_ENTRY)
			return;
		dbus_message_iter_recurse(&subiter, &dict_iter);
		if (dbus_message_iter_get_arg_type(&dict_iter) ==
		    DBUS_TYPE_STRING) {
			read_string(&dict_iter, str_ptr);
			if (!strcmp(str_ptr, "connection")) {
				dbus_message_iter_next(&dict_iter);
				read_connection(&dict_iter, name);
			}
		}
	} while (dbus_message_iter_next(&subiter));
}
Esempio n. 6
0
int test() 
{
  struct timeval timeout, now;
  fd_set sel_read, sel_except, sel_write;
  int i;
  
  {
    /* get server information */
    struct hostent *he;
    he = gethostbyname(machine);
    if (!he) err("gethostbyname");
    server.sin_family      = he->h_addrtype;
    server.sin_port        = htons(port);
    server.sin_addr.s_addr = ((unsigned long *)(he->h_addr_list[0]))[0];
  }

  con = malloc(concurrency*sizeof(struct connection));
  memset(con,0,concurrency*sizeof(struct connection));
  
  stats = malloc(requests * sizeof(struct data));

  FD_ZERO(&readbits);
  FD_ZERO(&writebits);

  /* setup request */
  sprintf(request,"GET %s HTTP/1.0\r\nUser-Agent: ZeusBench/1.0\r\n"
	  "%sHost: %s\r\nAccept: */*\r\n\r\n", file, 
	  keepalive?"Connection: Keep-Alive\r\n":"", machine );
    
  reqlen = strlen(request);

  /* ok - lets start */
  gettimeofday(&start,0);

  /* initialise lots of requests */
  for(i=0; i<concurrency; i++) start_connect(&con[i]);

  while(done<requests) {
    int n;
    /* setup bit arrays */
    memcpy(&sel_except, &readbits, sizeof(readbits));
    memcpy(&sel_read, &readbits, sizeof(readbits));
    memcpy(&sel_write, &writebits, sizeof(readbits));

    /* check for time limit expiry */
    gettimeofday(&now,0);
    if(tlimit && timedif(now,start) > (tlimit*1000)) {
      requests=done;   /* so stats are correct */
      output_results();
    }

    /* Timeout of 30 seconds. */
    timeout.tv_sec=30; timeout.tv_usec=0;
    n=select(256, &sel_read, &sel_write, &sel_except, &timeout);
    if(!n) {
      printf("\nServer timed out\n\n");
      exit(1);
    }
    if(n<1) err("select");

    for(i=0; i<concurrency; i++) {
      int s = con[i].fd;
      if(FD_ISSET(s, &sel_except)) {
	bad++; 
	err_except++;
	start_connect(&con[i]);
	continue;
      }
      if(FD_ISSET(s, &sel_read)) read_connection(&con[i]);
      if(FD_ISSET(s, &sel_write)) write_request(&con[i]);
    }
    if(done>=requests) output_results();
  }
  return 0;
}
Esempio n. 7
0
static void
test(struct global * registry) {
    struct timeval timeout, now;
    fd_set sel_read, sel_except, sel_write;
    int i;

    registry->con = calloc(registry->concurrency, sizeof(struct connection));
    memset(registry->con, 0, registry->concurrency * sizeof(struct connection));

#ifdef AB_DEBUG
    printf("AB_DEBUG: start of test()\n");
#endif

    for (i = 0; i < registry->concurrency; i++) {
        registry->con[i].url = registry->ready_to_run_queue[i].url;
        registry->con[i].run = registry->ready_to_run_queue[i].run;
        registry->con[i].state = STATE_READY;
        registry->con[i].thread = registry->ready_to_run_queue[i].thread;
    }

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 1\n");
#endif

    registry->stats = calloc(registry->number_of_urls, sizeof(struct data *));
    for (i = 0; i < registry->number_of_runs; i++) {
        int j;
        for (j = registry->position[i]; j < registry->position[i+1]; j++)
            registry->stats[j] = calloc(registry->repeats[i], sizeof(struct data));
    }

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 2\n");
#endif

    FD_ZERO(&registry->readbits);
    FD_ZERO(&registry->writebits);

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 3\n");
#endif

    /* ok - lets start */
    gettimeofday(&registry->starttime, 0);

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 4\n");
#endif

    /* initialise lots of requests */

    registry->head = registry->concurrency;
    for (i = 0; i < registry->concurrency; i++)
        start_connect(registry, &registry->con[i]);

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 5\n");
#endif

    while (registry->done < registry->need_to_be_done) {
        int n;

#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.1, registry->done = %d\n", registry->done);
#endif

        /* setup bit arrays */
        memcpy(&sel_except, &registry->readbits, sizeof(registry->readbits));
        memcpy(&sel_read, &registry->readbits, sizeof(registry->readbits));
        memcpy(&sel_write, &registry->writebits, sizeof(registry->writebits));

#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.2, registry->done = %d\n", registry->done);
#endif

        /* Timeout of 30 seconds, or minimum time limit specified by config. */
        timeout.tv_sec = registry->min_tlimit.tv_sec;
        timeout.tv_usec = registry->min_tlimit.tv_usec;
        n = select(FD_SETSIZE, &sel_read, &sel_write, &sel_except, &timeout);
#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.3, registry->done = %d\n", registry->done);
#endif
        if (!n)
            myerr(registry->warn_and_error, "Server timed out");
        if (n < 1)
            myerr(registry->warn_and_error, "Select error.");
#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.4, registry->done = %d\n", registry->done);
#endif
        /* check for time limit expiry */
        gettimeofday(&now, 0);
        if (registry->tlimit &&
            timedif(now, registry->starttime) > (registry->tlimit * 1000)) {
            char *warn = malloc(256 * sizeof(char));
            sprintf(warn, "Global time limit reached (%.2f sec), premature exit", registry->tlimit);
            myerr(registry->warn_and_error, warn);
            free(warn);
            registry->need_to_be_done = registry->done;        /* break out of loop */
        }

        for (i = 0; i < registry->concurrency; i++) {
            int s = registry->con[i].fd;
#ifdef AB_DEBUG
            printf("AB_DEBUG: test() - stage 5.5, registry->done = %d, i = %d\n", registry->done, i);
#endif
            if (registry->started[registry->con[i].url]
                > registry->finished[registry->con[i].url]) {
                struct connection * c = &registry->con[i];
                struct timeval url_now;

                /* check for per-url time limit expiry */
                gettimeofday(&url_now, 0);

#ifdef AB_DEBUG
                printf("AB_DEBUG: test() - stage 5.5.4, Time taken for current request = %d ms; Per-url time limit = %.4f sec; for run %d, url %d\n", timedif(url_now, c->start_time), registry->url_tlimit[c->url], c->run, c->url - registry->position[c->run]);
                printf("AB_DEBUG: test() - stage 5.5.5, registry->done = %d, i = %d\n", registry->done, i);
#endif
                if (registry->url_tlimit[c->url] &&
                    timedif(url_now, c->start_time) > (registry->url_tlimit[c->url] * 1000)) {
                    char *warn = malloc(256 * sizeof(char));
#ifdef AB_DEBUG
                    printf("AB_DEBUG: test() - stage 5.5.5.3, registry->done = %d, i = %d\n", registry->done, i);
#endif
                    sprintf(warn, "Per-url time limit reached (%.3f sec) for run %d, url %d, iteration %d; connection closed prematurely", registry->url_tlimit[c->url], c->run, c->url - registry->position[c->run], c->thread);
                    myerr(registry->warn_and_error, warn);
                    free(warn);

                    registry->failed[c->url]++;
                    close_connection(registry, c);
                    continue;
                }
            }

            if (registry->con[i].state == STATE_DONE)
                continue;
#ifdef AB_DEBUG
            printf("AB_DEBUG: test() - stage 5.6, registry->done = %d, i = %d\n", registry->done, i);
#endif
            if (FD_ISSET(s, &sel_except)) {
                registry->failed[registry->con[i].url]++;
                start_connect(registry, &registry->con[i]);
                continue;
            }
#ifdef AB_DEBUG
            printf("AB_DEBUG: test() - stage 5.7, registry->done = %d, i = %d\n", registry->done, i);
#endif
            if (FD_ISSET(s, &sel_read)) {
                read_connection(registry, &registry->con[i]);
                continue;
            }
#ifdef AB_DEBUG
            printf("AB_DEBUG: test() - stage 5.8, registry->done = %d, i = %d\n", registry->done, i);
#endif
            if (FD_ISSET(s, &sel_write))
                write_request(registry, &registry->con[i]);        
#ifdef AB_DEBUG
            printf("AB_DEBUG: test() - stage 5.9, registry->done = %d, i = %d\n", registry->done, i);
#endif
        }
    }

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 6\n");
#endif

    gettimeofday(&registry->endtime, 0);
    if (strlen(registry->warn_and_error) == 28)
        myerr(registry->warn_and_error, "None.\n");
    else myerr(registry->warn_and_error, "Done.\n");
}