Пример #1
0
/**
 * We have received a KSK result.  Check how it fits in with the
 * overall query and notify the client accordingly.
 *
 * @param sc context for the overall query
 * @param ent entry for the specific keyword
 * @param uri the URI that was found
 * @param meta metadata associated with the URI
 *        under the @a ent keyword
 */
static void
process_ksk_result (struct GNUNET_FS_SearchContext *sc,
                    struct SearchRequestEntry *ent,
                    const struct GNUNET_FS_Uri *uri,
                    const struct GNUNET_CONTAINER_MetaData *meta)
{
  struct GNUNET_HashCode key;
  struct GNUNET_FS_SearchResult *sr;
  struct GetResultContext grc;
  int is_new;
  unsigned int koff;

  /* check if new */
  GNUNET_assert (NULL != sc);
  GNUNET_FS_uri_to_key (uri, &key);
  if (GNUNET_SYSERR ==
      GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, &key,
                                                  &test_result_present,
                                                  (void *) uri))
    return;                     /* duplicate result */
  /* try to find search result in master map */
  grc.sr = NULL;
  grc.uri = uri;
  GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
                                              &get_result_present, &grc);
  sr = grc.sr;
  is_new = (NULL == sr) || (sr->mandatory_missing > 0);
  if (NULL == sr)
  {
    sr = GNUNET_new (struct GNUNET_FS_SearchResult);
    sr->h = sc->h;
    sr->sc = sc;
    sr->anonymity = sc->anonymity;
    sr->uri = GNUNET_FS_uri_dup (uri);
    sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
    sr->mandatory_missing = sc->mandatory_count;
    sr->key = key;
    sr->keyword_bitmap = GNUNET_malloc ((sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
    GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr,
                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
  }
Пример #2
0
DownloadItem* DownloadsModel::addDownload(DownloadItem *pde, struct GNUNET_FS_DownloadContext *dc,
                                          const struct GNUNET_FS_Uri *uri, QString filePath,
                                          const struct GNUNET_CONTAINER_MetaData *meta, qint64 size,
                                          qint64 completed )
{


    //Convert uri to Key
    GNUNET_HashCode hashcode;
    GNUNET_FS_uri_to_key(uri,&hashcode);

    //Get as QString
    const char * hash = GNUNET_h2s_full(&hashcode);
    QString strHash = QString(hash);



    DownloadItem* download = new DownloadItem(strHash);

    download->setParent(pde);
    download->setContext(dc);
    char* fancyName =  GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
                                                                 EXTRACTOR_METATYPE_PACKAGE_NAME,
                                                                 EXTRACTOR_METATYPE_TITLE,
                                                                 EXTRACTOR_METATYPE_BOOK_TITLE,
                                                                 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
                                                                 EXTRACTOR_METATYPE_FILENAME,
                                                                 EXTRACTOR_METATYPE_DESCRIPTION,
                                                                 EXTRACTOR_METATYPE_SUMMARY,
                                                                 EXTRACTOR_METATYPE_ALBUM,
                                                                 EXTRACTOR_METATYPE_COMMENT,
                                                                 EXTRACTOR_METATYPE_SUBJECT,
                                                                 EXTRACTOR_METATYPE_KEYWORDS,
                                                                 -1);

    char* fileName =  GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
                                                                 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
                                                                 EXTRACTOR_METATYPE_PACKAGE_NAME,
                                                                 EXTRACTOR_METATYPE_TITLE,
                                                                 EXTRACTOR_METATYPE_BOOK_TITLE,
                                                                 EXTRACTOR_METATYPE_FILENAME,
                                                                 EXTRACTOR_METATYPE_DESCRIPTION,
                                                                 EXTRACTOR_METATYPE_SUMMARY,
                                                                 EXTRACTOR_METATYPE_ALBUM,
                                                                 EXTRACTOR_METATYPE_COMMENT,
                                                                 EXTRACTOR_METATYPE_SUBJECT,
                                                                 EXTRACTOR_METATYPE_KEYWORDS,
                                                                 -1);



    download->setPath(filePath);
    download->setFancyName(QString(fancyName));
    download->setFileName(QString(fileName));
    download->setMetadata(meta);
    download->setSize(size);
    download->setCompleted(completed);


    emit addDownloadSignal(download);

    return download;


}