Exemplo n.º 1
0
int rx_replen(const gcstring& rep, Rxpart* subs)
	{
	int nr = rep.size();
	if (rep[0] == '\\' && rep[1] == '=')
		return nr - 2;

	int len = 0;
	for (int i = 0; i < nr; ++i)
		{
		char c = rep[i];
		if (c == '&')
			{
			if (subs->n > 0)
				len += subs[0].n;
			}
		else if ('\\' == c && i + 1 < nr)
			{
			c = rep[++i];
			if (RxCompile::digit->matches(c))
				{
				if (subs[c - '0'].n > 0)
					len += subs[c - '0'].n;
				}
			else if (c != 'u' && c != 'l' && c != 'U' && c != 'L' && c != 'E')
				++len;
			}
		else
			++len;
		}
	return len;
	}
Exemplo n.º 2
0
int load_table(const gcstring& table)
	{
	const size_t bufsize = 8000;
	char buf[bufsize];
	IstreamFile fin((table + ".su").str(), "rb");
	if (!fin)
		except("can't open " << table << ".su");
	fin.getline(buf, bufsize);
	if (!has_prefix(buf, "Suneido dump 1"))
		except("invalid file");

	char* buf2 = buf + table.size() + 1;
	fin.getline(buf2, bufsize);
	verify(0 == memcmp(buf2, "======", 6));
	memcpy(buf, "create ", 7);
	memcpy(buf + 7, table.ptr(), table.size());
	Loading loading;
	int n = load1(fin, buf);
	verify(!alerts);
	return n;
	}
Exemplo n.º 3
0
bool is_old_date(const gcstring& s)
	{
	if (s.size() != 9)
		return false;
	const unsigned char* p = (const unsigned char*) s.buf();
	if (*p != PACK_DATE)
		return false;
	++p;

	if (p[0] == 0 && p[1] < 32)
		return false; // new format already
	return true;
	}
/**
 * @param num_bytes The number of bytes to send, currently, this is also the number of packets to send (we sent one data byte per packet)
 *
 */
void tahoe_active_to_passive_big_chunks(int protocol, gcstring message) {
    AddressPort to_connect("127.0.0.1", 5002);

    pthread_t t;
    struct var v;
    Timer timer;
    int client;
    int result;

    v.sem_ = new Semaphore();
    v.flag_ = new Semaphore();
    v.done_ = new Semaphore();
    v.sem_->init(0);
    v.flag_->init(0);
    v.done_->init(0);
    v.to_bind_ = new AddressPort("127.0.0.1", 5002);
    v.protocol_ = protocol;

    //Specify the number of bytes to send here.
    v.expected_string = message;

    if (pthread_create(&(t), NULL, &tahoe_active_to_passive_big_chunks_thread, &(v)) != 0) {
        FAIL() << "Error creating new thread in IntegrationTest.h";
    }

    // ensure all variables are copied
    v.sem_->wait();

    // ensure we are in accept
    usleep(50000);

    // Create client
    timer.start();
    client = wifu_socket(AF_INET, SOCK_STREAM, protocol);
    result = wifu_connect(client, (const struct sockaddr *) to_connect.get_network_struct_ptr(), sizeof (struct sockaddr_in));
    timer.stop();
    ASSERT_EQ(0, result);

    v.flag_->wait();

    cout << "Duration (us) to create a socket and connect on localhost via wifu: " << timer.get_duration_microseconds() << endl;

    int index = 0;
    int chunk = 10000;
    int num_sent = 0;


    Timer send_timer;
    send_timer.start();

    while (index < message.length()) {

        if (index + chunk > message.length()) {
            chunk = message.length() - index;
        }
        const char* data = message.data() + index;

        int sent = wifu_send(client, data, chunk, 0);
        num_sent += sent;
        index += sent;
    }
    send_timer.stop();
    cout << "Duration (us) to send: " << message.size() << " bytes on localhost: " << send_timer.get_duration_microseconds() << endl;

    EXPECT_EQ(message.length(), num_sent);
    wifu_close(client);
    assert(v.done_);
    v.done_->wait();
}
Exemplo n.º 5
0
void Md5::update(gcstring s)
	{
	if (! CryptHashData(hHash, (BYTE*) s.ptr(), s.size(), 0))
		except("Md5: CryptHashData failed");
	}
Exemplo n.º 6
0
void SuAdler32::update(const gcstring& s)
	{
	value = checksum(value, s.ptr(), s.size());
	}