void addKey(HashTable *table, char *key, char *value){ //printf("Adding %s : %s to the table\n",key,value); if(table){ table->count += 1; if(table->count >= (table->maxSize)/2){ printf("After adding this one count is %08x\n",table->count); grow(table); } uint32_t k = prehash(key); if(table->values[k % table->maxSize]){ Node *n = initNode(key,value); //printf("Inserting at address: %08x\n",k%table->maxSize); // printf("Collision detected!\n"); insertNode(table->values[k % table->maxSize],n); }else{ //printf("Inserting at address: %08x\n",k%table->maxSize); table->values[k % table->maxSize] = initNode(key,value); } }else{ table = initTable(INITIAL_HASH_SIZE); uint32_t k = prehash(key); printf("Inserting at address: %08x\n",k%table->maxSize); table->values[k % table->maxSize] = initNode(key,value); } }
void LLMessageTemplateParserTestObject::test<6>() // tests message parsing method on a simple message { std::string message_skel( "{\n" "TestMessage Low 1 NotTrusted Zerocoded\n" "// comment \n" " {\n" "TestBlock1 Single\n" " { Test1 U32 }\n" " }\n" " {\n" " NeighborBlock Multiple 4\n" " { Test0 U32 }\n" " { Test1 U32 }\n" " { Test2 U32 }\n" " }\n" "}"); LLTemplateTokenizer tokens(message_skel); LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); ensure("simple message parsed", message != 0); ensure_equals("name of message", std::string(message->mName), std::string("TestMessage")); ensure_equals("frequency is Low", message->mFrequency, MFT_LOW); ensure_equals("trust is untrusted", message->mTrust, MT_NOTRUST); ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 1)); ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED); ensure_equals("message deprecation is notdeprecated", message->mDeprecation, MD_NOTDEPRECATED); LLMessageBlock * block = message->getBlock(prehash("NonexistantBlock")); ensure("Nonexistant block does not exist", block == 0); delete message; }
// Assume the table exists void rehash(HashTable *table, char *key, char *value){ /* if(table){ // If the table exists, then add a new node to the given key uint32_t k = prehash(key); Node *newNode = initNode(key,value); printf("prehash %08x, max size: %08x\n",k,table->maxSize); printf("Storing at index %02d \n",k%table->maxSize); insertNode(table->values[k % table->maxSize],newNode); table->count++; } */ //printf("Adding %s : %s to the table\n",key,value); if(table){ table->count += 1; uint32_t k = prehash(key); if(table->values[k % table->maxSize]){ Node *n = initNode(key,value); //printf("Inserting at address: %08x\n",k%table->maxSize); //printf("Collision detected!\n"); insertNode(table->values[k % table->maxSize],n); }else{ //printf("Inserting at address: %08x\n",k%table->maxSize); table->values[k % table->maxSize] = initNode(key,value); } } }
/* * Prepare the server for take off. * */ int server_prepare(struct nsd *nsd) { /* Open the database... */ if ((nsd->db = namedb_open(nsd->dbfile, nsd->options, nsd->child_count)) == NULL) { log_msg(LOG_ERR, "unable to open the database %s: %s", nsd->dbfile, strerror(errno)); return -1; } /* Read diff file */ if(!diff_read_file(nsd->db, nsd->options, NULL, nsd->child_count)) { log_msg(LOG_ERR, "The diff file contains errors. Will continue " "without it"); } #ifdef NSEC3 prehash(nsd->db, 0); #endif compression_table_capacity = 0; initialize_dname_compression_tables(nsd); #ifdef BIND8_STATS /* Initialize times... */ time(&nsd->st.boot); set_bind8_alarm(nsd); #endif /* BIND8_STATS */ return 0; }
static void evalpipe(union node *n) { struct job *jp; struct nodelist *lp; int pipelen; int prevfd; int pip[2]; TRACE(("evalpipe(%p) called\n", (void *)n)); pipelen = 0; for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) pipelen++; INTOFF; jp = makejob(n, pipelen); prevfd = -1; for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { prehash(lp->n); pip[1] = -1; if (lp->next) { if (pipe(pip) < 0) { if (prevfd >= 0) close(prevfd); error("Pipe call failed: %s", strerror(errno)); } } if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) { INTON; if (prevfd > 0) { dup2(prevfd, 0); close(prevfd); } if (pip[1] >= 0) { if (!(prevfd >= 0 && pip[0] == 0)) close(pip[0]); if (pip[1] != 1) { dup2(pip[1], 1); close(pip[1]); } } evaltree(lp->n, EV_EXIT); } if (prevfd >= 0) close(prevfd); prevfd = pip[0]; if (pip[1] != -1) close(pip[1]); } INTON; if (n->npipe.backgnd == 0) { INTOFF; exitstatus = waitforjob(jp, NULL); TRACE(("evalpipe: job done exit status %d\n", exitstatus)); INTON; } else exitstatus = 0; }
STATIC void evalpipe(union node *n) { struct job *jp; struct nodelist *lp; int pipelen; int prevfd; int pip[2]; TRACE(("evalpipe(0x%lx) called\n", (long)n)); pipelen = 0; for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) pipelen++; INTOFF; jp = makejob(n, pipelen); prevfd = -1; for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { prehash(lp->n); pip[1] = -1; if (lp->next) { if (sh_pipe(pip) < 0) { if (prevfd >= 0) close(prevfd); error("Pipe call failed"); } } if (forkshell(jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG) == 0) { INTON; if (prevfd > 0) { close(0); copyfd(prevfd, 0, 1, 0); close(prevfd); } if (pip[1] >= 0) { close(pip[0]); if (pip[1] != 1) { close(1); copyfd(pip[1], 1, 1, 0); close(pip[1]); } } evaltree(lp->n, EV_EXIT); } if (prevfd >= 0) close(prevfd); prevfd = pip[0]; close(pip[1]); } if (n->npipe.backgnd == 0) { exitstatus = waitforjob(jp); TRACE(("evalpipe: job done exit status %d\n", exitstatus)); } else exitstatus = 0; INTON; }
STATIC void evalpipe(shinstance *psh, union node *n) { struct job *jp; struct nodelist *lp; int pipelen; int prevfd; int pip[2]; TRACE((psh, "evalpipe(0x%lx) called\n", (long)n)); pipelen = 0; for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) pipelen++; INTOFF; jp = makejob(psh, n, pipelen); prevfd = -1; for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { prehash(psh, lp->n); pip[1] = -1; if (lp->next) { if (sh_pipe(psh, pip) < 0) { shfile_close(&psh->fdtab, prevfd); error(psh, "Pipe call failed"); } } if (forkshell(psh, jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG) == 0) { INTON; if (prevfd > 0) { movefd(psh, prevfd, 0); } if (pip[1] >= 0) { shfile_close(&psh->fdtab, pip[0]); if (pip[1] != 1) { movefd(psh, pip[1], 1); } } evaltree(psh, lp->n, EV_EXIT); } if (prevfd >= 0) shfile_close(&psh->fdtab, prevfd); prevfd = pip[0]; shfile_close(&psh->fdtab, pip[1]); } if (n->npipe.backgnd == 0) { psh->exitstatus = waitforjob(psh, jp); TRACE((psh, "evalpipe: job done exit status %d\n", psh->exitstatus)); } INTON; }
void LLMessageTemplateParserTestObject::test<5>() // tests block parsing method { LLTemplateTokenizer tokens("{ BlockA Single { VarX F32 } }"); LLMessageBlock * block = LLTemplateParser::parseBlock(tokens); ensure("blockA block parsed", block != 0); ensure_equals("name of block", std::string(block->mName), std::string("BlockA")); ensure_equals("type of block is Single", block->mType, MBT_SINGLE); ensure_equals("total size of block", block->mTotalSize, 4); ensure_equals("number of block defaults to 1", block->mNumber, 1); ensure_equals("variable type of VarX is F32", block->getVariableType(prehash("VarX")), MVT_F32); ensure_equals("variable size of VarX", block->getVariableSize(prehash("VarX")), 4); delete block; tokens = LLTemplateTokenizer("{ Stuff Variable { Id LLUUID } }"); block = LLTemplateParser::parseBlock(tokens); ensure("stuff block parsed", block != 0); ensure_equals("name of block", std::string(block->mName), std::string("Stuff")); ensure_equals("type of block is Multiple", block->mType, MBT_VARIABLE); ensure_equals("total size of block", block->mTotalSize, 16); ensure_equals("number of block defaults to 1", block->mNumber, 1); ensure_equals("variable type of Id is LLUUID", block->getVariableType(prehash("Id")), MVT_LLUUID); ensure_equals("variable size of Id", block->getVariableSize(prehash("Id")), 16); delete block; tokens = LLTemplateTokenizer("{ Stuff2 Multiple 45 { Shid LLVector3d } }"); block = LLTemplateParser::parseBlock(tokens); ensure("stuff2 block parsed", block != 0); ensure_equals("name of block", std::string(block->mName), std::string("Stuff2")); ensure_equals("type of block is Multiple", block->mType, MBT_MULTIPLE); ensure_equals("total size of block", block->mTotalSize, 24); ensure_equals("number of blocks", block->mNumber, 45); ensure_equals("variable type of Shid is Vector3d", block->getVariableType(prehash("Shid")), MVT_LLVector3d); ensure_equals("variable size of Shid", block->getVariableSize(prehash("Shid")), 24); delete block; }
void deleteKey(HashTable *table,char *strKey){ //printf("~~~~~~~~~~~~DELETING KEY~~~~~~~~~~\n"); //Node *dnode = findKey(table,strKey); uint32_t k = prehash(strKey); Node *dnode = findNode(table->values[k % table->maxSize],strKey); if(dnode){ //printf("Found a node with : %s : %s \n",dnode->key,dnode->value); if(dnode->previous){ //printf("It had a previous value\n"); if(dnode->next){ // printf("It had a next value\n"); Node *p = dnode->previous; p->next = dnode->next; p->next->previous = p; }else{ // printf("It didn't have a next value\n"); Node *p = dnode->previous; p->next = NULL; } destroyNode(dnode); }else{ //printf("It was the first in the chain\n"); free(dnode->value); free(dnode->key); if(dnode->next){ table->values[k % table->maxSize] = dnode->next; }else{ table->values[k % table->maxSize] = NULL; } } table->count--; if(table->count <= (table->maxSize/4)){ shrink(table); } } }
{ OwnerID LLUUID }\n\ { AttachmentPt U8 } // 0 for default\n\ { ItemFlags U32 }\n\ { GroupMask U32 }\n\ { EveryoneMask U32 }\n\ { NextOwnerMask U32 }\n\ { Name Variable 1 }\n\ { Description Variable 1 }\n\ }\n\ }\n\ "); LLTemplateTokenizer tokens(message_skel); LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); ensure("RezMultipleAttachmentsFromInv message parsed", message != 0); ensure_equals("name of message", message->mName, prehash("RezMultipleAttachmentsFromInv")); ensure_equals("frequency is low", message->mFrequency, MFT_LOW); ensure_equals("trust is not trusted", message->mTrust, MT_NOTRUST); ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 452)); ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED); ensure_block_attributes( "RMAFI", message, "AgentData", MBT_SINGLE, 1, 16+16); LLMessageBlock * block = message->getBlock(prehash("AgentData")); ensure_variable_attributes("RMAFI", block, "AgentID", MVT_LLUUID, 16); ensure_variable_attributes("RMAFI", block, "SessionID", MVT_LLUUID, 16); ensure_block_attributes( "RMAFI", message, "HeaderData", MBT_SINGLE, 1, 16+1+1);
Node *findKey(HashTable *table,char *key){ uint32_t k = prehash(key); //printf("The key is : %s %08x\n",key,k); //printf("Looking at address : %08x\n",k % table->maxSize); return findNode(table->values[k % table->maxSize],key); }