📄 upload.c
字号:
{ signalError (utc, _("Application aborted.")); return NULL; } if (GNUNET_YES == GNUNET_disk_directory_test (ectx, utc->filename)) { error = NULL; is_directory = 1; filename = createDirectoryHelper (ectx, utc->shared->ctx->cfg, utc->child, utc->meta, &error); if (filename == NULL) { if (error == NULL) error = GNUNET_strdup (_("Failed to create temporary directory.")); signalError (utc, error); GNUNET_free (error); return NULL; } } else { is_directory = 0; filename = GNUNET_strdup (utc->filename); } utc->start_time = GNUNET_get_time (); mem = GNUNET_GE_memory_create (2); ee = GNUNET_GE_create_context_memory (GNUNET_GE_USER | GNUNET_GE_ADMIN | GNUNET_GE_ERROR | GNUNET_GE_WARNING | GNUNET_GE_FATAL | GNUNET_GE_BULK | GNUNET_GE_IMMEDIATE, mem); ret = GNUNET_ECRS_file_upload (ee, utc->shared->ctx->cfg, filename, utc->shared->doIndex == GNUNET_YES ? (utc->child == NULL ? GNUNET_YES : GNUNET_NO) : utc->shared->doIndex, utc->shared->anonymityLevel, utc->shared->priority, utc->shared->expiration, &progressCallback, utc, &testTerminate, utc, &utc->uri); if (ret != GNUNET_OK) { if (utc->state == GNUNET_FSUI_ACTIVE) { const char *err; err = GNUNET_GE_memory_get (mem, 0); signalError (utc, err ? err : ""); } else if (utc->state == GNUNET_FSUI_ABORTED) { event.type = GNUNET_FSUI_upload_aborted; event.data.UploadAborted.uc.pos = utc; event.data.UploadAborted.uc.cctx = utc->cctx; event.data.UploadAborted.uc.ppos = utc->parent; event.data.UploadAborted.uc.pcctx = utc->parent->cctx; utc->shared->ctx->ecb (utc->shared->ctx->ecbClosure, &event); } else { /* must be suspended */ GNUNET_GE_BREAK (NULL, utc->state == GNUNET_FSUI_PENDING); } if (utc->child != NULL) UNLINK (filename); GNUNET_free (filename); GNUNET_GE_free_context (ee); GNUNET_GE_memory_free (mem); return NULL; } utc->state = GNUNET_FSUI_COMPLETED; if (utc->shared->doIndex != GNUNET_SYSERR) { if (utc->child == NULL) GNUNET_meta_data_extract_from_file (utc->shared->ctx->ectx, utc->meta, utc->filename, utc->shared->extractors); while (GNUNET_OK == GNUNET_meta_data_delete (utc->meta, EXTRACTOR_FILENAME, NULL)); /* only publish the last part of the path -- we do not want to publish $HOME or similar trivially deanonymizing information */ tpos = strlen (utc->filename) - 1; if ((utc->filename[tpos] == DIR_SEPARATOR) && (tpos > 0)) tpos--; while ((tpos > 0) && (utc->filename[tpos] != DIR_SEPARATOR)) tpos--; pfn = GNUNET_malloc (strlen (&utc->filename[tpos + 1]) + 2); strcpy (pfn, &utc->filename[tpos + 1]); if ((is_directory || (utc->child != NULL)) && ((strlen (pfn) == 0) || (pfn[strlen (pfn) - 1] != DIR_SEPARATOR))) strcat (pfn, DIR_SEPARATOR_STR); GNUNET_meta_data_insert (utc->meta, EXTRACTOR_FILENAME, pfn); GNUNET_free (pfn); if (0 != strcmp (utc->shared->top_filename, utc->filename)) { /* this is NOT the top-level upload, so we should add the directory name of our parent to the meta data */ tend = tpos; /* index of '/' */ if ((utc->filename[tpos] == DIR_SEPARATOR) && (tpos > 0)) tpos--; while ((tpos > 0) && (utc->filename[tpos] != DIR_SEPARATOR)) tpos--; if (tpos + 1 < tend) { char *p; pfn = p = GNUNET_malloc (tend - tpos + 1); pfn[tend - tpos] = '\0'; memcpy (pfn, &utc->filename[tpos + 1], tend - tpos); /* change OS native dir separators to unix '/' and others to '_' */ while (*p != '\0') { if (*p == DIR_SEPARATOR) *p = '/'; else if (*p == '\\') *p = '_'; p++; } GNUNET_meta_data_insert (utc->meta, EXTRACTOR_RELATION, pfn); GNUNET_free (pfn); } } if ((utc->shared->anonymityLevel == 0) && (utc->shared->doIndex == GNUNET_YES)) { /* generate location URI for non-anonymous download */ struct GNUNET_ClientServerConnection *sock; GNUNET_MessageHello *hello; sock = GNUNET_client_connection_create (utc->shared->ctx->ectx, utc->shared->ctx->cfg); if (GNUNET_OK == GNUNET_IDENTITY_get_self (sock, &hello)) { loc = GNUNET_ECRS_location_to_uri (utc->uri, &hello->publicKey, ntohl (hello->expiration_time), (GNUNET_ECRS_SignFunction) & GNUNET_IDENTITY_sign_function, sock); GNUNET_free (hello); } else { /* may happen if no transports are available... */ loc = GNUNET_ECRS_uri_duplicate (utc->uri); } GNUNET_client_connection_destroy (sock); } else { /* no location URI, use standard URI (copied here to allow free later) */ loc = GNUNET_ECRS_uri_duplicate (utc->uri); } if (utc->shared->individualKeywords == GNUNET_YES) { /* need to convert to URI *before* removing split/lower from meta */ uri = GNUNET_meta_data_to_uri (utc->meta); } while (GNUNET_OK == GNUNET_meta_data_delete (utc->meta, EXTRACTOR_SPLIT, NULL)); while (GNUNET_OK == GNUNET_meta_data_delete (utc->meta, EXTRACTOR_LOWERCASE, NULL)); if (utc->shared->individualKeywords == GNUNET_YES) { GNUNET_ECRS_publish_under_keyword (ectx, utc->shared->ctx->cfg, uri, utc->shared->anonymityLevel, utc->shared->priority, utc->shared->expiration, loc, utc->meta); GNUNET_ECRS_uri_destroy (uri); } if (utc->shared->global_keywords != NULL) GNUNET_ECRS_publish_under_keyword (ectx, utc->shared->ctx->cfg, utc->shared->global_keywords, utc->shared->anonymityLevel, utc->shared->priority, utc->shared->expiration, loc, utc->meta); if (utc->keywords != NULL) GNUNET_ECRS_publish_under_keyword (ectx, utc->shared->ctx->cfg, utc->keywords, utc->shared->anonymityLevel, utc->shared->priority, utc->shared->expiration, loc, utc->meta); GNUNET_ECRS_uri_destroy (loc); loc = NULL; fi.meta = utc->meta; fi.uri = utc->uri; if (utc->shared->doIndex != GNUNET_SYSERR) { GNUNET_URITRACK_track (ectx, utc->shared->ctx->cfg, &fi); GNUNET_URITRACK_add_state (ectx, utc->shared->ctx->cfg, utc->uri, utc->shared->doIndex == GNUNET_YES ? GNUNET_URITRACK_INDEXED : GNUNET_URITRACK_INSERTED); } } event.type = GNUNET_FSUI_upload_completed; event.data.UploadCompleted.uc.pos = utc; event.data.UploadCompleted.uc.cctx = utc->cctx; event.data.UploadCompleted.uc.ppos = utc->parent; event.data.UploadCompleted.uc.pcctx = utc->parent->cctx; event.data.UploadCompleted.total = utc->total; event.data.UploadCompleted.filename = utc->filename; event.data.UploadCompleted.uri = utc->uri; utc->shared->ctx->ecb (utc->shared->ctx->ecbClosure, &event); if (utc->child != NULL) UNLINK (filename); GNUNET_free (filename); GNUNET_GE_free_context (ee); GNUNET_GE_memory_free (mem); return NULL;}/** * Thread that does the upload. */static void *GNUNET_FSUI_uploadThreadEvent (void *cls){ GNUNET_FSUI_UploadList *utc = cls; if (utc->parent == &utc->shared->ctx->activeUploads) { /* top-level call: signal client! */ signalUploadStarted (utc, 1); } return GNUNET_FSUI_uploadThread (utc);}static voidfreeUploadList (struct GNUNET_FSUI_UploadList *ul){ struct GNUNET_FSUI_UploadList *next; struct GNUNET_FSUI_Context *ctx; ctx = ul->shared->ctx; while (ul->child != NULL) freeUploadList (ul->child); GNUNET_mutex_lock (ctx->lock); GNUNET_free (ul->filename); if (ul->keywords != NULL) GNUNET_ECRS_uri_destroy (ul->keywords); if (ul->uri != NULL) { GNUNET_ECRS_uri_destroy (ul->uri); ul->uri = NULL; } if (ul->meta != NULL) { GNUNET_meta_data_destroy (ul->meta); ul->meta = NULL; } /* unlink from parent */ next = ul->parent->child; if (next == NULL) { GNUNET_GE_BREAK (NULL, 0); GNUNET_mutex_unlock (ctx->lock); return; } if (next == ul) { ul->parent->child = ul->next; } else { while (next->next != ul) { next = next->next; if (next == NULL) { GNUNET_GE_BREAK (NULL, 0); GNUNET_mutex_unlock (ctx->lock); return; } } next->next = ul->next; } GNUNET_free (ul); GNUNET_mutex_unlock (ctx->lock);}static struct GNUNET_FSUI_UploadList *addUploads (struct GNUNET_FSUI_UploadShared *shared, const char *filename, const struct GNUNET_ECRS_URI *keywords, const struct GNUNET_MetaData *md, struct GNUNET_FSUI_UploadList *parent);static intaddChildUpload (const char *name, const char *dirName, void *data){ struct GNUNET_FSUI_UploadList *parent = data; char *filename; struct GNUNET_FSUI_UploadList *child; struct GNUNET_MetaData *md_tmp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -