bool test_remove() { Table * t = makeTable(); hset(t, "Key", "A"); char *returned = hget(t, "Key"); ASSERT(returned != 0, "Table returned null after setting"); hdel(t, "Key"); returned = hget(t, "Key"); //missing key returns empty string? ASSERT(returned[0] == 0, "Table returned non-null"); return true; }
/** Do an HTTP GET of the directory on the server that has the * available traceroute sets. The directory listing is parsed * for links, and these are appended to the trsets vector. */ bool ServerComm::getTrSets(QStringList& trsets, bool popupOnError) { static bool in_progress = false; if ( in_progress ) return false; //in theory, a race condition is here. in_progress = true; trsets.clear(); QBuffer buf; buf.open(QBuffer::WriteOnly); QUrl url("http://trgen.ixmaps.ca/trsets/"); HttpGet hget(url, &buf); qDebug() << "HttpGet error " << hget.error(); QHttp::Error err = hget.error(); if ( err != QHttp::NoError ) { msgConnFailure(err, popupOnError); in_progress = false; return false; } // scan the Apache directory listing. This makes it easy to change deployment // of batch trace files. // To see what this is parsing, fetch the link in a browser and view source. char prefix_str[] = "<a href=\""; qDebug() << "prefix_str len is " << sizeof(prefix_str); QByteArray ba = buf.buffer(); char *s = ba.data(); qDebug() << "from server got: " << s; char *e = s + ba.count() - (sizeof(prefix_str)+2); // guard against read past buffer end while ( s < e ) { // look for <a href="something.trset" if ( strncmp(s, prefix_str, sizeof(prefix_str)-1) == 0 ) { // found a likely URL char *token = s+sizeof(prefix_str)-1; char *p; for ( p = token; *p != '"'; p++ ) { if ( p >= e ) goto end_buffer; } *p = '\0'; // stomp the closing quote -> string terminator if ( token[0] == '.' && token[1] == '/' ) token += 2; // ignore superfluous ./ in ./something.trset // Apache directory listing contains a few unwanted URLs beginning with ? or / // restrict filenames to those ending with ".trset" if ( token[0] != '?' && token[0] != '/' && strcmp(p-6, ".trset") == 0 ) { QString qstr(token); trsets << qstr; qDebug() << "getTrSets got " << qstr.toAscii().data(); } s = p+1; } else s++; } end_buffer: in_progress = false; return true; }
int main() { int (**table)[2] = hnew(); hset(table, 10, 20); hset(table, 20, 30); hset(table, 30, 40); int (**a)[2] = hget(table, 10); int (**b)[2] = hget(table, 20); int (**c)[2] = hget(table, 30); printf("%d:%d\n", (**a)[0], (**a)[1]); printf("%d:%d\n", (**b)[0], (**b)[1]); printf("%d:%d\n", (**c)[0], (**c)[1]); hdel(table); }
int main() { INT32 ret; UINT8* buf = malloc(0x40000); ret = hget("http://gdata.youtube.com/feeds/api/videos", buf, 0x40000); printf("%d\n", ret); free(buf); return 0; }
bool test_duplicate_insert_overrides() { Table * t = makeTable(); hset(t, "Key", "A"); hset(t, "Key", "B"); char* returned = hget(t, "Key"); ASSERT(returned != 0, "Table returned null on duplicate insert"); ASSERT(returned[0] != 'A', "Table returned old value on duplicate insert"); ASSERT(returned[0] == 'B', "Table returned wrong value on duplicate insert"); freeTable(t); return true; }
leveldb::Status Server::hmget(leveldb::Slice user_key, const std::vector<Slice>& fields, std::vector<std::string>* value) { std::string cur; leveldb::Status s; for (Slice field: fields) { s = hget(user_key, field, &cur); if (!s.ok()) { return s; } value->push_back(cur); } return leveldb::Status::OK(); }
/** Fetch a trset batch file from the server. */ bool ServerComm::fetchBatch(const QString& filename, QBuffer& buf, bool popupOnError) { buf.open(QBuffer::WriteOnly); QString str_url("http://trgen.ixmaps.ca/trsets/"); str_url += filename; QUrl url(str_url); HttpGet hget(url, &buf); qDebug() << "HttpGet error " << hget.error(); QHttp::Error err = hget.error(); if ( err != QHttp::NoError ) { msgConnFailure(err, popupOnError); return false; } return true; }
bool CRedisClient::hget( const std::string &key, const std::string &field, string &value ) { CResult result; hget( key, field, result ); ReplyType type = result.getType(); if ( type == REDIS_REPLY_ERROR ) { throw ReplyErr( result.getErrorString() ); } if ( type == REDIS_REPLY_NIL ) { return false; } if ( type == REDIS_REPLY_STRING ) { value = result.getString(); return true; }else { throw ProtocolErr( "HSET: data recved is not string" ); } }
bool redis_hash::hget(const char* key, const char* name, string& result) { return hget(key, name, strlen(name), result); }
static void hset(int (**t)[2], int k, int v) { for (int (**a)[2] = hget(t, k); !*a && (*a=malloc(sizeof(**t))); (**a)[0]=k,(**a)[1]=v); }