[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r139 - in GNUnet: . src/applications/fs/tools src/include s
From: |
grothoff |
Subject: |
[GNUnet-SVN] r139 - in GNUnet: . src/applications/fs/tools src/include src/util |
Date: |
Mon, 31 Jan 2005 19:54:33 -0800 (PST) |
Author: grothoff
Date: 2005-01-31 19:54:32 -0800 (Mon, 31 Jan 2005)
New Revision: 139
Modified:
GNUnet/src/applications/fs/tools/gnunet-insert.c
GNUnet/src/applications/fs/tools/gnunet-pseudonym.c
GNUnet/src/include/gnunet_util.h
GNUnet/src/util/checksum.c
GNUnet/todo
Log:
utf8 conversion for gnunet-insert
Modified: GNUnet/src/applications/fs/tools/gnunet-insert.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-insert.c 2005-02-01 03:31:17 UTC
(rev 138)
+++ GNUnet/src/applications/fs/tools/gnunet-insert.c 2005-02-01 03:54:32 UTC
(rev 139)
@@ -20,7 +20,7 @@
/**
* @file applications/fs/tools/gnunet-insert.c
- * @brief Tool to insert or index files into GNUnet's AFS.
+ * @brief Tool to insert or index files into GNUnet's FS.
* @author Christian Grothoff
* @author Krista Bennett
* @author James Blackwell
@@ -30,11 +30,8 @@
* Todo:
* - implement namespace insertion
* - check that the various options still work
- * - utf-8 conversion of keywords (from the CMD-line)
* - allow any kind of meta-data attribute (currently only
* description, filename and mime-type can be specified)
- * - do not use plain sleep to wait for completion (better:
- * use the shutdown semaphore (signal or completion))
*/
#include "platform.h"
@@ -42,6 +39,7 @@
#include <langinfo.h>
+
/* hmm. Man says time.h, but that doesn't yield the
prototype. Strange... */
extern char *strptime(const char *s,
@@ -53,178 +51,75 @@
static int errorCode = 0;
/**
- * We're done with the upload of the file, do the
- * post-processing.
+ * Meta-data for the main file.
*/
-static void postProcess(const struct ECRS_URI * uri) {
-#if 0
- /* if SBlock requested create SBlock */
- if (pname != NULL) {
- HashCode160 thisId;
- HashCode160 nextId;
- char * hx;
- SBlock * sb;
- TIME_T creationTime;
- TIME_T now;
+static struct ECRS_MetaData * meta;
- GNUNET_ASSERT(fileNameCount == 1);
- shortFN = getConfigurationString("GNUNET-INSERT",
- "FILENAME");
- fileName = expandFileName(fileNames[0]);
- if ( (shortFN == NULL) && (fileName != NULL)) {
- shortFN = &fileName[strlen(fileName)-1];
- while ( (shortFN[-1] != DIR_SEPARATOR) &&
- (shortFN != fileName) )
- shortFN--;
- shortFN = STRDUP(shortFN);
- }
- FREENONNULL(fileName);
- timestr = getConfigurationString("GNUNET-INSERT",
- "INSERTTIME");
- if (timestr != NULL) {
- struct tm t;
+static struct FSUI_Context * ctx;
- /* we can assert here: input was verified earlier! */
- GNUNET_ASSERT(NULL != strptime(timestr, "%j-%m-%Y %R", &t));
- now = mktime(&t);
- FREE(timestr);
- /* On my system, the printed time is in advance +1h
- to what was specified? -- It is in UTC! */
- timestr = GN_CTIME(&now);
- LOG(LOG_DEBUG,
- "Read time '%s'.\n",
- timestr);
- FREE(timestr);
- } else {
- /* use current time */
- TIME(&now);
- }
- /* determine update frequency / policy */
- prevname = getConfigurationString("GNUNET-INSERT",
- "PREVIOUS_SBLOCK");
- if (prevname != NULL) {
- FREE(prevname);
- /* now, compute CURRENT ID and next ID from SBlock 'pb' */
- computeIdAtTime(&pb,
- now,
- &thisId);
- /* interval was read and verified earlier... */
- if (interval != SBLOCK_UPDATE_SPORADIC) {
- int delta;
-
- /* periodic update */
- delta = now - ntohl(pb.creationTime);
- delta = delta / ntohl(pb.updateInterval);
- if (delta <= 0)
- delta = 1; /* force to be in the future from the updated block! */
- creationTime = ntohl(pb.creationTime) + delta *
ntohl(pb.updateInterval);
+static char ** topKeywords = NULL;
+int topKeywordCnt = 0;
+static char ** gloKeywords = NULL;
+int gloKeywordCnt = 0;
- /* periodic update, compute _next_ ID as increment! */
- addHashCodes(&thisId,
- &pb.identifierIncrement,
- &nextId); /* n = k + inc */
- } else { /* interval == SBLOCK_UPDATE_SPORADIC */
- creationTime = now;
- LOG(LOG_DEBUG,
- "Sporadic update in sblock.\n");
- hx = getConfigurationString("GNUNET-INSERT",
- "NEXTHASH");
- if (hx == NULL) {
- makeRandomId(&nextId);
- } else {
- tryhex2hashOrHashString(hx, &nextId);
- FREE(hx);
- }
- }
- } else {
- /* no previous sblock specified */
- creationTime = now;
- interval = getConfigurationInt("GNUNET-INSERT",
- "INTERVAL");
- hx = getConfigurationString("GNUNET-INSERT",
- "THISHASH");
- tryhex2hashOrHashString(hx, &thisId);
- FREENONNULL(hx);
- hx = getConfigurationString("GNUNET-INSERT",
- "NEXTHASH");
- if (hx == NULL) {
- if (interval == SBLOCK_UPDATE_NONE) {
- /* no next id and no interval specified, to be */
- /* consistent with gnunet-gtk, nextId == thisId */
- memcpy(&nextId,
- &thisId,
- sizeof(HashCode160));
- } else {
- makeRandomId(&nextId);
- }
- } else {
- tryhex2hashOrHashString(hx, &nextId);
- if (interval == SBLOCK_UPDATE_NONE) {
- /* if next was specified, aperiodic is default */
- interval = SBLOCK_UPDATE_SPORADIC;
- }
- FREE(hx);
- }
- if (testConfigurationString("GNUNET-INSERT",
- "SPORADIC",
- "YES"))
- interval = SBLOCK_UPDATE_SPORADIC;
- }
-
- /* finally we can create the SBlock */
- sb = buildSBlock(pseudonym,
- &fid,
- description,
- shortFN,
- mimetype,
- creationTime,
- interval,
- &thisId,
- &nextId);
- freePrivateKey(pseudonym);
- hash(&sb->subspace,
- sizeof(PublicKey),
- &hc);
- if (OK == insertSBlock(sock,
- sb)) {
- char * outname;
- char * uri;
-
- outname = getConfigurationString("GNUNET-INSERT",
- "OUTPUT_SBLOCK");
- if (outname != NULL) {
- SBlock plainSBlock;
- decryptSBlock(&thisId,
- sb,
- &plainSBlock);
- writeFile(outname,
- &plainSBlock,
- sizeof(SBlock),
- "600");
- FREE(outname);
- }
- uri = createSubspaceURI(&hc,
- &thisId);
- printf(_("File '%s' (%s, %s) successfully inserted into namespace
under\n"
- "\t'%s'\n"),
- shortFN,
- description,
- mimetype,
- uri);
- FREE(uri);
- } else {
- printf(_("Insertion of file into namespace failed.\n"));
- }
- FREE(sb);
- FREE(shortFN);
- }
-#endif
-}
+/**
+ * We're done with the upload of the file, do the
+ * post-processing.
+ */
+static void postProcess(const struct ECRS_URI * uri) {
+ char * pname;
+ HashCode160 prevId;
+ HashCode160 thisId;
+ HashCode160 nextId;
+ char * pid;
+ char * tid;
+ char * nid;
+ struct ECRS_URI * nsuri;
+ unsigned int updateInterval;
+ pname = getConfigurationString("GNUNET-INSERT",
+ "PSEUDONYM");
+ if (pname == NULL)
+ return;
+ pid = NULL; /* FIXME */
+ if (pid != NULL)
+ enc2hash(pid, &prevId);
+ tid = getConfigurationString("GNUNET-INSERT",
+ "THISHASH");
+ if (tid != NULL)
+ enc2hash(tid, &thisId);
+ nid = getConfigurationString("GNUNET-INSERT",
+ "NEXTHASH");
+ if (nid != NULL)
+ enc2hash(nid, &nextId);
+ updateInterval = getConfigurationInt("GNUNET-INSERT",
+ "INTERVAL");
+
+ FSUI_addToNamespace(ctx,
+ pname,
+ updateInterval,
+ pid == NULL ? NULL : &prevId,
+ tid == NULL ? NULL : &thisId,
+ nid == NULL ? NULL : &nextId,
+ uri,
+ meta,
+ &nsuri);
+ FREE(pname);
+ FREENONNULL(pid);
+ FREENONNULL(tid);
+ FREENONNULL(nid);
+ pname = ECRS_uriToString(nsuri);
+ ECRS_freeUri(nsuri);
+ printf(_("Created namespace entry '%s'\n"),
+ pname);
+ FREE(pname);
+}
+
+
/**
* Print progess message.
*/
@@ -350,17 +245,11 @@
help);
}
-static char ** topKeywords = NULL;
-int topKeywordCnt = 0;
-static char ** gloKeywords = NULL;
-int gloKeywordCnt = 0;
-
-static struct ECRS_MetaData * meta;
-
static int parseOptions(int argc,
char ** argv) {
int c;
int printAndReturn = NO;
+ char * tmp;
FREENONNULL(setConfigurationString("GNUNET-INSERT",
"INDEX-CONTENT",
@@ -406,18 +295,26 @@
"PREVIOUS_SBLOCK",
GNoptarg));
break;
- case 'D':
+ case 'D':
+ tmp = convertToUtf8(GNoptarg,
+ strlen(GNoptarg),
+ nl_langinfo(CODESET));
ECRS_addToMetaData(meta,
EXTRACTOR_DESCRIPTION,
- GNoptarg);
+ tmp);
+ FREE(tmp);
break;
case 'E':
printAndReturn = YES;
break;
case 'f':
+ tmp = convertToUtf8(GNoptarg,
+ strlen(GNoptarg),
+ nl_langinfo(CODESET));
ECRS_addToMetaData(meta,
EXTRACTOR_FILENAME,
- GNoptarg);
+ tmp);
+ FREE(tmp);
break;
case 'h':
printhelp();
@@ -439,13 +336,19 @@
GROW(topKeywords,
topKeywordCnt,
topKeywordCnt+1);
- topKeywords[topKeywordCnt-1] = STRDUP(GNoptarg);
+ topKeywords[topKeywordCnt-1]
+ = convertToUtf8(GNoptarg,
+ strlen(GNoptarg),
+ nl_langinfo(CODESET));
break;
case 'K':
GROW(gloKeywords,
gloKeywordCnt,
gloKeywordCnt+1);
- gloKeywords[gloKeywordCnt-1] = STRDUP(GNoptarg);
+ gloKeywords[gloKeywordCnt-1]
+ = convertToUtf8(GNoptarg,
+ strlen(GNoptarg),
+ nl_langinfo(CODESET));
break;
case 'l':
FREENONNULL(setConfigurationString("GNUNET-INSERT",
@@ -453,9 +356,13 @@
"YES"));
break;
case 'm':
+ tmp = convertToUtf8(GNoptarg,
+ strlen(GNoptarg),
+ nl_langinfo(CODESET));
ECRS_addToMetaData(meta,
EXTRACTOR_MIMETYPE,
- GNoptarg);
+ tmp);
+ FREE(tmp);
break;
case 'n':
FREENONNULL(setConfigurationString("GNUNET-INSERT",
@@ -485,7 +392,9 @@
case 'p': {
unsigned int contentPriority;
- if (1 != sscanf(GNoptarg, "%ud", &contentPriority)) {
+ if (1 != sscanf(GNoptarg,
+ "%ud",
+ &contentPriority)) {
LOG(LOG_FAILURE,
_("You must pass a number to the '%s' option.\n"),
"-p");
@@ -614,7 +523,6 @@
int verbose;
char * timestr;
char * prevname;
- struct FSUI_Context * ctx;
int doIndex;
int ret;
char * extractors;
Modified: GNUnet/src/applications/fs/tools/gnunet-pseudonym.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-pseudonym.c 2005-02-01 03:31:17 UTC
(rev 138)
+++ GNUnet/src/applications/fs/tools/gnunet-pseudonym.c 2005-02-01 03:54:32 UTC
(rev 139)
@@ -227,7 +227,6 @@
static int namespacePrinter(void * unused,
const char * namespaceName,
- const HashCode160 * ns,
const struct ECRS_MetaData * md,
int rating) {
EncName enc;
@@ -237,10 +236,8 @@
set = getConfigurationString("PSEUDONYM",
"SET-RATING");
- hash2enc(ns, &enc);
- printf(_("Namespace '%s' has ID '%s' and rating %d.\n"),
- (namespaceName != NULL) ? namespaceName : "",
- (char*) &enc,
+ printf(_("Namespace '%s' has rating %d.\n"),
+ namespaceName,
rating);
printMeta(md);
@@ -269,7 +266,7 @@
if (delta != 0) {
rating = FSUI_rankNamespace(ctx,
- ns,
+ namespaceName,
delta);
printf(_("\tRating (after update): %d\n"),
rating);
Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h 2005-02-01 03:31:17 UTC (rev 138)
+++ GNUnet/src/include/gnunet_util.h 2005-02-01 03:54:32 UTC (rev 139)
@@ -571,6 +571,15 @@
*/
unsigned long long htonll(unsigned long long n);
+/**
+ * Convert the len characters long character sequence
+ * given in input that is in the given charset
+ * to UTF-8.
+ * @return the converted string (0-terminated)
+ */
+char * convertToUtf8(const char * input,
+ size_t len,
+ const char * charset);
/**
* GNU gettext support macro.
Modified: GNUnet/src/util/checksum.c
===================================================================
--- GNUnet/src/util/checksum.c 2005-02-01 03:31:17 UTC (rev 138)
+++ GNUnet/src/util/checksum.c 2005-02-01 03:54:32 UTC (rev 139)
@@ -30,6 +30,7 @@
#include "platform.h"
#include "gnunet_util.h"
+#include <iconv.h>
/* Avoid wasting space on 8-byte longs. */
#if UINT_MAX >= 0xffffffff
@@ -125,4 +126,53 @@
#endif
}
+/* ************* character conversion helpers *********** */
+
+/**
+ * Convert the len characters long character sequence
+ * given in input that is in the given charset
+ * to UTF-8.
+ * @return the converted string (0-terminated),
+ * if conversion fails, a copy of the orignal
+ * string is returned.
+ */
+char * convertToUtf8(const char * input,
+ size_t len,
+ const char * charset) {
+ size_t tmpSize;
+ size_t finSize;
+ char * tmp;
+ char * ret;
+ char * itmp;
+ iconv_t cd;
+
+ cd = iconv_open("UTF-8", charset);
+ if (cd == (iconv_t) -1)
+ return strdup(charset);
+ tmpSize = 3 * len + 4;
+ tmp = malloc(tmpSize);
+ itmp = tmp;
+ finSize = tmpSize;
+ if (iconv(cd,
+ (char**) &input,
+ &len,
+ &itmp,
+ &finSize) == (size_t)-1) {
+ iconv_close(cd);
+ free(tmp);
+ return strdup(charset);
+ }
+ ret = malloc(tmpSize - finSize + 1);
+ memcpy(ret,
+ tmp,
+ tmpSize - finSize);
+ ret[tmpSize - finSize] = '\0';
+ free(tmp);
+ iconv_close(cd);
+ return ret;
+}
+
+
+
+
/* end of checksum.c */
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-02-01 03:31:17 UTC (rev 138)
+++ GNUnet/todo 2005-02-01 03:54:32 UTC (rev 139)
@@ -7,13 +7,9 @@
- 593???
0.7.0pre0 [4'05] (aka "preview"):
-- AFS:
- a) complete libfsui:
- - namespace updates
- - collections
- b) complete gnunet-afs-tools:
- - insert - DONE (very rough cut)
- - download - COMPILES
+- complete gnunet-afs-tools:
+ * insert - DONE (very rough cut)
+ * download - COMPILES
- Missing Features:
* fs/module/fs+migration: anonymity level and expiration time considerations
(Christian)
* gap: economy for local queries, forwardQuery dead?, anonymityLevel
@@ -31,6 +27,14 @@
* gnunet-pseudonym
* gnunet-search
+0.7.0pre1 [5'05]:
+- gnunet-insert:
+ * allow any kind of meta-data to be specified on the
+ command-line
+- FSUI:
+ * namespace updates
+ * collections
+
0.7.0 [6'05] (aka "compatibility? what's that?"):
- Missing Features:
* topology: do eager bootstrap on first start (Christian)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r139 - in GNUnet: . src/applications/fs/tools src/include src/util,
grothoff <=