示例#1
0
文件: clx.c 项目: mycoboco/beluga
/*
 *  initializes a keyword-code table
 */
void (clx_init)(void)
{
    static struct {
        const char *name;
        int code;
    } map[] = {
#define xx(a, b, c, d, e, f, g, h)
#define kk(a, b, c, d, e, f, g, h) g, LEX_##a,
#define yy(a, b, c, d, e, f, g, h)
#include "xtoken.h"
    };

    int i;
    unsigned h;
    struct tab *p;

    for (i = 0; i < NELEM(map); i++) {
        map[i].name = hash_string(map[i].name);
        h = hashkey(map[i].name, NELEM(tab));
        p = ARENA_ALLOC(strg_perm, sizeof(*p));
        p->key = map[i].name;
        p->code = map[i].code;
        p->link = tab[h];
        tab[h] = p;
    }

    proc_prep();
}
示例#2
0
void put(void *args)
{
	int i;
	char *key = ((kv_args*) args)->c_key;
	int value = ((kv_args*) args)->i_value;
	uint32_t index = hashkey(key) % ARRAYLEN;
	kv_node *new_node = (kv_node*) malloc(sizeof(kv_node));

	for(i = 0; (i < KEYLEN || *(key + i) != '\0'); i++) {
		new_node->c_key[i] = *(key + i);
	}

	new_node->i_value = value;
	new_node->next = NULL;

	kv_node **node;
	node = &keys[index];

	pthread_mutex_lock(&kv_lock);

	while(*node) {
		if(strcmp((*node)->c_key, key) == 0) {
			(*node)->i_value = value;
		}

		node = &((*node)->next);
	}

	(*node) = new_node;

	pthread_mutex_unlock(&kv_lock);

	((kv_args*) args)->status = KV_OK;
}
示例#3
0
 /**  Clears everything out. 
  */
 void clear() {
   m_size = 0;
   n_entries = 0;
   base_level = 1;
   base_level_candidate_count = 0;
   cached_insertion_key = hashkey();
   cached_insertion_value = nullptr;
   global_map.clear();
 }
示例#4
0
文件: hashtable.c 项目: volodden/MIPT
int findElementInHashTable(struct HT* newHT, char* key, char** val)
{
//	printf("---FIND ELEMEMT---\n");
    int skey = 0;
    int t = hashkey(key, &skey, newHT->CP);
    if (t)
    {
        return ERROR_FIND_ELEMENT;
    }
    if (newHT->hshtbl[skey]->sz == 0)
    {
        return NO_ELEMENT_FIND;
    }
    int i = 0;
    if (*val != NULL)
    {
        free(*val);
    }
    *val = 0;

    struct dList* fd = newHT->hshtbl[skey]->first;
    if (strcmp(key, fd->key) == 0)
    {
        *val = (char*) malloc((strlen(fd->val) + 1) * sizeof(char));
        if (*val == NULL)
        {
            return ERROR_FIND_ELEMENT;
        }
//	printf("1 malloc in findElement: val\n");
        strcpy(*val, fd->val);
//	printf("11 FOUND: %s\n", fd->val);
//	printf("12 FOUND: %s\n", *val);
//	printf("---END FIND ELEMENT---\n");
        return SUCCESS_FIND_ELEMENT;
    }

    while(fd->next != 0)
    {
        fd = fd->next;
        if (strcmp(key, fd->key) == 0)
        {
            *val = (char*) malloc((strlen(fd->val) + 1) * sizeof(char));
            if (*val == NULL)
            {
                return ERROR_FIND_ELEMENT;
            }
//		printf("1 malloc in findElement: val\n");
            strcpy(*val, fd->val);
//		printf("21: %s\n", fd->val);
//		printf("22: %s\n", *val);
//		printf("---END FIND ELEMENT---\n");
            return SUCCESS_FIND_ELEMENT;
        }
    }
    return NO_ELEMENT_FIND;
}
示例#5
0
void del(void* args)
{
	char *key = ((kv_args*) args)->c_key;

	//Grab hash and mod it w/ array length
	uint32_t index = hashkey(key) % ARRAYLEN;

	//Iterate through list and try to find the key
	kv_node **node = &keys[index];
	kv_node *prev_node = *node; //pointer to previous node in list

	pthread_mutex_lock(&kv_lock);

	while(*node) {
		// Node to be deleted has been found
		if (strcmp((*node)->c_key, key) == 0) {

			// Make sure list isn't broken if deletion node isn't last in the
			// list
			if ((*node)->next) {
				// This condition implies that the node to be deleted is the
				// first node on this chain
				if(*node == prev_node) {
					*node = (*node)->next;
					free(prev_node);
				}

				else {
					kv_node *del_node = prev_node->next; //Node to be deleted
					prev_node->next = (*node)->next;
					free(del_node);
				}
			}

			else {
				free(*node);
			}

			((kv_args*) args)->status = KV_OK;
			pthread_mutex_unlock(&kv_lock);
			return;
		}

		else {
			prev_node = *node;
			node = &((*node)->next);
		}
	}

	pthread_mutex_unlock(&kv_lock);

	((kv_args*) args)->status = KV_NOK;
}
示例#6
0
/* Look up the bundle with all the connections to the same host this
   connectdata struct is setup to use.

   **NOTE**: When it returns, it holds the connection cache lock! */
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
                                                 struct conncache *connc)
{
  struct connectbundle *bundle = NULL;
  CONN_LOCK(conn->data);
  if(connc) {
    char key[128];
    hashkey(conn, key, sizeof(key));
    bundle = Curl_hash_pick(&connc->hash, key, strlen(key));
  }

