Beispiel #1
0
/**
 * Add a pseudonym to the set of known pseudonyms.
 * For all pseudonym advertisements that we discover
 * FS should automatically call this function.
 *
 * @param cfg overall configuration
 * @param id the pseudonym identifier
 * @param meta metadata for the pseudonym
 */
void
GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
                      const struct GNUNET_HashCode * id,
                      const struct GNUNET_CONTAINER_MetaData *meta)
{
  char *name;
  int32_t ranking;
  struct GNUNET_CONTAINER_MetaData *old;
  char *fn;
  struct stat sbuf;

  ranking = 0;
  fn = get_data_filename (cfg, PS_METADATA_DIR, id);
  GNUNET_assert (fn != NULL);

  if ((0 == STAT (fn, &sbuf)) &&
      (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name)))
  {
    GNUNET_CONTAINER_meta_data_merge (old, meta);
    write_pseudonym_info (cfg, id, old, ranking, name);
    GNUNET_CONTAINER_meta_data_destroy (old);
    GNUNET_free_non_null (name);
  }
  else
  {
    write_pseudonym_info (cfg, id, meta, ranking, NULL);
  }
  GNUNET_free (fn);
  internal_notify (id, meta, ranking);
}
Beispiel #2
0
/**
 * read the pseudonym infomation from a file
 * @param cfg configuration to use
 * @param nsid hash code of a pseudonym
 * @param meta meta data to be read from a file
 * @param ranking ranking of a pseudonym
 * @param ns_name name of a pseudonym
 */
static int
read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
           const struct GNUNET_HashCode * nsid,
           struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking,
           char **ns_name)
{
  char *fn;
  char *emsg;
  struct GNUNET_BIO_ReadHandle *fileR;

  fn = get_data_filename (cfg, PS_METADATA_DIR, nsid);
  GNUNET_assert (fn != NULL);
  if (GNUNET_YES !=
      GNUNET_DISK_file_test (fn))
  {
    GNUNET_free (fn);
    return GNUNET_SYSERR;
  }
  fileR = GNUNET_BIO_read_open (fn);
  if (fileR == NULL)
  {
    GNUNET_free (fn);
    return GNUNET_SYSERR;
  }
  emsg = NULL;
  *ns_name = NULL;
  if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) ||
      (GNUNET_OK !=
       GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) ||
      (GNUNET_OK !=
       GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta)))
  {
    (void) GNUNET_BIO_read_close (fileR, &emsg);
    GNUNET_free_non_null (emsg);
    GNUNET_free_non_null (*ns_name);
    *ns_name = NULL;
    GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
    GNUNET_free (fn);
    return GNUNET_SYSERR;
  }
  if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg))
  {
    LOG (GNUNET_ERROR_TYPE_WARNING,
         _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fn,
         emsg);
    GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
    GNUNET_CONTAINER_meta_data_destroy (*meta);
    *meta = NULL;
    GNUNET_free_non_null (*ns_name);
    *ns_name = NULL;
    GNUNET_free_non_null (emsg);
    GNUNET_free (fn);
    return GNUNET_SYSERR;
  }
  GNUNET_free (fn);
  return GNUNET_OK;
}
Beispiel #3
0
/**
 * Get the namespace ID belonging to the given namespace name.
 *
 * @param cfg configuration to use
 * @param ns_uname unique (!) human-readable name for the namespace
 * @param nsid set to namespace ID based on 'ns_uname'
 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
 */
