2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <glib/gi18n-lib.h>
29 #include "_quvi_media_s.h"
30 #include "_quvi_net_s.h"
31 #include "_quvi_script_s.h"
33 #include "misc/match_media_script.h"
34 #include "misc/unescape.h"
35 #include "misc/resolve.h"
36 #include "misc/media.h"
37 #include "net/handle.h"
40 static gboolean
_chk_goto_url(_quvi_media_t qm
)
42 if (qm
->url
.redirect_to
->len
>0)
44 g_string_assign(qm
->url
.input
, qm
->url
.redirect_to
->str
);
45 g_string_assign(qm
->url
.redirect_to
, "");
51 extern QuviError
l_match_url_to_media_script(_quvi_media_t
, GSList
**);
52 extern const gchar
*show_script
; /* m_scan_scripts */
54 typedef QuviMatchMediaScriptMode _qm_mode
;
56 QuviError
m_match_media_script(_quvi_t q
, _quvi_media_t
*qm
,
57 const gchar
*url
, const _qm_mode mode
)
59 gboolean resolve_flag
;
63 resolve_flag
= (mode
!= QM_MATCH_MS_SUPPORTED_OFFLINE
)
68 *qm
= m_media_new(q
, url
);
70 if (resolve_flag
== TRUE
) /* Resolve URL redirection. */
72 m_resolve(q
, url
, (*qm
)->url
.input
);
73 if (quvi_ok(q
) == QUVI_FALSE
)
74 return (q
->status
.rc
);
77 m_unescape_url((*qm
)->url
.input
);
78 rc
= l_match_url_to_media_script(*qm
, &s
);
80 if (rc
== QUVI_ERROR_NO_SUPPORT
)
82 static const gchar
*_E
=
83 N_("No support: %s: Could not find a media script for URL");
85 g_string_printf(q
->status
.errmsg
, g_dgettext(GETTEXT_PACKAGE
, _E
), url
);
88 else if (rc
!= QUVI_OK
)
91 if (show_script
!= NULL
&& strlen(show_script
) >0)
93 const _quvi_script_t qs
= (const _quvi_script_t
) s
->data
;
95 g_message("[%s] libquvi: %s: input URL accepted",
96 __func__
, qs
->fpath
->str
);
101 case QM_MATCH_MS_PARSE
:
102 rc
= l_exec_media_script_parse(*qm
, s
);
105 /* Check if goto_url was set. */
106 if (_chk_goto_url(*qm
) == TRUE
)
107 return (m_match_media_script(q
, qm
, url
, mode
));
111 case QM_MATCH_MS_SUPPORTED_OFFLINE
:
112 case QM_MATCH_MS_SUPPORTED_ONLINE
:
118 /* vim: set ts=2 sw=2 tw=72 expandtab: */