allow to change local files

- fuse/filecache:
     * add filecache_upload_patch
     * allow opening files in modes other than RDONLY
 - fuse/hashtbl:
     * add folder_tree_upload_patch
 - fuse/operations:
     * allow opening files in modes other than RDONLY
     * add members to private context which allow tracking of
       not-yet-uploaded files and files opened for writing and
       files opened in read-only mode
 - mfapi/apicalls/upload_patch:
     * supply x-filename and x-filesize headers
 - mfapi/apicalls/upload_simple:
     * do not supply the x-filehash header as it is not used by the
       server
 - utils/hash:
     * hex characters must be lower case for the server
 - utils/strings:
     * clean up unused functions strdup_join, strdup_substr,
       string_chomp
 - utils/stringv:
     * complete rewrite with different string vector implementation
This commit is contained in:
josch
2014-12-08 14:12:17 +01:00
parent 5bd9e418c4
commit 171fd815f2
16 changed files with 521 additions and 439 deletions

View File

@@ -59,132 +59,6 @@ char *strdup_printf(char *fmt, ...)
return ret_str;
}
char *strdup_join(char *string1, char *string2)
{
char *new_string;
size_t string1_len;
size_t string2_len;
if (string1 == NULL || string2 == NULL)
return NULL;
string1_len = strlen(string1);
string2_len = strlen(string2);
new_string = (char *)malloc(string1_len + string2_len + 1);
strncpy(new_string, string1, string1_len);
strncat(new_string, string2, string2_len);
new_string[string1_len + string2_len] = '\0';
return new_string;
}
char *strdup_subst(char *string, char *token, char *subst,
unsigned int max)
{
size_t string_len = 0;
size_t subst_len = 0;
size_t token_len = 0;
size_t total_len = 0;
size_t copy_len = 0;
size_t token_count;
char *str_new = NULL;
char **vectors;
char **rewind;
if (string == NULL)
return NULL;
if (token == NULL || subst == NULL)
return NULL;
string_len = strlen(string);
token_len = strlen(token);
// return on conditions that we could never handle.
if (token_len > string_len)
return NULL;
if (token[0] == '\0')
return NULL;
vectors = stringv_find(string, token, max);
if (vectors == NULL)
return NULL;
rewind = vectors;
// count the number of tokens found in the string
token_count = stringv_len(vectors);
if (token_count > max)
token_count = max;
// start with the original string size;
total_len = string_len;
// subtract the total number of token chars to be removed
total_len -= (token_len * token_count);
// add back the total number of subst chars to be inserted
total_len += (subst_len * token_count);
str_new = (char *)malloc((total_len + 1) * sizeof(char));
str_new[0] = '\0';
while (*vectors != NULL) {
// calculate distance to the next token from current position
copy_len = *vectors - string;
if (copy_len > 0) {
strncat(str_new, string, copy_len);
string += copy_len;
// when total_len == 0 the process is complete
total_len -= copy_len;
}
strncat(str_new, token, token_len);
// when total_len == 0 the process is complete
total_len -= token_len;
vectors++;
}
// might have one more copy operation to complete
if (total_len > 0) {
strcat(str_new, string);
}
// todo: can't free vectors directly cuz it was incremented
free(rewind);
return str_new;
}
void string_chomp(char *string)
{
size_t len;
char *pos;
if (string == NULL)
return;
len = strlen(string);
if (len == 0)
return;
pos = &string[len - 1];
while (isspace((int)*pos) != 0) {
*pos = '\0';
pos--;
}
return;
}
char *string_line_from_stdin(bool hide)
{
char *line = NULL;