  return bundle;
}
示例#7
0
文件: mg.c 项目: mycoboco/beluga
/*
 *  checks if a file is macro-guarded;
 *  path is assumed to be a hash string
 */
int (mg_isguarded)(const char *path)
{
    unsigned h;
    struct mgt *p;

    assert(path);

    h = hashkey(path, NELEM(mgt));
    for (p = mgt[h]; p; p = p->link)
        if (p->path == path && (!p->name || mcr_redef(p->name)))
            return 1;

    return 0;
}
示例#8
0
文件: conncache.c 项目: AnnaSerg/curl
/* Look up the bundle with all the connections to the same host this
   connectdata struct is setup to use. */
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
                                                 struct conncache *connc)
{
  struct connectbundle *bundle = NULL;
  if(connc) {
    char *key = hashkey(conn);
    if(key) {
      bundle = Curl_hash_pick(&connc->hash, key, strlen(key));
      free(key);
    }
  }

  return bundle;
}
示例#9
0
void free_list(struct pf_nattrack_list **l) {
   struct pf_nattrack_list *item;
   struct pf_nattrack_hash *pfnth;

   while(*l) {
      item = *l;
      print_nattrack(item->nt, 0);
      pfnth = &pfnt_hash[hashkey(item->nt)];
      ldel(&pfnth->list, item->ref);
      ldel(l, item);
      free(item->ref);
      free(item->nt);
      free(item);
   }
}
示例#10
0
文件: conncache.c 项目: AnnaSerg/curl
CURLcode Curl_conncache_add_conn(struct conncache *connc,
                                 struct connectdata *conn)
{
  CURLcode result;
  struct connectbundle *bundle;
  struct connectbundle *new_bundle = NULL;
  struct SessionHandle *data = conn->data;

  bundle = Curl_conncache_find_bundle(conn, data->state.conn_cache);
  if(!bundle) {
    char *key;
    int rc;

    result = bundle_create(data, &new_bundle);
    if(result)
      return result;

    key = hashkey(conn);
    if(!key) {
      bundle_destroy(new_bundle);
      return CURLE_OUT_OF_MEMORY;
    }

    rc = conncache_add_bundle(data->state.conn_cache, key, new_bundle);
    free(key);
    if(!rc) {
      bundle_destroy(new_bundle);
      return CURLE_OUT_OF_MEMORY;
    }
    bundle = new_bundle;
  }

  result = bundle_add_conn(bundle, conn);
  if(result) {
    if(new_bundle)
      conncache_remove_bundle(data->state.conn_cache, new_bundle);
    return result;
  }

  conn->connection_id = connc->next_connection_id++;
  connc->num_connections++;

  DEBUGF(infof(conn->data, "Added connection %ld. "
               "The cache now contains %" CURL_FORMAT_CURL_OFF_TU " members\n",
               conn->connection_id, (curl_off_t) connc->num_connections));

  return CURLE_OK;
}
示例#11
0
文件: clx.c 项目: mycoboco/beluga
/*
 *  recognizes keywords and identifiers
 */
