Reviewed-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -392,6 +392,86 @@ static int libssh_close_dir(URLContext *h) |
392 | 392 |
return 0; |
393 | 393 |
} |
394 | 394 |
|
395 |
+static int libssh_delete(URLContext *h) |
|
396 |
+{ |
|
397 |
+ int ret; |
|
398 |
+ LIBSSHContext *libssh = h->priv_data; |
|
399 |
+ sftp_attributes attr = NULL; |
|
400 |
+ char path[MAX_URL_SIZE]; |
|
401 |
+ |
|
402 |
+ if ((ret = libssh_connect(h, h->filename, path, sizeof(path))) < 0) |
|
403 |
+ goto cleanup; |
|
404 |
+ |
|
405 |
+ if (!(attr = sftp_stat(libssh->sftp, path))) { |
|
406 |
+ ret = AVERROR(sftp_get_error(libssh->sftp)); |
|
407 |
+ goto cleanup; |
|
408 |
+ } |
|
409 |
+ |
|
410 |
+ if (attr->type == SSH_FILEXFER_TYPE_DIRECTORY) { |
|
411 |
+ if (sftp_rmdir(libssh->sftp, path) < 0) { |
|
412 |
+ ret = AVERROR(sftp_get_error(libssh->sftp)); |
|
413 |
+ goto cleanup; |
|
414 |
+ } |
|
415 |
+ } else { |
|
416 |
+ if (sftp_unlink(libssh->sftp, path) < 0) { |
|
417 |
+ ret = AVERROR(sftp_get_error(libssh->sftp)); |
|
418 |
+ goto cleanup; |
|
419 |
+ } |
|
420 |
+ } |
|
421 |
+ |
|
422 |
+ ret = 0; |
|
423 |
+ |
|
424 |
+cleanup: |
|
425 |
+ if (attr) |
|
426 |
+ sftp_attributes_free(attr); |
|
427 |
+ libssh_close(h); |
|
428 |
+ return ret; |
|
429 |
+} |
|
430 |
+ |
|
431 |
+static int libssh_move(URLContext *h_src, URLContext *h_dst) |
|
432 |
+{ |
|
433 |
+ int ret; |
|
434 |
+ LIBSSHContext *libssh = h_src->priv_data; |
|
435 |
+ char path_src[MAX_URL_SIZE], path_dst[MAX_URL_SIZE]; |
|
436 |
+ char hostname_src[1024], hostname_dst[1024]; |
|
437 |
+ char credentials_src[1024], credentials_dst[1024]; |
|
438 |
+ int port_src = 22, port_dst = 22; |
|
439 |
+ |
|
440 |
+ av_url_split(NULL, 0, |
|
441 |
+ credentials_src, sizeof(credentials_src), |
|
442 |
+ hostname_src, sizeof(hostname_src), |
|
443 |
+ &port_src, |
|
444 |
+ path_src, sizeof(path_src), |
|
445 |
+ h_src->filename); |
|
446 |
+ |
|
447 |
+ av_url_split(NULL, 0, |
|
448 |
+ credentials_dst, sizeof(credentials_dst), |
|
449 |
+ hostname_dst, sizeof(hostname_dst), |
|
450 |
+ &port_dst, |
|
451 |
+ path_dst, sizeof(path_dst), |
|
452 |
+ h_dst->filename); |
|
453 |
+ |
|
454 |
+ if (strcmp(credentials_src, credentials_dst) || |
|
455 |
+ strcmp(hostname_src, hostname_dst) || |
|
456 |
+ port_src != port_dst) { |
|
457 |
+ return AVERROR(EINVAL); |
|
458 |
+ } |
|
459 |
+ |
|
460 |
+ if ((ret = libssh_connect(h_src, h_src->filename, path_src, sizeof(path_src))) < 0) |
|
461 |
+ goto cleanup; |
|
462 |
+ |
|
463 |
+ if (sftp_rename(libssh->sftp, path_src, path_dst) < 0) { |
|
464 |
+ ret = AVERROR(sftp_get_error(libssh->sftp)); |
|
465 |
+ goto cleanup; |
|
466 |
+ } |
|
467 |
+ |
|
468 |
+ ret = 0; |
|
469 |
+ |
|
470 |
+cleanup: |
|
471 |
+ libssh_close(h_src); |
|
472 |
+ return ret; |
|
473 |
+} |
|
474 |
+ |
|
395 | 475 |
#define OFFSET(x) offsetof(LIBSSHContext, x) |
396 | 476 |
#define D AV_OPT_FLAG_DECODING_PARAM |
397 | 477 |
#define E AV_OPT_FLAG_ENCODING_PARAM |
... | ... |
@@ -416,6 +496,8 @@ URLProtocol ff_libssh_protocol = { |
416 | 416 |
.url_write = libssh_write, |
417 | 417 |
.url_seek = libssh_seek, |
418 | 418 |
.url_close = libssh_close, |
419 |
+ .url_delete = libssh_delete, |
|
420 |
+ .url_move = libssh_move, |
|
419 | 421 |
.url_open_dir = libssh_open_dir, |
420 | 422 |
.url_read_dir = libssh_read_dir, |
421 | 423 |
.url_close_dir = libssh_close_dir, |