Пример #1
0
int main (int argc, char *argv[])
{
  char buff[1024];
  char *s;
  
  struct sig **lastsig = NULL;
  struct uid **lastuid = NULL;
  struct key *k = new_key();
  
  lastuid = &k->uids;

  if (argc == 2 && !strcmp (argv[1], "-S"))
    DontRequireSelfSig = 1;

  while (fgets (buff, sizeof (buff), stdin))
  {
    if ((s = strtok (buff, ":")))
    {
      if (!strcmp (s, "pub"))
      {
	do_key (k);
	k->rev = 0;
	k->uids = new_uid();

	lastuid = &k->uids->next;
	lastsig = &k->uids->sigs;

	strtok (NULL, ":");
	strtok (NULL, ":");
	strtok (NULL, ":");

	sprintf (k->id, "%s", strtok (NULL, ":"));
      }
      else if (!strcmp (s, "rev"))
	k->rev = 1;
      else if (!strcmp (s, "uid"))
      {
	struct uid *uid = *lastuid = new_uid();
	lastuid = &(*lastuid)->next;
	lastsig = &uid->sigs;
      }
      else if (!strcmp (s, "sig"))
      {
	struct sig *sig = *lastsig = new_sig();
	lastsig = &sig->next;
	sprintf (sig->id, "%s", strtok (NULL, ":"));
      }
    }
  }
  
  do_key (k);
  
  return 0;
}
Пример #2
0
sig* insert_sig_node(unsigned long long sign) {

  hash_dict_node_t snode;
  int res;
  sig *sig_q;
  //char s;
  //if (dimension < 10) s = (char) dimension + '0';
  //else if (dimension < 36) s = (char) dimension - 10 + 'a';
  //else s = (char) dimension - 36 + '_';
  //printf("%llu\n", sign);
  snode.sign1 = (sign >> 32) + 1;
  //printf("%u ", snode.sign1);
  snode.sign2 = (sign << 32) >> 32;
  //printf("%u ;", snode.sign2);

  if (hash_dict_search(_sig_index_hash_dict, &snode) == RT_HASH_DICT_SEARCH_SUCC) {
    sig_q = (sig *) snode.pointer;
    sig_q->frq++;
  } else {
    if ((sig_q = new_sig()) == NULL) {
      fprintf(stderr, "ERROR: Out of memory \n");
      exit(-1);
    }
    //sig_q->sign = ((unsigned long long)snode.sign1 << 32) + (unsigned long long)snode.sign2;
    //sig_q->sign = sign;
    sig_q->idf_list = NULL;
    //sig_q->pfx_num = 0;
    sig_q->frq = 1;
    sig_q->last_idf = 0;
    //sig_q->buffer = (char *) malloc(sizeof (char) * Q * MAX_ELEMENT_LEN);
    //strcpy(sig_q->buffer, sig_buffer);
    g_sig_num++;
    snode.pointer = (void *) sig_q;
    res = hash_dict_add(_sig_index_hash_dict, &snode, 0);
    // insert it into hash_dict
    if (res != RT_HASH_DICT_ADD_SUCC && res != RT_HASH_DICT_ADD_EXIST) {
      fprintf(stderr, "Error, insert a sig node into hash dict error \n");
      return NULL;
    }
  }
  return sig_q;
}