003 File Manager
Current Path:
/usr/local/share/examples/curl
usr
/
local
/
share
/
examples
/
curl
/
📁
..
📄
10-at-a-time.c
(4.24 KB)
📄
Makefile.example
(1.86 KB)
📄
README.md
(1.35 KB)
📄
altsvc.c
(1.83 KB)
📄
anyauthput.c
(4.82 KB)
📄
cacertinmem.c
(7.14 KB)
📄
certinfo.c
(2.25 KB)
📄
chkspeed.c
(6.54 KB)
📄
cookie_interface.c
(4.03 KB)
📄
crawler.c
(6.53 KB)
📄
curlgtk.c
(2.94 KB)
📄
curlx.c
(16.41 KB)
📄
debug.c
(4.21 KB)
📄
ephiperfifo.c
(14.49 KB)
📄
evhiperfifo.c
(11.9 KB)
📄
externalsocket.c
(4.83 KB)
📄
fileupload.c
(2.78 KB)
📄
fopen.c
(13.87 KB)
📄
ftp-wildcard.c
(4.15 KB)
📄
ftpget.c
(2.59 KB)
📄
ftpgetinfo.c
(2.86 KB)
📄
ftpgetresp.c
(2.51 KB)
📄
ftpsget.c
(2.89 KB)
📄
ftpupload.c
(4.48 KB)
📄
ftpuploadfrommem.c
(3.81 KB)
📄
ftpuploadresume.c
(4.24 KB)
📄
getinfo.c
(1.62 KB)
📄
getinmemory.c
(3.24 KB)
📄
getredirect.c
(2.3 KB)
📄
getreferrer.c
(1.81 KB)
📄
ghiper.c
(12.04 KB)
📄
hiperfifo.c
(11.97 KB)
📄
href_extractor.c
(2.61 KB)
📄
htmltidy.c
(3.88 KB)
📄
htmltitle.cpp
(6.23 KB)
📄
http-post.c
(1.99 KB)
📄
http2-download.c
(6.19 KB)
📄
http2-pushinmemory.c
(5.02 KB)
📄
http2-serverpush.c
(7.1 KB)
📄
http2-upload.c
(8.05 KB)
📄
http3-present.c
(1.53 KB)
📄
http3.c
(1.81 KB)
📄
httpcustomheader.c
(2.27 KB)
📄
httpput-postfields.c
(3.36 KB)
📄
httpput.c
(3.6 KB)
📄
https.c
(2.53 KB)
📄
imap-append.c
(3.77 KB)
📄
imap-authzid.c
(2.21 KB)
📄
imap-copy.c
(2.35 KB)
📄
imap-create.c
(2.06 KB)
📄
imap-delete.c
(2.06 KB)
📄
imap-examine.c
(2.11 KB)
📄
imap-fetch.c
(1.95 KB)
📄
imap-list.c
(2.08 KB)
📄
imap-lsub.c
(2.08 KB)
📄
imap-multi.c
(2.29 KB)
📄
imap-noop.c
(2 KB)
📄
imap-search.c
(2.35 KB)
📄
imap-ssl.c
(3.25 KB)
📄
imap-store.c
(2.69 KB)
📄
imap-tls.c
(3.5 KB)
📄
makefile.dj
(1.58 KB)
📄
multi-app.c
(3.36 KB)
📄
multi-debugcallback.c
(4.21 KB)
📄
multi-double.c
(2.62 KB)
📄
multi-event.c
(6.01 KB)
📄
multi-formadd.c
(3.23 KB)
📄
multi-legacy.c
(5.13 KB)
📄
multi-post.c
(3.04 KB)
📄
multi-single.c
(2.49 KB)
📄
multi-uv.c
(5.97 KB)
📄
multithread.c
(2.59 KB)
📄
opensslthreadlock.c
(2.69 KB)
📄
parseurl.c
(2.13 KB)
📄
persistent.c
(2.15 KB)
📄
pop3-authzid.c
(2.18 KB)
📄
pop3-dele.c
(2.15 KB)
📄
pop3-list.c
(1.93 KB)
📄
pop3-multi.c
(2.29 KB)
📄
pop3-noop.c
(2.11 KB)
📄
pop3-retr.c
(1.93 KB)
📄
pop3-ssl.c
(3.22 KB)
📄
pop3-stat.c
(2.13 KB)
📄
pop3-tls.c
(3.47 KB)
📄
pop3-top.c
(2.09 KB)
📄
pop3-uidl.c
(2.03 KB)
📄
post-callback.c
(5.15 KB)
📄
postinmemory.c
(3.36 KB)
📄
postit2-formadd.c
(3.51 KB)
📄
postit2.c
(3.41 KB)
📄
progressfunc.c
(4.8 KB)
📄
resolve.c
(1.92 KB)
📄
rtsp.c
(9.02 KB)
📄
sampleconv.c
(3.25 KB)
📄
sendrecv.c
(4.52 KB)
📄
sepheaders.c
(2.67 KB)
📄
sessioninfo.c
(3.06 KB)
📄
sftpget.c
(3.25 KB)
📄
sftpuploadresume.c
(3.82 KB)
📄
shared-connection-cache.c
(2.51 KB)
📄
simple.c
(1.68 KB)
📄
simplepost.c
(1.83 KB)
📄
simplessl.c
(4.56 KB)
📄
smooth-gtk-thread.c
(6.01 KB)
📄
smtp-authzid.c
(5.33 KB)
📄
smtp-expn.c
(2.55 KB)
📄
smtp-mail.c
(4.86 KB)
📄
smtp-mime.c
(5.47 KB)
📄
smtp-multi.c
(4.54 KB)
📄
smtp-ssl.c
(5.75 KB)
📄
smtp-tls.c
(6.21 KB)
📄
smtp-vrfy.c
(2.62 KB)
📄
sslbackend.c
(2.29 KB)
📄
synctime.c
(12.6 KB)
📄
threaded-ssl.c
(4.34 KB)
📄
url2file.c
(2.43 KB)
📄
urlapi.c
(1.98 KB)
📄
usercertinmem.c
(8.87 KB)
📄
xmlstream.c
(4.94 KB)
Editing: rtsp.c
/* * Copyright (c) 2011 - 2021, Jim Hollinger * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Jim Hollinger nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ /* <DESC> * A basic RTSP transfer * </DESC> */ #include <stdio.h> #include <stdlib.h> #include <string.h> #if defined (WIN32) # include <conio.h> /* _getch() */ #else # include <termios.h> # include <unistd.h> static int _getch(void) { struct termios oldt, newt; int ch; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~( ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return ch; } #endif #include <curl/curl.h> #define VERSION_STR "V1.0" /* error handling macros */ #define my_curl_easy_setopt(A, B, C) \ do { \ res = curl_easy_setopt((A), (B), (C)); \ if(res != CURLE_OK) \ fprintf(stderr, "curl_easy_setopt(%s, %s, %s) failed: %d\n", \ #A, #B, #C, res); \ } while(0) #define my_curl_easy_perform(A) \ do { \ res = curl_easy_perform(A); \ if(res != CURLE_OK) \ fprintf(stderr, "curl_easy_perform(%s) failed: %d\n", #A, res); \ } while(0) /* send RTSP OPTIONS request */ static void rtsp_options(CURL *curl, const char *uri) { CURLcode res = CURLE_OK; printf("\nRTSP: OPTIONS %s\n", uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_OPTIONS); my_curl_easy_perform(curl); } /* send RTSP DESCRIBE request and write sdp response to a file */ static void rtsp_describe(CURL *curl, const char *uri, const char *sdp_filename) { CURLcode res = CURLE_OK; FILE *sdp_fp = fopen(sdp_filename, "wb"); printf("\nRTSP: DESCRIBE %s\n", uri); if(!sdp_fp) { fprintf(stderr, "Could not open '%s' for writing\n", sdp_filename); sdp_fp = stdout; } else { printf("Writing SDP to '%s'\n", sdp_filename); } my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, sdp_fp); my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_DESCRIBE); my_curl_easy_perform(curl); my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); if(sdp_fp != stdout) { fclose(sdp_fp); } } /* send RTSP SETUP request */ static void rtsp_setup(CURL *curl, const char *uri, const char *transport) { CURLcode res = CURLE_OK; printf("\nRTSP: SETUP %s\n", uri); printf(" TRANSPORT %s\n", transport); my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, transport); my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_SETUP); my_curl_easy_perform(curl); } /* send RTSP PLAY request */ static void rtsp_play(CURL *curl, const char *uri, const char *range) { CURLcode res = CURLE_OK; printf("\nRTSP: PLAY %s\n", uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); my_curl_easy_setopt(curl, CURLOPT_RANGE, range); my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY); my_curl_easy_perform(curl); /* switch off using range again */ my_curl_easy_setopt(curl, CURLOPT_RANGE, NULL); } /* send RTSP TEARDOWN request */ static void rtsp_teardown(CURL *curl, const char *uri) { CURLcode res = CURLE_OK; printf("\nRTSP: TEARDOWN %s\n", uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_TEARDOWN); my_curl_easy_perform(curl); } /* convert url into an sdp filename */ static void get_sdp_filename(const char *url, char *sdp_filename, size_t namelen) { const char *s = strrchr(url, '/'); strcpy(sdp_filename, "video.sdp"); if(s != NULL) { s++; if(s[0] != '\0') { snprintf(sdp_filename, namelen, "%s.sdp", s); } } } /* scan sdp file for media control attribute */ static void get_media_control_attribute(const char *sdp_filename, char *control) { int max_len = 256; char *s = malloc(max_len); FILE *sdp_fp = fopen(sdp_filename, "rb"); control[0] = '\0'; if(sdp_fp != NULL) { while(fgets(s, max_len - 2, sdp_fp) != NULL) { sscanf(s, " a = control: %32s", control); } fclose(sdp_fp); } free(s); } /* main app */ int main(int argc, char * const argv[]) { #if 1 const char *transport = "RTP/AVP;unicast;client_port=1234-1235"; /* UDP */ #else /* TCP */ const char *transport = "RTP/AVP/TCP;unicast;client_port=1234-1235"; #endif const char *range = "0.000-"; int rc = EXIT_SUCCESS; char *base_name = NULL; printf("\nRTSP request %s\n", VERSION_STR); printf(" Project website: " "https://github.com/BackupGGCode/rtsprequest\n"); printf(" Requires curl V7.20 or greater\n\n"); /* check command line */ if((argc != 2) && (argc != 3)) { base_name = strrchr(argv[0], '/'); if(!base_name) { base_name = strrchr(argv[0], '\\'); } if(!base_name) { base_name = argv[0]; } else { base_name++; } printf("Usage: %s url [transport]\n", base_name); printf(" url of video server\n"); printf(" transport (optional) specifier for media stream" " protocol\n"); printf(" default transport: %s\n", transport); printf("Example: %s rtsp://192.168.0.2/media/video1\n\n", base_name); rc = EXIT_FAILURE; } else { const char *url = argv[1]; char *uri = malloc(strlen(url) + 32); char *sdp_filename = malloc(strlen(url) + 32); char *control = malloc(strlen(url) + 32); CURLcode res; get_sdp_filename(url, sdp_filename, strlen(url) + 32); if(argc == 3) { transport = argv[2]; } /* initialize curl */ res = curl_global_init(CURL_GLOBAL_ALL); if(res == CURLE_OK) { curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); CURL *curl; fprintf(stderr, " curl V%s loaded\n", data->version); /* initialize this curl session */ curl = curl_easy_init(); if(curl != NULL) { my_curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); my_curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); my_curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout); my_curl_easy_setopt(curl, CURLOPT_URL, url); /* request server options */ snprintf(uri, strlen(url) + 32, "%s", url); rtsp_options(curl, uri); /* request session description and write response to sdp file */ rtsp_describe(curl, uri, sdp_filename); /* get media control attribute from sdp file */ get_media_control_attribute(sdp_filename, control); /* setup media stream */ snprintf(uri, strlen(url) + 32, "%s/%s", url, control); rtsp_setup(curl, uri, transport); /* start playing media stream */ snprintf(uri, strlen(url) + 32, "%s/", url); rtsp_play(curl, uri, range); printf("Playing video, press any key to stop ..."); _getch(); printf("\n"); /* teardown session */ rtsp_teardown(curl, uri); /* cleanup */ curl_easy_cleanup(curl); curl = NULL; } else { fprintf(stderr, "curl_easy_init() failed\n"); } curl_global_cleanup(); } else { fprintf(stderr, "curl_global_init(%s) failed: %d\n", "CURL_GLOBAL_ALL", res); } free(control); free(sdp_filename); free(uri); } return rc; }
Upload File
Create Folder