return ret;
}
+#define GNUNET_FS_URI_KSK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX
/**
* Parse a KSK URI.
GNUNET_assert (s != NULL);
slen = strlen (s);
- pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX);
+ pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
if ( (slen <= pos) ||
- (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX,
+ (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX,
pos) ) )
return NULL; /* not KSK URI */
if ( (s[slen - 1] == '+') ||
}
+#define GNUNET_FS_URI_SKS_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX
+
/**
* Parse an SKS URI.
*
GNUNET_assert (s != NULL);
slen = strlen (s);
- pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX);
+ pos = strlen ( GNUNET_FS_URI_SKS_PREFIX);
if ( (slen <= pos) ||
- (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX,
+ (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX,
pos) ) )
return NULL; /* not an SKS URI */
if ( (slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) ||
return ret;
}
+#define GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX
+
/**
* Parse a CHK URI.
GNUNET_assert (s != NULL);
slen = strlen (s);
- pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX);
+ pos = strlen (GNUNET_FS_URI_CHK_PREFIX);
if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
- (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX,
+ (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX,
pos) ) )
return NULL; /* not a CHK URI */
if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
};
+#define GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX
+
/**
* Parse a LOC URI.
* Also verifies validity of the location URI.
GNUNET_assert (s != NULL);
slen = strlen (s);
- pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX);
+ pos = strlen ( GNUNET_FS_URI_LOC_PREFIX);
if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
- (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX,
+ (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX,
pos) ) )
return NULL; /* not an SKS URI */
if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
}
ass.purpose.size = htonl(sizeof(struct LocUriAssembly));
ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
- et.value = exptime;
+ et.abs_value = exptime;
ass.exptime = GNUNET_TIME_absolute_hton (et);
if (GNUNET_OK !=
GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
}
+/**
+ * Add the given keyword to the set of keywords represented by the URI.
+ * Does nothing if the keyword is already present.
+ *
+ * @param uri ksk uri to modify
+ * @param keyword keyword to add
+ * @param is_mandatory is this keyword mandatory?
+ */
+void
+GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
+ const char *keyword,
+ int is_mandatory)
+{
+ unsigned int i;
+ const char *old;
+ char *n;
+
+ GNUNET_assert (uri->type == ksk);
+ for (i = 0; i < uri->data.ksk.keywordCount; i++)
+ {
+ old = uri->data.ksk.keywords[i];
+ if (0 == strcmp (&old[1], keyword))
+ return;
+ }
+ GNUNET_asprintf (&n,
+ is_mandatory ? "+%s" : " %s",
+ keyword);
+ GNUNET_array_append (uri->data.ksk.keywords,
+ uri->data.ksk.keywordCount,
+ n);
+}
+
+
+/**
+ * Remove the given keyword from the set of keywords represented by the URI.
+ * Does nothing if the keyword is not present.
+ *
+ * @param uri ksk uri to modify
+ * @param keyword keyword to add
+ */
+void
+GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
+ const char *keyword)
+{
+ unsigned int i;
+ char *old;
+
+ GNUNET_assert (uri->type == ksk);
+ for (i = 0; i < uri->data.ksk.keywordCount; i++)
+ {
+ old = uri->data.ksk.keywords[i];
+ if (0 == strcmp (&old[1], keyword))
+ {
+ uri->data.ksk.keywords[i] = uri->data.ksk.keywords[uri->data.ksk.keywordCount-1];
+ GNUNET_array_grow (uri->data.ksk.keywords,
+ uri->data.ksk.keywordCount,
+ uri->data.ksk.keywordCount - 1);
+ GNUNET_free (old);
+ return;
+ }
+ }
+}
+
+
/**
* Obtain the identity of the peer offering the data
*
*/
struct GNUNET_FS_Uri *
GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
- struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Absolute expiration_time)
{
struct GNUNET_FS_Uri *uri;
}
+/**
+ * Create an SKS URI from a namespace ID and an identifier.
+ *
+ * @param nsid namespace ID
+ * @param id identifier
+ * @return an FS URI for the given namespace and identifier
+ */
+struct GNUNET_FS_Uri *
+GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *nsid,
+ const char *id)
+{
+ struct GNUNET_FS_Uri *ns_uri;
+
+ ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
+ ns_uri->type = sks;
+ ns_uri->data.sks.namespace = *nsid;
+ ns_uri->data.sks.identifier = GNUNET_strdup (id);
+ return ns_uri;
+}
+
+
/**
* Canonicalize a keyword.
*
case '\n':
case '\r':
/* skip characters listed above */
- rpos++;
break;
case 'b':
case 'c':
/* convert characters listed above to lower case */
*wpos = tolower( (unsigned char)*rpos);
wpos++;
+ break;
case '!':
case '.':
case '?':
/* replace characters listed above with '_' */
*wpos = '_';
wpos++;
+ break;
}
rpos++;
}
break;
}
if (0 == found)
- kl[kc++] = GNUNET_strdup (kp - 1);
+ kl[kc++] = GNUNET_strdup (kp);
}
ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri));
ret->type = ksk;
if (keywords == NULL)
{
+ *emsg = GNUNET_strdup (_("No keywords specified!\n"));
GNUNET_break (0);
return NULL;
}
for (j = uri->data.ksk.keywordCount - 1; j >= 0; j--)
if (0 == strcmp (&uri->data.ksk.keywords[j][1], data))
return GNUNET_OK;
- nkword = GNUNET_malloc (strlen (data) + 2);
- strcpy (nkword, " "); /* not mandatory */
- strcat (nkword, data);
+ GNUNET_asprintf (&nkword,
+ " %s", /* space to mark as 'non mandatory' */
+ data);
uri->data.ksk.keywords[uri->data.ksk.keywordCount++] = nkword;
return 0;
}
GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md)
{
struct GNUNET_FS_Uri *ret;
+ int ent;
if (md == NULL)
return NULL;
ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
ret->type = ksk;
- ret->data.ksk.keywordCount = 0;
- ret->data.ksk.keywords = NULL;
- ret->data.ksk.keywords
- = GNUNET_malloc (sizeof (char *) *
- GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL));
- GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
+ ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
+ if (ent > 0)
+ {
+ ret->data.ksk.keywords
+ = GNUNET_malloc (sizeof (char *) * ent);
+ GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
+ }
return ret;
-
}
(unsigned long long) GNUNET_ntohll (uri->data.loc.fi.file_length),
peerId,
peerSig,
- (unsigned long long) uri->data.loc.expirationTime.value);
+ (unsigned long long) uri->data.loc.expirationTime.abs_value);
GNUNET_free (peerSig);
GNUNET_free (peerId);
return ret;