* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
This chunk size worked at the first try, uploading a
~100KiB file, so let's stick with it. */
- const int maxc = 64472;
+ const unsigned int maxc = 64472;
if (header && len > maxc)
return -1;
static int rnet_recv(gnutls_session_t session, struct rnet_message **message)
{
- char *out;
- size_t olen;
+ char *out = NULL;
+ size_t olen = 0;
char *buffer;
size_t len;
rnet_message_expand(message, 6);
int fd;
char cwd[PATH_MAX];
char *path, *fname, *tmp;
- size_t fname_len, r;
+ size_t fname_len;
+ ssize_t r;
/* If the user provided the output directory where she wishes
to save the receipt, then we use it. Otherwise, we save
the file in the current working directory (CWD). */
the receipt with the name "$CPF.REC". */
tmp = strstr(args->input_file, ".DEC");
if (tmp != NULL && tmp[sizeof(".DEC") - 1] == '\0') {
- const char *p;
+ char *p;
/* We found the ".REC" extension. */
- p = strdup(args->input_file);
+ p = strdup(basename(args->input_file));
/* Replacing the ".DEC" by ".REC". Fortunately, we
just have to change one letter. */
tmp = strstr(p, ".DEC");
fname_len = strlen(p) + strlen(path) + 2;
fname = alloca(fname_len);
snprintf(fname, fname_len, "%s/%s", path, p);
+ free(p);
} else {
/* The declaration filename does not follow the
convention, so we will not use it as a template.
}
do {
r = write(fd, buffer, len);
- } while (r != len && errno == EAGAIN);
+ } while (r < 0 && errno == EAGAIN);
if (r != len)
fprintf(stderr, "Could not write to receipt file: %s", strerror(errno));
else
fprintf(stderr, "error in handshake: %s\n",
gnutls_strerror(r));
- rnet_encode(decfile, &message);
+ r = rnet_encode(decfile, &message);
+ if (r < 0) {
+ fprintf(stderr, "error encoding message, file not supported?\n");
+ goto out;
+ }
+
rnet_send(session, message->buffer, message->len, 1);
rnet_message_del(message);