void Swig_feature_set(Hash *features, String *name, SwigType *decl, String *featurename, DOH *value) { Hash *n; Hash *fhash; /* Printf(stdout,"feature: %s %s %s %s\n", name, decl, featurename, value);*/ n = Getattr(features,name); if (!n) { n = NewHash(); Setattr(features,name,n); } if (!decl) { fhash = Getattr(n,"*"); if (!fhash) { fhash = NewHash(); Setattr(n,"*",fhash); } } else { fhash = Getattr(n,decl); if (!fhash) { fhash = NewHash(); Setattr(n,Copy(decl),fhash); } } if (value) { Setattr(fhash,featurename,value); } else { Delattr(fhash,featurename); } }
void DBInitEventQueue(void) { pthread_mutex_init(&DBEventQueueMutex, NULL); pthread_mutex_init(&DBEventExitQueueMutex, NULL); DBQueueEvents = NewHash(1, Flathash); DBInboundEventQueues[0] = NewHash(1, Flathash); DBInboundEventQueues[1] = NewHash(1, Flathash); DBInboundEventQueue = DBInboundEventQueues[0]; }
DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, size_t oaepBlockLen, byte *output, const NameValuePairs ¶meters) const { bool invalid = false; #if defined(CRYPTOPP_CXX11) std::unique_ptr<HashTransformation> pHash(NewHash()); #else std::auto_ptr<HashTransformation> pHash(NewHash()); #endif // convert from bit length to byte length if (oaepBlockLen % 8 != 0) { invalid = (oaepBlock[0] != 0) || invalid; oaepBlock++; } oaepBlockLen /= 8; const size_t hLen = pHash->DigestSize(); const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen; invalid = (oaepBlockLen < 2*hLen+1) || invalid; SecByteBlock t(oaepBlock, oaepBlockLen); byte *const maskedSeed = t; byte *const maskedDB = t+seedLen; #if defined(CRYPTOPP_CXX11) std::unique_ptr<MaskGeneratingFunction> pMGF(NewMGF()); #else std::auto_ptr<MaskGeneratingFunction> pMGF(NewMGF()); #endif pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen); pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen); ConstByteArrayParameter encodingParameters; parameters.GetValue(Name::EncodingParameters(), encodingParameters); // DB = pHash' || 00 ... || 01 || M byte *M = std::find(maskedDB+hLen, maskedDB+dbLen, 0x01); invalid = (M == maskedDB+dbLen) || invalid; invalid = (std::find_if(maskedDB+hLen, M, std::bind2nd(std::not_equal_to<byte>(), byte(0))) != M) || invalid; invalid = !pHash->VerifyDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()) || invalid; if (invalid) return DecodingResult(); M++; memcpy(output, M, maskedDB+dbLen-M); return DecodingResult(maskedDB+dbLen-M); }
void ServerStartModule_CONTEXT (void) { long *v; HttpReqTypes = NewHash(1, NULL); HttpHeaderHandler = NewHash(1, NULL); v = malloc(sizeof(long)); *v = eGET; Put(HttpReqTypes, HKEY("GET"), v, NULL); v = malloc(sizeof(long)); *v = ePOST; Put(HttpReqTypes, HKEY("POST"), v, NULL); v = malloc(sizeof(long)); *v = eOPTIONS; Put(HttpReqTypes, HKEY("OPTIONS"), v, NULL); v = malloc(sizeof(long)); *v = ePROPFIND; Put(HttpReqTypes, HKEY("PROPFIND"), v, NULL); v = malloc(sizeof(long)); *v = ePUT; Put(HttpReqTypes, HKEY("PUT"), v, NULL); v = malloc(sizeof(long)); *v = eDELETE; Put(HttpReqTypes, HKEY("DELETE"), v, NULL); v = malloc(sizeof(long)); *v = eHEAD; Put(HttpReqTypes, HKEY("HEAD"), v, NULL); v = malloc(sizeof(long)); *v = eMOVE; Put(HttpReqTypes, HKEY("MOVE"), v, NULL); v = malloc(sizeof(long)); *v = eCOPY; Put(HttpReqTypes, HKEY("COPY"), v, NULL); v = malloc(sizeof(long)); *v = eREPORT; Put(HttpReqTypes, HKEY("REPORT"), v, NULL); }
String *Swig_name_destroy(const_String_or_char_ptr nspace, const_String_or_char_ptr classname) { String *r; String *f; String *rclassname; char *cname; rclassname = SwigType_namestr(classname); r = NewStringEmpty(); if (!naming_hash) naming_hash = NewHash(); f = Getattr(naming_hash, "destroy"); if (!f) { Append(r, "delete_%n%c"); } else { Append(r, f); } cname = Char(rclassname); if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { cname = strchr(cname, ' ') + 1; } replace_nspace(r, nspace); Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; }
String *Swig_name_disown(const String_or_char *classname) { String *r; String *f; String *rclassname; char *cname; rclassname = SwigType_namestr(classname); r = NewString(""); if (!naming_hash) naming_hash = NewHash(); f = Getattr(naming_hash,"disown"); if (!f) { Append(r,"disown_%c"); } else { Append(r,f); } cname = Char(rclassname); if ((strncmp(cname,"struct ", 7) == 0) || ((strncmp(cname,"class ", 6) == 0)) || ((strncmp(cname,"union ", 6) == 0))) { cname = strchr(cname, ' ')+1; } Replace(r,"%c",cname, DOH_REPLACE_ANY); Delete(rclassname); return r; }
int DohSetmeta(DOH *ho, const DOH *name, const DOH *value) { DohBase *h = (DohBase *) ho; if (!DohCheck(ho)) return 0; if (!h->meta) h->meta = NewHash(); return DohSetattr(h->meta, name, value); }
SwigType *SwigType_strip_qualifiers(SwigType *t) { static Hash *memoize_stripped = 0; SwigType *r; List *l; Iterator ei; if (!memoize_stripped) memoize_stripped = NewHash(); r = Getattr(memoize_stripped, t); if (r) return Copy(r); l = SwigType_split(t); r = NewStringEmpty(); for (ei = First(l); ei.item; ei = Next(ei)) { if (SwigType_isqualifier(ei.item)) continue; Append(r, ei.item); } Delete(l); { String *key, *value; key = Copy(t); value = Copy(r); Setattr(memoize_stripped, key, value); Delete(key); Delete(value); } return r; }
void Swig_fragment_register(Node* fragment) { if (Getattr(fragment,k_emitonly)) { Swig_fragment_emit(fragment); return; } else { String *name = Copy(Getattr(fragment,k_value)); String *type = Getattr(fragment,k_type); if (type) { SwigType *rtype = SwigType_typedef_resolve_all(type); String *mangle = Swig_string_mangle(type); Append(name,mangle); Delete(mangle); Delete(rtype); if (debug) Printf(stdout,"register fragment %s %s\n",name,type); } if (!fragments) { fragments = NewHash(); } if (!Getattr(fragments,name)) { String *section = Copy(Getattr(fragment,k_section)); String *ccode = Copy(Getattr(fragment,k_code)); Hash *kwargs = Getattr(fragment,k_kwargs); Setmeta(ccode,k_section,section); if (kwargs) { Setmeta(ccode,k_kwargs,kwargs); } Setattr(fragments,name,ccode); if (debug) Printf(stdout,"registering fragment %s %s\n",name,section); Delete(section); Delete(ccode); } Delete(name); } }
void TestHash() { Thing key = Word(7); Thing item = Word(11); Thing X, Y; CommentLine("Testing Hashtable"); Hash H = NewHash(NULL); HashIns(H, key, item); //BAD CODE: if (IntWord(HashGet(H, key)) != 11) //{ printf("no match!\n"); } //HashGet can return NULL! X = HashGet(H, key); assert(X); assert(SameThing(X, item)); if (ThingCmp(X, item) != EQ) printf("error in retr hash"); Y = HashRm(H, key); assert(SameThing(Y, item)); assert(SameThing(X, Y)); DelThing(X); X = HashRm(H, key); assert(X == NULL); DelHash(H); //asm("int3"); DelThing(Y); // this calls the dtor on item DelThing(key); printf("Basic insert/retrieve in hash table done.\n"); }
HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP) { StrBuf *Buf; HashList *Hash; char nnn[64]; char buf[SIZ]; int nUsed; NodeConf *Node; serv_puts("CONF getsys|application/x-citadel-ignet-config"); serv_getln(buf, sizeof buf); if (buf[0] == '1') { Hash = NewHash(1, NULL); Buf = NewStrBuf(); while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) { Node = NewNode(Buf); if (Node != NULL) { nUsed = GetCount(Hash); nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1); Put(Hash, nnn, nUsed, Node, DeleteNodeConf); } } FreeStrBuf(&Buf); return Hash; } return NULL; }
void OAEP_Base::Pad(RandomNumberGenerator &rng, const byte *input, size_t inputLength, byte *oaepBlock, size_t oaepBlockLen, const NameValuePairs ¶meters) const { assert (inputLength <= MaxUnpaddedLength(oaepBlockLen)); // convert from bit length to byte length if (oaepBlockLen % 8 != 0) { oaepBlock[0] = 0; oaepBlock++; } oaepBlockLen /= 8; std::auto_ptr<HashTransformation> pHash(NewHash()); const size_t hLen = pHash->DigestSize(); const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen; byte *const maskedSeed = oaepBlock; byte *const maskedDB = oaepBlock+seedLen; ConstByteArrayParameter encodingParameters; parameters.GetValue(Name::EncodingParameters(), encodingParameters); // DB = pHash || 00 ... || 01 || M pHash->CalculateDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()); memset(maskedDB+hLen, 0, dbLen-hLen-inputLength-1); maskedDB[dbLen-inputLength-1] = 0x01; memcpy(maskedDB+dbLen-inputLength, input, inputLength); rng.GenerateBlock(maskedSeed, seedLen); std::auto_ptr<MaskGeneratingFunction> pMGF(NewMGF()); pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen); pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen); }
Parm *NewParm(SwigType *type, String_or_char *n) { Parm *p = NewHash(); if (type) { Setattr(p,"type", Copy(type)); } Setattr(p,"name",n); return p; }
eNextState POP3C_GetListCommandState(pop3aggr *RecvMsg) { AsyncIO *IO = &RecvMsg->IO; POP3C_DBG_READ(); if (!POP3C_OK) return eTerminateConnection; RecvMsg->MsgNumbers = NewHash(1, NULL); RecvMsg->State++; return eReadMore; }
Wrapper *NewWrapper(void) { Wrapper *w; w = (Wrapper *) malloc(sizeof(Wrapper)); w->localh = NewHash(); w->locals = NewStringEmpty(); w->code = NewStringEmpty(); w->def = NewStringEmpty(); return w; }
void Swig_fragment_register(String *name, String *section, String *code) { String *ccode; if (!fragments) { fragments = NewHash(); } ccode = Copy(code); Setmeta(ccode,"section",Copy(section)); Setattr(fragments,Copy(name),ccode); }
void swill_user(const char *name, const char *password) { String *str; if (!SwillInit) return; if (!SwillUsers) { SwillUsers = NewHash(); } str = NewString(""); Printf(str,"%s:%s",name,password); Setattr(SwillUsers,str,name); }
Parm *NewParmWithoutFileLineInfo(SwigType *type, const_String_or_char_ptr name) { Parm *p = NewHash(); set_nodeType(p, "parm"); if (type) { SwigType *ntype = Copy(type); Setattr(p, "type", ntype); Delete(ntype); } Setattr(p, "name", name); return p; }
Parm *NewParm(SwigType *type, const String_or_char *name) { Parm *p = NewHash(); set_nodeType(p, "parm"); if (type) { SwigType *ntype = Copy(type); Setattr(p, "type", ntype); Delete(ntype); } Setattr(p, "name", name); return p; }
Node *copyNode(Node *n) { Iterator ki; Node *c = NewHash(); for (ki = First(n); ki.key; ki = Next(ki)) { if (DohIsString(ki.item)) { Setattr(c, ki.key, Copy(ki.item)); } } Setfile(c, Getfile(n)); Setline(c, Getline(n)); return c; }
void Swig_warn(const char *filename, int line, const char *msg) { String *key; if (!warnings) { warnings = NewHash(); } key = NewStringf("%s:%d", filename, line); if (!Getattr(warnings, key)) { Printf(stderr, "swig-dev warning:%s:%d:%s\n", filename, line, msg); Setattr(warnings, key, key); } Delete(key); }
Parm *CopyParm(Parm *p) { Parm *np = NewHash(); Iterator ki; for (ki = First(p); ki.key; ki = Next(ki)) { if (DohIsString(ki.item)) { DOH *c = Copy(ki.item); Setattr(np,ki.key,c); Delete(c); } } Setfile(np, Getfile(p)); Setline(np, Getline(p)); return np; }
void NewMailQEntry(OneQueItem *Item) { Item->Current = (MailQEntry*) malloc(sizeof(MailQEntry)); memset(Item->Current, 0, sizeof(MailQEntry)); if (Item->MailQEntries == NULL) Item->MailQEntries = NewHash(1, Flathash); /* alocate big buffer so we won't get problems reallocating later. */ Item->Current->StatusMessage = NewStrBufPlain(NULL, SIZ); Item->Current->n = GetCount(Item->MailQEntries); Put(Item->MailQEntries, IKEY(Item->Current->n), Item->Current, FreeMailQEntry); }
/* * Fetch the "mortuary" - a list of dead buddies which we keep around forever * so we can remove them from any client's roster that still has them listed */ HashList *xmpp_fetch_mortuary(void) { HashList *mortuary = NewHash(1, NULL); if (!mortuary) { syslog(LOG_ALERT, "NewHash() failed!\n"); return(NULL); } if (CtdlGetRoom(&CC->room, USERCONFIGROOM) != 0) { /* no config room exists - no further processing is required. */ return(mortuary); } CtdlForEachMessage(MSGS_LAST, 1, NULL, XMPPMORTUARY, NULL, xmpp_fetch_mortuary_backend, (void *)mortuary ); return(mortuary); }
void Swig_name_object_set(Hash *namehash, String *name, SwigType *decl, DOH *object) { DOH *n; /* Printf(stdout,"name: '%s', '%s'\n", name, decl);*/ n = Getattr(namehash,name); if (!n) { n = NewHash(); Setattr(namehash,name,n); } /* Add an object based on the declarator value */ if (!decl) { Setattr(n,NewString("*"),object); } else { Setattr(n,Copy(decl),object); } }
String * Swig_name_wrapper(const String_or_char *fname) { String *r; String *f; r = NewString(""); if (!naming_hash) naming_hash = NewHash(); f = Getattr(naming_hash,"wrapper"); if (!f) { Append(r,"_wrap_%f"); } else { Append(r,f); } Replace(r,"%f",fname, DOH_REPLACE_ANY); name_mangle(r); return r; }
String * Swig_name_set(const String_or_char *vname) { String *r; String *f; r = NewString(""); if (!naming_hash) naming_hash = NewHash(); f = Getattr(naming_hash,"set"); if (!f) { Append(r,"%v_set"); } else { Append(r,f); } Replace(r,"%v",vname, DOH_REPLACE_ANY); Replace(r,"::","_", DOH_REPLACE_ANY); return r; }
static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) { Node *kw = nextSibling(nameobj); List *matchlist = 0; while (kw) { Node *next = nextSibling(kw); String *kname = Getattr(kw, "name"); char *ckey = kname ? Char(kname) : 0; if (ckey) { const char **rkey; int isnotmatch = 0; int isregexmatch = 0; if ((strncmp(ckey, "match", 5) == 0) || (isnotmatch = (strncmp(ckey, "notmatch", 8) == 0)) || (isregexmatch = (strncmp(ckey, "regexmatch", 10) == 0)) || (isnotmatch = isregexmatch = (strncmp(ckey, "notregexmatch", 13) == 0))) { Hash *mi = NewHash(); List *attrlist = Swig_make_attrlist(ckey); if (!matchlist) matchlist = NewList(); Setattr(mi, "value", Getattr(kw, "value")); Setattr(mi, "attrlist", attrlist); if (isnotmatch) SetFlag(mi, "notmatch"); if (isregexmatch) SetFlag(mi, "regexmatch"); Delete(attrlist); Append(matchlist, mi); Delete(mi); removeNode(kw); } else { for (rkey = keys; *rkey != 0; ++rkey) { if (strcmp(ckey, *rkey) == 0) { Setattr(nameobj, *rkey, Getattr(kw, "value")); removeNode(kw); } } } } kw = next; } if (matchlist) { Setattr(nameobj, "matchlist", matchlist); Delete(matchlist); } }
SwigType *SwigType_strip_single_qualifier(const SwigType *t) { static Hash *memoize_stripped = 0; SwigType *r = 0; List *l; int numitems; if (!memoize_stripped) memoize_stripped = NewHash(); r = Getattr(memoize_stripped, t); if (r) return Copy(r); l = SwigType_split(t); numitems = Len(l); if (numitems >= 2) { int item; /* iterate backwards from last but one item */ for (item = numitems - 2; item >= 0; --item) { String *subtype = Getitem(l, item); if (SwigType_isqualifier(subtype)) { Iterator it; Delitem(l, item); r = NewStringEmpty(); for (it = First(l); it.item; it = Next(it)) { Append(r, it.item); } break; } } } if (!r) r = Copy(t); Delete(l); { String *key, *value; key = Copy(t); value = Copy(r); Setattr(memoize_stripped, key, value); Delete(key); Delete(value); } return r; }
void TestFactorial() { uint c; uint checkbuff[14]; //const uint * const here = checkbuff; Hash H = NewHash(FactHasher); for (c=0; c<TESTFACTORIALMAX; c++) { checkbuff[c] = Factorial(H, c); //printf("%d\n", Factorial(H, c)); } //asm("int3"); if (TestCheckBufferWithFunction(checkbuff, TESTFACTORIALMAX, FactCheck) == false) printf ("test failed.\n"); DelHash(H); printf("Factorial, using a hash table for memoization passed.\n"); }