int
GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
    const char *ns_uname, struct GNUNET_HashCode * nsid)
{
  size_t slen;
  uint64_t len;
  unsigned int idx;
  char *name;
  struct GNUNET_HashCode nh;
  char *fn;
  struct GNUNET_DISK_FileHandle *fh;

  idx = -1;
  slen = strlen (ns_uname);
  while ((slen > 0) && (1 != SSCANF (&ns_uname[slen - 1], "-%u", &idx)))
    slen--;
  if (slen == 0)
    return GNUNET_SYSERR;
  name = GNUNET_strdup (ns_uname);
  name[slen - 1] = '\0';

  GNUNET_CRYPTO_hash (name, strlen (name), &nh);
  GNUNET_free (name);
  fn = get_data_filename (cfg, PS_NAMES_DIR, &nh);
  GNUNET_assert (fn != NULL);

  if ((GNUNET_OK != GNUNET_DISK_file_test (fn) ||
       (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES))) ||
      ((idx + 1) * sizeof (struct GNUNET_HashCode) > len))
  {
    GNUNET_free (fn);
    return GNUNET_SYSERR;
  }
  fh = GNUNET_DISK_file_open (fn,
                              GNUNET_DISK_OPEN_CREATE |
                              GNUNET_DISK_OPEN_READWRITE,
                              GNUNET_DISK_PERM_USER_READ |
                              GNUNET_DISK_PERM_USER_WRITE);
  GNUNET_free (fn);
  if (GNUNET_SYSERR ==
      GNUNET_DISK_file_seek (fh, idx * sizeof (struct GNUNET_HashCode),
			     GNUNET_DISK_SEEK_SET))
  {
    GNUNET_DISK_file_close (fh);
    return GNUNET_SYSERR;
  }
  if (sizeof (struct GNUNET_HashCode) !=
      GNUNET_DISK_file_read (fh, nsid, sizeof (struct GNUNET_HashCode)))
  {
    GNUNET_DISK_file_close (fh);
    return GNUNET_SYSERR;
  }
  GNUNET_DISK_file_close (fh);
  return GNUNET_OK;
}
Beispiel #4
0
/**
 * Return unique variant of the namespace name.
 * Use it after GNUNET_PSEUDONYM_get_info() to make sure
 * that name is unique.
 *
 * @param cfg configuration
 * @param nsid cryptographic ID of the namespace
 * @param name name to uniquify
 * @param suffix if not NULL, filled with the suffix value
 * @return NULL on failure (should never happen), name on success.
 *         Free the name with GNUNET_free().
 */
char *
GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
    const struct GNUNET_HashCode * nsid, const char *name, unsigned int *suffix)
{
  struct GNUNET_HashCode nh;
  uint64_t len;
  char *fn;
  struct GNUNET_DISK_FileHandle *fh;
  unsigned int i;
  unsigned int idx;
  char *ret;
  struct stat sbuf;

  GNUNET_CRYPTO_hash (name, strlen (name), &nh);
  fn = get_data_filename (cfg, PS_NAMES_DIR, &nh);
  GNUNET_assert (fn != NULL);

  len = 0;
  if (0 == STAT (fn, &sbuf))
    GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES));
  fh = GNUNET_DISK_file_open (fn,
                              GNUNET_DISK_OPEN_CREATE |
                              GNUNET_DISK_OPEN_READWRITE,
                              GNUNET_DISK_PERM_USER_READ |
                              GNUNET_DISK_PERM_USER_WRITE);
  i = 0;
  idx = -1;
  while ((len >= sizeof (struct GNUNET_HashCode)) &&
         (sizeof (struct GNUNET_HashCode) ==
          GNUNET_DISK_file_read (fh, &nh, sizeof (struct GNUNET_HashCode))))
  {
    if (0 == memcmp (&nh, nsid, sizeof (struct GNUNET_HashCode)))
    {
      idx = i;
      break;
    }
    i++;
    len -= sizeof (struct GNUNET_HashCode);
  }
  if (idx == -1)
  {
    idx = i;
    if (sizeof (struct GNUNET_HashCode) !=
        GNUNET_DISK_file_write (fh, nsid, sizeof (struct GNUNET_HashCode)))
      LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn);
  }
  GNUNET_DISK_file_close (fh);
  ret = GNUNET_malloc (strlen (name) + 32);
  GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx);
  if (suffix != NULL)
    *suffix = idx;
  GNUNET_free (fn);
  return ret;
}
Beispiel #5
0
/**
 * List all available pseudonyms.
 *
 * @param cfg overall configuration
 * @param iterator function to call for each pseudonym
 * @param closure closure for iterator
 * @return number of pseudonyms found
 */
int
GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
                           GNUNET_PSEUDONYM_Iterator iterator, void *closure)
{
  struct ListPseudonymClosure cls;
  char *fn;
  int ret;

  cls.iterator = iterator;
  cls.closure = closure;
  cls.cfg = cfg;
  fn = get_data_filename (cfg, PS_METADATA_DIR, NULL);
  GNUNET_assert (fn != NULL);
  GNUNET_DISK_directory_create (fn);
  ret = GNUNET_DISK_directory_scan (fn, &list_pseudonym_helper, &cls);
  GNUNET_free (fn);
  return ret;
}
Beispiel #6
0
/**
 * Write the pseudonym infomation into a file
 * @param cfg configuration to use
 * @param nsid hash code of a pseudonym
 * @param meta meta data to be written into a file
 * @param ranking ranking of a pseudonym
 * @param ns_name non-unique name of a pseudonym
 */