static int id(lex_t *t)
{
    unsigned h;
    const struct tab *p;

    assert(t);

    clx_tok = hash_string(LEX_SPELL(t));
    h = hashkey(clx_tok, NELEM(tab));
    for (p = tab[h]; p; p = p->link)
        if (p->key == clx_tok)
            return p->code;

    clx_sym = sym_lookup(clx_tok, sym_ident);
    return LEX_ID;
}
示例#12
0
文件: hashtable.c 项目: volodden/MIPT
int deleteElementInHashTable(struct HT* newHT, char* key)
{
//	printf("---DELETE ELEMENT---\n");
    int skey = 0;
    int t = hashkey(key, &skey, newHT->CP);
    if ((t != 0) || (newHT->SZ == 0))
    {
        return ERROR_DELETE_ELEMENT;
    }
    if (newHT->hshtbl[skey]->sz == 0)
    {
        return NO_ELEMENT_DELETE;
    }

    int i = 0;

    struct dList* fd = newHT->hshtbl[skey]->first;
    if (strcmp(key, fd->key) == 0)
    {
        char* temp = 0;
        if (shift(newHT->hshtbl[skey], &temp))
        {
            return ERROR_DELETE_ELEMENT;
        }
	free(temp);
//	printf("1 free in deleteElement: val\n");
        newHT->SZ -= 1;
//	printf("---END DELETE ELEMENT---\n");
        return SUCCESS_DELETE_ELEMENT;
    }

    while(fd->next != 0)
    {
        fd = fd->next;
        if (strcmp(key, fd->key) == 0)
        {
            if (deleteElement(newHT->hshtbl[skey], fd))
            {
                return ERROR_DELETE_ELEMENT;
            }
            newHT->SZ -= 1;
//		printf("---END DELETE ELEMENT---\n");
            return SUCCESS_DELETE_ELEMENT;
        }
    }
    return ERROR_DELETE_ELEMENT;
}
示例#13
0
CURLcode Curl_conncache_add_conn(struct conncache *connc,
                                 struct connectdata *conn)
{
  CURLcode result = CURLE_OK;
  struct connectbundle *bundle;
  struct connectbundle *new_bundle = NULL;
  struct Curl_easy *data = conn->data;

  /* *find_bundle() locks the connection cache */
  bundle = Curl_conncache_find_bundle(conn, data->state.conn_cache);
  if(!bundle) {
    int rc;
    char key[128];

    result = bundle_create(data, &new_bundle);
    if(result) {
      goto unlock;
    }

    hashkey(conn, key, sizeof(key));
    rc = conncache_add_bundle(data->state.conn_cache, key, new_bundle);

    if(!rc) {
      bundle_destroy(new_bundle);
      result = CURLE_OUT_OF_MEMORY;
      goto unlock;
    }
    bundle = new_bundle;
  }

  bundle_add_conn(bundle, conn);
  conn->connection_id = connc->next_connection_id++;
  connc->num_conn++;

  DEBUGF(infof(conn->data, "Added connection %ld. "
               "The cache now contains %zu members\n",
               conn->connection_id, connc->num_conn));

  unlock:
  CONN_UNLOCK(data);

  return result;
}
示例#14
0
文件: mg.c 项目: mycoboco/beluga
/*
 *  remembers a macro guard
 */
