diff options
Diffstat (limited to 'src/fs/fs_uri.c')
-rw-r--r-- | src/fs/fs_uri.c | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 55503b71b..d3fcdd8ca 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -970,129 +970,6 @@ GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id) | |||
970 | 970 | ||
971 | 971 | ||
972 | /** | 972 | /** |
973 | * Canonicalize a keyword. | ||
974 | * | ||
975 | * @param in input string (the keyword) | ||
976 | * @return canonicalized keyword | ||
977 | */ | ||
978 | static char * | ||
979 | canonicalize_keyword (const char *in) | ||
980 | { | ||
981 | char *ret; | ||
982 | char *wpos; | ||
983 | const char *rpos; | ||
984 | |||
985 | ret = GNUNET_strdup (in); | ||
986 | wpos = ret; | ||
987 | rpos = in; | ||
988 | while ('\0' != *rpos) | ||
989 | { | ||
990 | switch (tolower ((unsigned char) *rpos)) | ||
991 | { | ||
992 | case 'a': | ||
993 | case 'e': | ||
994 | case 'i': | ||
995 | case 'o': | ||
996 | case 'u': | ||
997 | case ' ': | ||
998 | case '\t': | ||
999 | case '\n': | ||
1000 | case '\r': | ||
1001 | /* skip characters listed above */ | ||
1002 | break; | ||
1003 | case 'b': | ||
1004 | case 'c': | ||
1005 | case 'd': | ||
1006 | case 'f': | ||
1007 | case 'g': | ||
1008 | case 'h': | ||
1009 | case 'j': | ||
1010 | case 'k': | ||
1011 | case 'l': | ||
1012 | case 'm': | ||
1013 | case 'n': | ||
1014 | case 'p': | ||
1015 | case 'r': | ||
1016 | case 's': | ||
1017 | case 't': | ||
1018 | case 'v': | ||
1019 | case 'w': | ||
1020 | case 'x': | ||
1021 | case 'y': | ||
1022 | case 'z': | ||
1023 | /* convert characters listed above to lower case */ | ||
1024 | *wpos = tolower ((unsigned char) *rpos); | ||
1025 | wpos++; | ||
1026 | break; | ||
1027 | case '!': | ||
1028 | case '.': | ||
1029 | case '?': | ||
1030 | case '-': | ||
1031 | /* keep characters listed above without changes */ | ||
1032 | *wpos = *rpos; | ||
1033 | wpos++; | ||
1034 | break; | ||
1035 | default: | ||
1036 | if (isspace ((unsigned char) *rpos) || isdigit ((unsigned char) *rpos)) | ||
1037 | break; | ||
1038 | /* replace characters listed above with '_' */ | ||
1039 | *wpos = '_'; | ||
1040 | wpos++; | ||
1041 | break; | ||
1042 | } | ||
1043 | rpos++; | ||
1044 | } | ||
1045 | *wpos = '\0'; | ||
1046 | return ret; | ||
1047 | } | ||
1048 | |||
1049 | |||
1050 | /** | ||
1051 | * Canonicalize keyword URI. Performs operations such | ||
1052 | * as decapitalization and removal of certain characters. | ||
1053 | * (useful for search). | ||
1054 | * | ||
1055 | * @param uri the URI to canonicalize | ||
1056 | * @return canonicalized version of the URI, NULL on error | ||
1057 | */ | ||
1058 | struct GNUNET_FS_Uri * | ||
1059 | GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri) | ||
1060 | { | ||
1061 | struct GNUNET_FS_Uri *ret; | ||
1062 | unsigned int kc; | ||
1063 | unsigned int i; | ||
1064 | const char *in; | ||
1065 | char *sb; | ||
1066 | char *cc; | ||
1067 | const char *tok; | ||
1068 | |||
1069 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | ||
1070 | ret->type = ksk; | ||
1071 | kc = uri->data.ksk.keywordCount; | ||
1072 | for (i = 0; i < kc; i++) | ||
1073 | { | ||
1074 | in = uri->data.ksk.keywords[i]; | ||
1075 | GNUNET_FS_uri_ksk_add_keyword (ret, &in[1], | ||
1076 | (in[0] == '+') ? GNUNET_YES : GNUNET_NO); | ||
1077 | sb = GNUNET_strdup (&in[1]); | ||
1078 | #define DELIMS " \\|\"'`/&@-_,.;!?+-*^$#~=[]{}()<>" | ||
1079 | for (tok = strtok (sb, DELIMS); NULL != tok; tok = strtok (NULL, DELIMS)) | ||
1080 | #undef DELIMS | ||
1081 | { | ||
1082 | if (strlen (tok) < 3) | ||
1083 | continue; | ||
1084 | GNUNET_FS_uri_ksk_add_keyword (ret, tok, GNUNET_NO); | ||
1085 | cc = canonicalize_keyword (tok); | ||
1086 | if (strlen (cc) > 2) | ||
1087 | GNUNET_FS_uri_ksk_add_keyword (ret, cc, GNUNET_NO); | ||
1088 | } | ||
1089 | GNUNET_free (sb); | ||
1090 | } | ||
1091 | return ret; | ||
1092 | } | ||
1093 | |||
1094 | |||
1095 | /** | ||
1096 | * Merge the sets of keywords from two KSK URIs. | 973 | * Merge the sets of keywords from two KSK URIs. |
1097 | * (useful for merging the canonicalized keywords with | 974 | * (useful for merging the canonicalized keywords with |
1098 | * the original keywords for sharing). | 975 | * the original keywords for sharing). |