/* PUT's from fd to URI */ int ne_put(ne_session *sess, const char *uri, int fd) { ne_request *req; struct stat st; int ret; if (fstat(fd, &st)) { int errnum = errno; char buf[200]; ne_set_error(sess, _("Could not determine file size: %s"), ne_strerror(errnum, buf, sizeof buf)); return NE_ERROR; } req = ne_request_create(sess, "PUT", uri); #ifdef NE_HAVE_DAV ne_lock_using_resource(req, uri, 0); ne_lock_using_parent(req, uri); #endif ne_set_request_body_fd(req, fd, 0, st.st_size); ret = ne_request_dispatch(req); if (ret == NE_OK && ne_get_status(req)->klass != 2) ret = NE_ERROR; ne_request_destroy(req); return ret; }
static void convert_dirstring(ne_buffer *buf, const char *charset, gnutls_datum *data) { iconv_t id = iconv_open("UTF-8", charset); size_t inlen = data->size, outlen = buf->length - buf->used; char *inbuf = (char *)data->data; char *outbuf = buf->data + buf->used - 1; if (id == (iconv_t)-1) { char err[128], err2[128]; ne_snprintf(err, sizeof err, "[unprintable in %s: %s]", charset, ne_strerror(errno, err2, sizeof err2)); ne_buffer_zappend(buf, err); return; } ne_buffer_grow(buf, buf->used + 64); while (inlen && outlen && iconv(id, &inbuf, &inlen, &outbuf, &outlen) == 0) ; iconv_close(id); buf->used += buf->length - buf->used - outlen; buf->data[buf->used - 1] = '\0'; }
static int str_errors(void) { char expect[200], actual[200]; strncpy(expect, strerror(ENOENT), sizeof(expect)); ONN("ne_strerror did not return passed-in buffer", ne_strerror(ENOENT, actual, sizeof(actual)) != actual); ONV(strcmp(expect, actual), ("error from ENOENT was `%s' not `%s'", actual, expect)); /* Test truncated error string is still NUL-terminated. */ ne_strerror(ENOENT, actual, 6); NE_DEBUG(NE_DBG_HTTP, "error: %s\n", actual); ONN("truncated string had wrong length", strlen(actual) != 5); ne_strerror(-1, actual, 6); ONN("truncated string for bad error had wrong length", strlen(actual) != 5); return OK; }