void (mg_once)(void)
{
    unsigned h;
    struct mgt *p;
    const lmap_t *pos = lmap_pfrom(lmap_from);

    assert(pos->type <= LMAP_INC);
    h = hashkey(pos->u.i.rf, NELEM(mgt));
    for (p = mgt[h]; p; p = p->link)
        if (p->path == pos->u.i.rf) {
            if (p->name)    /* #pragma once always wins */
                p->name = mg_name;
            return;
        }

    p = ARENA_ALLOC(strg_perm, sizeof(*p));
    p->path = pos->u.i.rf;
    p->name = mg_name;
    p->link = mgt[h];
    mgt[h] = p;
}
示例#15
0
void get(void* args)
{
	char *key = ((kv_args*) args)->c_key;
	uint32_t index = hashkey(key) % ARRAYLEN;
	kv_node *node = keys[index];

	pthread_mutex_lock(&kv_lock);

	while(node) {
		if (strcmp(node->c_key, key) == 0) {
			((kv_args*) args)->i_value = node->i_value;
			((kv_args*) args)->status = KV_OK;
			pthread_mutex_unlock(&kv_lock);
			return;
		}

		else
			node = node->next;
	}

	pthread_mutex_unlock(&kv_lock);

	((kv_args*) args)->status = KV_NOK;
}
示例#16
0
文件: hashtable.c 项目: volodden/MIPT
int addElementInHashTable(struct HT* newHT, char* key, char* val)
{
//	printf("---ADD ELEMENT---\n");
    int skey = 0;
//	printf("1CP = %d\n", newHT->CP);
    if (newHT->SZ * 2 > newHT->CP)
    {
        char** masKEY = (char**) malloc(newHT->SZ * sizeof(char*));
        if (masKEY == NULL)
        {
            return ERROR_ADD_ELEMENT;
        }
        char** masVAL = (char**) malloc(newHT->SZ * sizeof(char*));
        if (masVAL == NULL)
        {
            return ERROR_ADD_ELEMENT;
        }
        int j = 0;
        int k = -1;
        for (j = 0; j < newHT->CP; ++j)
	{
//	printf("j = %d\n", j);
            while(newHT->hshtbl[j]->sz != 0)
            {
                ++k;
                masKEY[k] = (char*) malloc((strlen(newHT->hshtbl[j]->last->key) + 1) * sizeof(char));
                if (masKEY[k] == NULL)
                {
                    return ERROR_ADD_ELEMENT;
                }
//	printf("k = %d\n", k);
//	printf("%s\n", newHT->hshtbl[j]->last->key);
                strcpy(masKEY[k], newHT->hshtbl[j]->last->key);
  //              printf("strcpy\n");
		if (pop(newHT->hshtbl[j], &(masVAL[k])) != 0)
                {
                    return ERROR_ADD_ELEMENT;
                }
//	printf("end while\n");
            }
        }
        if (k+1 != newHT->SZ)
        {
            return ERROR_ADD_ELEMENT;
        }
	for (j = 0; j < newHT->CP; ++j)
	{
	    clearList(newHT->hshtbl[j]);
	    free(newHT->hshtbl[j]);
	}
	free(newHT->hshtbl);
        newHT->CP *= 4;
	newHT->hshtbl = (struct myList**) malloc(newHT->CP * sizeof(struct myList*));
	if (newHT->hshtbl == NULL)
	{
		return ERROR_ADD_ELEMENT;
	}
	for (j = 0; j < newHT->CP; ++j)
	{
		newHT->hshtbl[j] = newList();
		if (newHT->hshtbl[j] == NULL)
		{
			return ERROR_ADD_ELEMENT;
		}	
	}
	newHT->SZ = 0;
        for (j = 0; j <= k; ++j)
        {
            if (addElementInHashTable(newHT, masKEY[j], masVAL[j]) != 0)
            {
                return ERROR_ADD_ELEMENT;
            }
	   free(masKEY[j]);
	   free(masVAL[j]);
        }
	free(masKEY);
	free(masVAL);
    }

    newHT->SZ += 1;
    int t = hashkey(key, &skey, newHT->CP);
    if (t)
    {
        return ERROR_ADD_ELEMENT;
    }
    t = push(newHT->hshtbl[skey], key, val);
    if (t)
    {
        return ERROR_ADD_ELEMENT;
    }
//	printf("SIZE: %d\n",newHT->SZ);
//	printf("CP2 = %2d\n", newHT->CP);
//	printf("---END ADD ELEMENT---\n");
    return SUCCESS_ADD_ELEMENT;
}
示例#17
0
int main() {
   struct pf_nattrack_hash *pfnth = NULL;
   struct pf_nattrack_list *item, *item2;
   struct pf_nattrack_list *lastlist = NULL, *freelist;
   struct pf_nattrack node, *nodep;
   int i, dev;

   initialize();

   dev = open("/dev/pf", O_RDWR);
   if (dev < 0) {
      printerror("open(/dev/pf)");
      return 1;
   }

   do {
      //printf("\n\n===================================\n");
      //printf("Nova rodada\n");
      //printf("===================================\n");

      freelist = lastlist;
      lastlist = NULL;
      
      struct pfioc_states ps;
      struct pfsync_state *p;
      char *inbuf = NULL, *newinbuf = NULL;
      unsigned int len = 0;
      int i, opts = 0;

      memset(&ps, 0, sizeof(ps));
      for (;;) {
         ps.ps_len = len;
         if (len) {
            newinbuf = realloc(inbuf, len);
            if (newinbuf == NULL) {
               printerror("error realloc - out of memory?");
               goto done;
            }
            ps.ps_buf = inbuf = newinbuf;
         }
         if (ioctl(dev, DIOCGETSTATES, &ps) < 0) {
            printerror("failed to get states from PF device");
            goto done;
         }
         if (ps.ps_len + sizeof(struct pfioc_states) < len)
            break;
         if (len == 0 && ps.ps_len == 0)
            goto done;
         if (len == 0 && ps.ps_len != 0)
            len = ps.ps_len;
         if (ps.ps_len == 0)
            goto done;	/* no states */
         len *= 2;
      }
      p = ps.ps_states;
      for (i = 0; i < ps.ps_len; i += sizeof(*p), p++) {
         if (!convert_state(p, &node)) continue;

         pfnth = &pfnt_hash[hashkey(&node)];

         item = lfind(pfnth->list, &node);

         if (item) {
            //printf("Item found! Deleting from freelist\n");
            item2 = item->ref;
            *(item2->nt) = node;
            ldel(&freelist, item2);
         } else {
            //printf("Not found. Inserting...\n");
            nodep = (struct pf_nattrack *)malloc(sizeof(struct pf_nattrack));
            *nodep = node;
            item = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item->nt = nodep;
            item2 = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item2->nt = nodep;
            ladd(&pfnth->list, item);
            item->ref = item2;
         }
         ladd(&lastlist, item2);
         item2->ref = item;
      }
done:
      free(inbuf);
      free_list(&freelist);

      sleep(PFTM_INTERVAL);
   } while(1);
      /* comentando para trabalhar com o get_states
      while ( scanf("\n%d", &i) != EOF && i != 0) {
         if (!read_input(&node)) continue;

         pfnth = &pfnt_hash[hashkey(&node)];

         item = lfind(pfnth->list, &node);

         if (item) {
            //printf("Item found! Deleting from freelist\n");
            item2 = item->ref;
            ldel(&freelist, item2);
         } else {
            //printf("Not found. Inserting...\n");
            nodep = (struct pf_nattrack *)malloc(sizeof(struct pf_nattrack));
            *nodep = node;
            item = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item->nt = nodep;
            item2 = (struct pf_nattrack_list *)malloc(
                  sizeof(struct pf_nattrack_list));
            item2->nt = nodep;
            ladd(&pfnth->list, item);
            item->ref = item2;
         }
         ladd(&lastlist, item2);
         item2->ref = item;
      }
      //printf("done\n");
      //printf("-> removendo itens da freelist\n");
      free_list(&freelist);
      //printf("-> items armazenados:\n");
      //for(i=0; i <= pf_hashmask; i++) {
      //   for(item=pfnt_hash[i].list; item; item=item->next) {
      //      print_nattrack(item->nt, 0);
      //   }
      //}

      //printf("Nova rodada? (1 = sim) ");
   } while(scanf("\n%d", &i) != EOF && i != 0);
   */ // comentando para get_states

   free_list(&lastlist);
   free(pfnt_hash);

   return 0;
}
PDWORD GetProcAddressByHash(WCHAR* dll, ULONGLONG hash) {
	PPEB Peb; UINT i;
	PPEB_LDR_DATA Ldr;
	PLDR_DATA_TABLE_ENTRY Module;
	PLIST_ENTRY ModuleListEntry, ModuleListHead;

	/* get PEB
	*/
	__asm {
		mov eax, FS:[0x30];
		mov Peb, eax
	}

	Ldr = (PPEB_LDR_DATA)Peb->Ldr;
	ModuleListHead = &Ldr->InMemoryOrderModuleList;
	ModuleListEntry = ModuleListHead->Flink;

	while (ModuleListEntry != ModuleListHead)
	{
		Module = (PLDR_DATA_TABLE_ENTRY)ModuleListEntry;
		ModuleListEntry = ModuleListEntry->Flink;
		if (!wcscmp(Module->FullDllName.Buffer, dll))
			break;
	}
	DWORD imageBaseAddr = (DWORD)Module->Reserved2[0];

#if DEBUG
	printf("PEB location : 0x%p\n", Peb);
	printf("Dll: %ls imageBaseAddr: 0x%p\n", Module->FullDllName.Buffer, Module->Reserved2[0]);
#endif // DEBUG

	PIMAGE_DOS_HEADER hDOS = MapPE_DOS(GetCurrentProcess(), (PVOID)imageBaseAddr);
	if (!isDOS(hDOS))
		return NULL;

	PIMAGE_NT_HEADERS hNT = MapPE_NT(GetCurrentProcess(), (PVOID)(imageBaseAddr + hDOS->e_lfanew));
	if (!isNT(hNT))
		return NULL;

	IMAGE_SECTION_HEADER** hSection = MapPE_SECTIONS(
		GetCurrentProcess(),
		(PVOID)(imageBaseAddr + hDOS->e_lfanew + sizeof(IMAGE_NT_HEADERS)),
		hNT->FileHeader.NumberOfSections);

#if DEBUG
	for (i = 0; i < hNT->FileHeader.NumberOfSections; i++)
		printf("%s\n", hSection[i]->Name);
#endif // DEBUG

	PIMAGE_EXPORT_DIRECTORY hExport = MapPE_DD_EXPORT(GetCurrentProcess(), (PVOID)(imageBaseAddr + hNT->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress));
	EAT hEAT;
	hEAT.function = (PDWORD)(imageBaseAddr + hExport->AddressOfFunctions);
	hEAT.name = (PDWORD)(imageBaseAddr + hExport->AddressOfNames);
	hEAT.ordinal = (PDWORD)(imageBaseAddr + hExport->AddressOfNameOrdinals);

#if DEBUG
	printf("Dll: %s\n", imageBaseAddr + hExport->Name);
	for (i = 0; i < hExport->NumberOfNames; i++)
		printf("%s <> 0x%p\n", (char*)(imageBaseAddr + hEAT.name[i]), (PDWORD)(imageBaseAddr + hEAT.function[i]));
#endif // DEBUG

	for (i = 0; i < hExport->NumberOfNames; i++) {
		if (hashkey((PCHAR)(imageBaseAddr + hEAT.name[i])) == hash)
			break;
	}

	free(hSection);
	free(hExport);
	free(hNT);
	free(hDOS);

	return (PDWORD)(imageBaseAddr + hEAT.function[i]);
}
PRBool
nsMathMLOperators::LookupOperator(const nsString&       aOperator,
                                  const nsOperatorFlags aForm,
                                  nsOperatorFlags*      aFlags,
                                  float*                aLeftSpace,
                                  float*                aRightSpace)
{
  if (!gInitialized) {
    InitGlobals();
  }
  if (gOperatorTable) {
    NS_ASSERTION(aFlags && aLeftSpace && aRightSpace, "bad usage");
    NS_ASSERTION(aForm>=0 && aForm<4, "*** invalid call ***");

    OperatorData* found;
    PRInt32 form = NS_MATHML_OPERATOR_GET_FORM(aForm);
    gOperatorFound[NS_MATHML_OPERATOR_FORM_INFIX] = nsnull;
    gOperatorFound[NS_MATHML_OPERATOR_FORM_POSTFIX] = nsnull;
    gOperatorFound[NS_MATHML_OPERATOR_FORM_PREFIX] = nsnull;

    nsAutoString key(aOperator);
    key.AppendInt(form, 10);
    nsStringKey hkey(key);
    gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hkey);

    // If not found, check if the operator exists perhaps in a different form,
    // in the order of preference: infix, postfix, prefix
    if (!found) {
      if (form != NS_MATHML_OPERATOR_FORM_INFIX) {
        form = NS_MATHML_OPERATOR_FORM_INFIX;
        key.Assign(aOperator);
        key.AppendInt(form, 10);
        nsStringKey hashkey(key);
        gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hashkey);
      }
      if (!found) {
        if (form != NS_MATHML_OPERATOR_FORM_POSTFIX) {
          form = NS_MATHML_OPERATOR_FORM_POSTFIX;
          key.Assign(aOperator);
          key.AppendInt(form, 10);
          nsStringKey hashkey(key);
          gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hashkey);
        }
        if (!found) {
          if (form != NS_MATHML_OPERATOR_FORM_PREFIX) {
            form = NS_MATHML_OPERATOR_FORM_PREFIX;
            key.Assign(aOperator);
            key.AppendInt(form, 10);
            nsStringKey hashkey(key);
            gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hashkey);
          }
        }
      }
    }
    if (found) {
      NS_ASSERTION(found->mStr.Equals(aOperator), "bad setup");
      *aLeftSpace = found->mLeftSpace;
      *aRightSpace = found->mRightSpace;
      *aFlags &= ~NS_MATHML_OPERATOR_FORM; // clear the form bits
      *aFlags |= found->mFlags; // just add bits without overwriting
      return PR_TRUE;
    }
  }
  return PR_FALSE;
}
示例#20
0
/**
@briesf 주어진 Domain/URL 이 statfilter 목록에 포함되는지 확인하고,
포함되는 경우 단말에 보낼 메시지를 버퍼에 저장하고, return 1.

@param keystr  DOMAIN/URL/MDN 값. 입력치.
@param notimesg 이 함수의 결과로 얻는 텍스트 메시지. 단말기에 전달되어야 할 공지 내용.
@param iport DOMAIN 의 port ?
@param iType keystr이 DOMAIN/URL/MDN 중 어느 타입인지 표시하는 것. URL-1, DOMAIN-2, MDN-3

@return 0 statfilter 목록에 포함되지 않는 경우.
*/
bool StatFilter::isBlocked(int iType , char *keystr, int iport,  char* notimesg)
{

	char strhashkey[256];

	notimesg[0] = 0;


	/**
	DOMAIN type 인 경우에는 keystr 값은  포트값이 포함되지 않는다. $HOST
	URL type 경우에는  keystr 값은  포트값이 포함된 URL 이다.  $EURL

	테스트 결과, 지오텔의 소스에서
	$HOST (즉, 도메인, type==2) 에는 포트값이 포함되지 않는다.  포트값이 80이든 아니든.
	$URL (즉, URL type==1) 에는 포트값이 포함된다 (당연).

	*/


	#ifdef DEBUG_NEWSTAT
	printf ("##STAT: org=%s type=%d port =%d : %s\n", keystr, iType, iport, hashkey);
	#endif

	int	notiIndex = -1;
	if (iType==FILTER_BY_MDN)
	{
		intMDN_t mdnKey = Util::phonenum2int(keystr);
		
		map<intMDN_t,  int>::const_iterator pos = mdnList.find(mdnKey);
		if (pos != mdnList.end())
		{
			notiIndex = pos->second;
		}
		if (notiIndex != -1) PAS_INFO3("StatFilter: MDN %s, %d, Res=%d", keystr, mdnKey, notiIndex);
		if (tracelog) tracelog->logprint(LVL_DEBUG, "MDN %s, %d, Res=%d\n", keystr, mdnKey, notiIndex);
		
	}
	else if (iType==FILTER_BY_URL)
	{
		//  Domain 이면 "호스트:포트" 형태의 키값을 만들어야 한다.
		// URL, DOMAIN 의 http:// 를 제거한다.
		normalizeUrl(keystr, iType, iport, strhashkey, sizeof(strhashkey)-1);
		string hashkey(strhashkey);
		
		map<string,  int>::const_iterator pos = urlList.find(hashkey);
		if (pos != urlList.end())
		{
			notiIndex = pos->second;
		}

		if (notiIndex != -1) PAS_INFO3("StatFilter: URL %s, %s, Res=%d", keystr, strhashkey, notiIndex);
		if (tracelog) tracelog->logprint(LVL_DEBUG, "URL %s, %s, Res=%d\n", keystr, strhashkey, notiIndex);
	}
	else if (iType==FILTER_BY_DOMAIN)
	{
		normalizeUrl(keystr, iType, iport, strhashkey, sizeof(strhashkey)-1);
		string hashkey(strhashkey);
		
		map<string,  int>::const_iterator pos = domainList.find(hashkey);
		if (pos != domainList.end())
		{
			notiIndex = pos->second;
		}
		if (notiIndex != -1) PAS_INFO3("StatFilter: DOMAIN %s, %s, Res=%d", keystr, strhashkey, notiIndex);
		if (tracelog) tracelog->logprint(LVL_DEBUG, "DOMAIN %s, %s, Res=%d\n", keystr, strhashkey, notiIndex);
	
	}
	

	if (notiIndex < 0)
		return false;
		
	if (BETWEEN(notiIndex, 0,  MAX_NOTIMESG))
	{
		strcpy(notimesg, notiMesgs[notiIndex].c_str());
	}

	if (notimesg[0] ) 
		return true;
	else 
		return false;
}