static void
write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
                      const struct GNUNET_HashCode * nsid,
                      const struct GNUNET_CONTAINER_MetaData *meta,
                      int32_t ranking, const char *ns_name)
{
  char *fn;
  struct GNUNET_BIO_WriteHandle *fileW;

  fn = get_data_filename (cfg, PS_METADATA_DIR, nsid);
  GNUNET_assert (fn != NULL);
  fileW = GNUNET_BIO_write_open (fn);
  if (NULL != fileW)
  {
    if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) ||
        (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) ||
        (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta)))
    {
      (void) GNUNET_BIO_write_close (fileW);
      GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
      GNUNET_free (fn);
      return;
    }
    if (GNUNET_OK != GNUNET_BIO_write_close (fileW))
    {
      GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
      GNUNET_free (fn);
      return;
    }
  }
  GNUNET_free (fn);
  /* create entry for pseudonym name in names */
  if (ns_name != NULL)
    GNUNET_free_non_null (GNUNET_PSEUDONYM_name_uniquify (cfg, nsid, ns_name,
        NULL));
}
Beispiel #7
0
int main(int argc, char **argv)
{ 
  char filename[256]; 

  if ( argc <= 1 )
    show_usage();

  parse_args(argc, argv);
  if ( !option_valid )
    show_usage();
	
  show_version();  
  printf("\n");

  get_data_filename(SCE_DATA_KEYS, filename);
  if (load_keysets(filename)) {
    if (verbose)
      printf("[*] Loaded keysets.\n");
  } else {
    if (cmd_print_keysets) {
      printf("[*] Error: Could not load keys.\n");
      return 0;
    }
    printf("[*] Warning: Could not load keys.\n");
  }

  // loader curves
  get_data_filename(SCE_DATA_LDR_CURVES, filename);
  if ( load_ldr_curves(filename) ) {
    if ( verbose )
      printf("[*] Loaded loader curves.\n");
  } else {
    printf("[*] Warning: Could not load loader curves.\n");
  }

  // vsh curves
  get_data_filename(SCE_DATA_VSH_CURVES, filename);
  if ( load_vsh_curves(filename) ) {
    if ( verbose )
      printf("[*] Loaded loader curves.\n");
  } else {
    printf("[*] Warning: Could not load loader curves.\n");
  }

  if (klicensee_value) {
    if ( strlen(klicensee_value) != 32 ) {
      printf("[*] Error: klicensee needs to be 16 bytes.\n");
      return 0;
    }
    klicensee = x_to_u8_buffer(klicensee_value);
  } else {
    get_data_filename(SCE_DATA_KLICS, filename);
    if ( load_klicensees(filename) ) {
      if ( verbose )
        printf("[*] Loaded klicensees.\n");
    } else {
      if ( verbose )
        printf("[*] Warning: Could not load klicenseees.\n");
    }
  }

  if (cmd_print_keysets) {
    printf("[*] Loaded keysets:\n");
    print_keysets(stdout);
  } else if (cmd_print) {
    backend_cmd_print();
  } else if (cmd_decrypt) {
    backend_cmd_decrypt();   
  } else if (cmd_encrypt) {
    backend_cmd_encrypt();
  }
  return 0;
}
Beispiel #8
0
bool sfx_load_file(struct sfx * sfx, const char * filename)
{
  bool rv;
  char fn[1024];

  rv = false;

  if(filename != NULL)
    snprintf(fn, sizeof fn, "%s", filename);
  else
    snprintf(fn, sizeof fn, "%s/%s.wav", get_data_filename("sfx"), sfx->base_filename);

  SNDFILE * fp;
  SF_INFO info;

  info.format = 0;
  fp = sf_open(fn, SFM_READ, &info);
  if(fp != NULL)
    {
      bool done;
      int16_t * wav;
      int wavlen;

      done = false;
      wav = NULL;
      wavlen = 0;
      while(done == false)
        {
          int n;
          float buf[128];

          n = sf_read_float(fp, buf, 128);
          if(n > 0)
            {
              int16_t * tmp;

              tmp = realloc(wav, (wavlen + n) * sizeof(int16_t));
              assert(tmp != NULL);
              if(tmp != NULL)
                {
                  wav = tmp;
                  for(int i = 0; i < n; i++)
                    wav[wavlen + i] = buf[i] * 32767.0f;
                  wavlen += n;
                }
            }
          if(n < 128)
            done = true;
        }
      
      sf_close(fp);

      alGenBuffers(1, &sfx->openal_buffer);
      alBufferData(sfx->openal_buffer, AL_FORMAT_MONO16, wav, wavlen * sizeof(int16_t), 44100);
      rv = true;

      free(wav);
    }
  
  return rv;
}
void widget_new_trait_info_window(trait_t trait, bool enable_controls)
{
  struct trait * traitdata;
  
  traitdata = trait_get(trait);
  if(traitdata != NULL)
    {
      char buf[128];
      struct widget * window;

      snprintf(buf, sizeof buf, "%s: %s", gettext("Trait"), trait_get_name(trait));
      window = widget_new_window(widget_root(), 420, 200, buf);
      assert(window != NULL);
      if(window != NULL)
        {
          int y;

          widget_set_modal(window);
          widget_set_image_pointer(window, "raw_image", gfx_image(traitdata->image_id));
          widget_set_widget_pointer(window, "previously_selected_object", widget_focus());

          y = 40 + font_height();

          char ** description;
          char fn[1024];
          
          snprintf(fn, sizeof fn, "data/trait-%s", traitdata->filename);
          description = read_localized_text_file(get_data_filename(fn));
          if(description != NULL)
            {
              for(int i = 0; description[i] != NULL; i++)
                {
                  widget_new_text(window, 10, y, description[i]);
                  free(description[i]);
                  y += font_height();
                }
              free(description);
            }

          y += font_height() * 2;

          struct widget * prev;
          
          prev = NULL;
          if(enable_controls)
            {
              if(traits_get_active() & trait)
                {
                  struct widget * t;

                  t = widget_new_text(window, 10, y, gettext("You have this trait."));
                  if(traits_get_active() & TRAIT_RECYCLER)
                    {
                      struct widget * b;

                      snprintf(buf + 1, (sizeof buf) - 1, gettext("Recycle for %lu"), (long unsigned) traitdata->cost * 90 / 100);
                      buf[0] = ' '; snprintf(buf + strlen(buf), sizeof buf - strlen(buf), " "); /* Pad with spaces */
                      b = widget_new_button(window, widget_x(t) + widget_width(t) + 10, y, buf);
                      widget_set_on_release(b, on_recycle_trait_clicked);
                      widget_set_ulong(b, "trait", trait);
                      y += widget_height(b);
                      prev = b;
                    }
                  y += font_height();

                  if(trait == TRAIT_EDIT)
                    {
                      struct widget * b;

                      y += font_height();
                      snprintf(buf, sizeof buf, " %s ", gettext("Edit cave"));
                      b = widget_new_button(window, 0, y, buf);
                      widget_set_on_release(b, on_edit_trait_clicked);
                      widget_center_horizontally(b);
                      y += widget_height(b);
                      if(prev != NULL)
                        widget_set_navigation_updown(prev, b);
                      prev = b;
                    }
              
                  y += font_height();
                }
              else if(traits_get_available() & trait)
                {
                  struct widget * t;
                  
                  t = widget_new_text(window, 10, y, gettext("You don't have this trait."));
                  if(traits_get_score() >= traitdata->cost)
                    {
                      struct widget * b;

                      snprintf(buf, sizeof buf, " %s ", gettext("Buy"));
                      b = widget_new_button(window, widget_x(t) + widget_width(t) + 10, y, buf);
                      widget_set_on_release(b, on_buy_trait_clicked);
                      widget_set_ulong(b, "trait", trait);
                      if(prev != NULL)
                        widget_set_navigation_updown(prev, b);
                      prev = b;
                    }
                  y += font_height();
                  
                  widget_new_text(window, 10, y, gettext("Cost:"));
                  snprintf(buf, sizeof buf, "%u", (unsigned int) traitdata->cost);
                  widget_new_text(window, 100, y, buf);
                  y += font_height();
                  
                  widget_new_text(window, 10, y, gettext("You have:"));
                  snprintf(buf, sizeof buf, "%u", (unsigned int) traits_get_score());
                  if( ! (traits_get_active() & trait) )
                    if(traits_get_score() < traitdata->cost)
                      snprintf(buf + strlen(buf), sizeof buf - strlen(buf), gettext(" [need %u more]"), (unsigned int) (traitdata->cost - traits_get_score()));
                  widget_new_text(window, 100, y, buf);
                  y += font_height();
                }
              else
                {
                  unsigned int level;
                  
                  level = traitdata->cave_level;
                  if(level == 0)
                    level = get_cave_level_count(traitdata->cave_name);
                  snprintf(buf, sizeof buf, gettext("Level required: %u"), level);
                  widget_new_text(window, 10, y, buf);
                  y += font_height();
                }

              y += font_height();
            }

          struct widget * closebutton;

          snprintf(buf, sizeof buf, "  %s  ", gettext("Close"));
          closebutton = widget_new_button(window, 0, y, buf);
          widget_set_x(closebutton, (widget_width(window) - widget_width(closebutton)) / 2);
          widget_set_focus(closebutton);
          y += widget_height(closebutton);
          if(prev != NULL)
            widget_set_navigation_updown(prev, closebutton);


          widget_resize_to_fit_children(window);
          widget_set_width(window, widget_width(window) + 10);
          widget_set_height(window, widget_height(window) + 10);
          widget_center(window);

          ui_wait_for_window_close(window, closebutton);
        }
    }
}