[vlc-commits] Audioscrobbler: Replace ParseURL() by vlc_UrlParse().
Samuel Pitoiset
git at videolan.org
Tue Feb 14 18:21:13 CET 2012
vlc | branch: master | Samuel Pitoiset <samuel.pitoiset at gmail.com> | Mon Feb 13 12:52:01 2012 +0100| [5318fb666a69ccf8b78df3049ca11ff06908e4c4] | committer: Rafaël Carré
Audioscrobbler: Replace ParseURL() by vlc_UrlParse().
Signed-off-by: Rafaël Carré <funman at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5318fb666a69ccf8b78df3049ca11ff06908e4c4
---
modules/misc/audioscrobbler.c | 95 ++++-------------------------------------
1 files changed, 9 insertions(+), 86 deletions(-)
diff --git a/modules/misc/audioscrobbler.c b/modules/misc/audioscrobbler.c
index 33c1238..ef1a8e4 100644
--- a/modules/misc/audioscrobbler.c
+++ b/modules/misc/audioscrobbler.c
@@ -77,9 +77,7 @@ struct intf_sys_t
vlc_cond_t wait; /**< song to submit event */
/* submission of played songs */
- char *psz_submit_host; /**< where to submit data */
- int i_submit_port; /**< port to which submit */
- char *psz_submit_file; /**< file to which submit */
+ vlc_url_t p_submit_url; /**< where to submit data */
/* submission of playing song */
#if 0 //NOT USED
@@ -451,8 +449,7 @@ static void Close(vlc_object_t *p_this)
int i;
for (i = 0; i < p_sys->i_songs; i++)
DeleteSong(&p_sys->p_queue[i]);
- free(p_sys->psz_submit_host);
- free(p_sys->psz_submit_file);
+ vlc_UrlClean(&p_sys->p_submit_url);
#if 0 //NOT USED
free(p_sys->psz_nowp_host);
free(p_sys->psz_nowp_file);
@@ -462,69 +459,6 @@ static void Close(vlc_object_t *p_this)
free(p_sys);
}
-
-/*****************************************************************************
- * ParseURL : Split an http:// URL into host, file, and port
- *
- * Example: "62.216.251.205:80/protocol_1.2"
- * will be split into "62.216.251.205", 80, "protocol_1.2"
- *
- * psz_url will be freed before returning
- * *psz_file & *psz_host will be freed before use
- *
- * Return value:
- * VLC_ENOMEM Out Of Memory
- * VLC_EGENERIC Invalid url provided
- * VLC_SUCCESS Success
- *****************************************************************************/
-static int ParseURL(char *psz_url, char **psz_host, char **psz_file,
- int *i_port)
-{
- size_t i_pos;
- size_t i_len = strlen(psz_url);
- bool b_no_port = false;
- FREENULL(*psz_host);
- FREENULL(*psz_file);
-
- i_pos = strcspn(psz_url, ":");
- if (i_pos == i_len)
- {
- *i_port = 80;
- i_pos = strcspn(psz_url, "/");
- b_no_port = true;
- }
-
- *psz_host = strndup(psz_url, i_pos);
- if (!*psz_host)
- return VLC_ENOMEM;
-
- if (!b_no_port)
- {
- i_pos++; /* skip the ':' */
- *i_port = atoi(psz_url + i_pos);
- if (*i_port <= 0)
- {
- FREENULL(*psz_host);
- return VLC_EGENERIC;
- }
-
- i_pos = strcspn(psz_url, "/");
- }
-
- if (i_pos == i_len)
- return VLC_EGENERIC;
-
- i_pos++; /* skip the '/' */
- *psz_file = strdup(psz_url + i_pos);
- if (!*psz_file)
- {
- FREENULL(*psz_host);
- return VLC_ENOMEM;
- }
-
- return VLC_SUCCESS;
-}
-
/*****************************************************************************
* Handshake : Init audioscrobbler connection
*****************************************************************************/
@@ -716,21 +650,10 @@ static int Handshake(intf_thread_t *p_this)
if (!psz_url)
goto oom;
- int ret = ParseURL(psz_url, &p_sys->psz_submit_host,
- &p_sys->psz_submit_file, &p_sys->i_submit_port);
+ /* parse the submission url */
+ vlc_UrlParse(&p_sys->p_submit_url, psz_url, 0);
free(psz_url);
- switch(ret)
- {
- case VLC_ENOMEM:
- goto oom;
- case VLC_EGENERIC:
- goto proto;
- case VLC_SUCCESS:
- default:
- break;
- }
-
return VLC_SUCCESS;
oom:
@@ -879,8 +802,8 @@ static void Run(intf_thread_t *p_intf)
}
vlc_mutex_unlock(&p_sys->lock);
- int i_post_socket = net_ConnectTCP(p_intf, p_sys->psz_submit_host,
- p_sys->i_submit_port);
+ int i_post_socket = net_ConnectTCP(p_intf, p_sys->p_submit_url.psz_host,
+ p_sys->p_submit_url.i_port);
if (i_post_socket == -1)
{
@@ -893,7 +816,7 @@ static void Run(intf_thread_t *p_intf)
/* we transmit the data */
int i_net_ret = net_Printf(p_intf, i_post_socket, NULL,
- "POST /%s HTTP/1.1\n"
+ "POST %s HTTP/1.1\n"
"Accept-Encoding: identity\n"
"Content-length: %zu\n"
"Connection: close\n"
@@ -903,8 +826,8 @@ static void Run(intf_thread_t *p_intf)
"\r\n"
"%s\r\n"
"\r\n",
- p_sys->psz_submit_file, strlen(psz_submit),
- p_sys->psz_submit_host, psz_submit
+ p_sys->p_submit_url.psz_path, strlen(psz_submit),
+ p_sys->p_submit_url.psz_host, psz_submit
);
free(psz_submit);
More information about the vlc-commits
mailing list