Esempio n. 1
0
void old_to_new_date(gcstring& s)
	{
	if (! is_old_date(s))
		return ;
	const unsigned char* p = (unsigned char*) s.buf() + 1;
	DateTime dt = unpack_old_datetime(p);
	SuDate sudt(dt.date(), dt.time());
	sudt.pack(s.buf());
	}
Esempio n. 2
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;
	}
Esempio n. 3
0
static int load1(Istream& fin, gcstring tblspec)
	{
	int n = tblspec.find(' ', 7);
	gcstring table = tblspec.substr(7, n - 7);

	if (table != "views")
		{
		if (theDB()->istable(table))
			theDB()->remove_table(table);
		database_admin(tblspec.str());
		}
	return load_data(fin, table);
	}
Esempio n. 4
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;
	}
Esempio n. 5
0
static void load_data_record(Istream& fin, const gcstring& table, int tran, int n)
	{
	try
		{
		if (n > loadbuf_size)
			{
			loadbuf_size = max(n, 2 * loadbuf_size);
			mem_release(loadbuf);
			loadbuf = (char*) mem_committed(loadbuf_size);
			verify(loadbuf);
			}
		fin.read(loadbuf, n);
		Record rec(loadbuf);
		if (rec.cursize() != n)
			except_err(table << ": rec size " << rec.cursize() << " not what was read " << n);
		if (table == "views")
			theDB()->add_any_record(tran, table, rec);
		else
			theDB()->add_record(tran, table, rec);
		}
	catch (const Except& e)
		{
		errlog("load: skipping corrupted record in: ", table.str(), e.str());
		alert("skipping corrupted record in: " << table << ": " << e);
		alerts = true;
		}
	}
Esempio n. 6
0
Except::Except(gcstring x) : SuString(x.trim()),
	fp_fn_(tls().proc ? tls().proc->fp->fn : 0), is_block_return(x == "block return")
	{
	if (x.has_prefix("block") &&
		(x == "block:continue" || x == "block:break" || is_block_return))
		{
		static SuObject* empty = new SuObject;
		calls_ =  empty;
		if (is_block_return)
			verify(fp_fn_);
		}
	else
		{
		TRACE(EXCEPTIONS, "throwing: " << x);
		calls_ = copyCallStack();
		}
	}
Esempio n. 7
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;
	}
/**
 * @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();
}
Esempio n. 9
0
void Md5::update(gcstring s)
	{
	if (! CryptHashData(hHash, (BYTE*) s.ptr(), s.size(), 0))
		except("Md5: CryptHashData failed");
	}
Esempio n. 10
0
void SuAdler32::update(const gcstring& s)
	{
	value = checksum(value, s.ptr(), s.size());
	}
Esempio n. 11
0
Value symbol(const gcstring& s)
	{
	return symbol(s.str());
	}