1 /*****************************************************************************
2 * htcpcp.c: HTCPCP module for VLC media player
3 *****************************************************************************
4 * Copyright © 2011 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
27 #include <vlc_access.h>
28 #include <vlc_dialog.h>
29 #include <vlc_network.h>
32 #define IPPORT_HTCPCP 80
34 static int Open (vlc_object_t *);
35 static void Close (vlc_object_t *);
38 set_shortname ("HTCPCP")
39 set_description (N_("Coffee pot control"))
40 set_capability ("access", 0)
41 set_category (CAT_INPUT)
42 set_subcategory (SUBCAT_INPUT_ACCESS)
43 add_shortcut ("koffie", "q%C3%A6hv%C3%A6", "%D9%82%D9%87%D9%88%D8%A9",
44 "akeita", "koffee", "kahva", "kafe", "caf%C3%E8",
45 "%E5%92%96%E5%95%A1", "kava", "k%C3%A1va", "kaffe", "coffee",
46 "kafo", "kohv", "kahvi", "%4Baffee"/*,
47 "%CE%BA%CE%B1%CF%86%CE%AD",
48 "%E0%A4%95%E0%A5%8C%E0%A4%AB%E0%A5%80",
49 "%E3%82%B3%E3%83%BC%E3%83%92%E3%83%BC",
50 "%EC%BB%A4%ED%94%BC", "%D0%BA%D0%BE%D1%84%D0%B5",
51 "%E0%B8%81%E0%B8%B2%E0%B9%81%E0%B8%9F"*/)
52 set_callbacks (Open, Close)
55 static ssize_t Read( access_t *, uint8_t *, size_t );
56 static int Seek( access_t *, uint64_t );
57 static int Control( access_t *, int, va_list );
64 static int Open (vlc_object_t *obj)
66 access_t *access = (access_t *)obj;
69 vlc_UrlParse (&url, access->psz_location, 0);
71 int fd = net_ConnectTCP (obj, url.psz_host,
72 url.i_port ? url.i_port : IPPORT_HTCPCP);
79 access_sys_t *sys = malloc (sizeof (*sys));
80 if (unlikely(sys == NULL))
84 net_Printf (obj, fd, NULL, "BREW %s HTTP/1.1\r\n",
85 url.psz_path ? url.psz_path : "/");
87 net_Printf (obj, fd, NULL, "Host: %s:%u\r\n",
88 url.psz_host, url.i_port);
90 net_Printf (obj, fd, NULL, "Host: %s\r\n", url.psz_host);
91 net_Printf (obj, fd, NULL,
92 "User-Agent: "PACKAGE_NAME"/"PACKAGE_VERSION"\r\n"
93 "Accept-Additions: \r\n"
94 "Content-Type: application/coffee-pot-command\r\n"
95 "Content-Length: 0\r\n"
100 access->pf_read = Read;
101 access->pf_seek = Seek;
102 access->pf_control = Control;
112 static void Close (vlc_object_t *obj)
114 access_t *access = (access_t *)obj;
115 access_sys_t *sys = access->p_sys;
121 static ssize_t Read (access_t *access, uint8_t *buf, size_t len)
123 access_sys_t *sys = access->p_sys;
125 char *resp = net_Gets (access, sys->fd, NULL);
130 if (sscanf (resp, "HTTP/%*u.%*u %u", &code) != 1)
132 msg_Err (access, "cannot parse response from coffee server");
135 if ((code / 100) != 2)
137 msg_Err (access, "server error %u", code);
139 dialog_FatalWait (access, N_("Teapot"), "%s",
140 N_("The server is a teapot. You can't brew coffee with "
143 dialog_FatalWait (access, N_("Coffee pot"),
144 N_("The pot failed to brew coffee (server error %u)."), code);
148 (void) buf; (void) len;
149 dialog_FatalWait (access, N_("Coffee pot"), N_("Coffee is ready."));
151 access->info.b_eof = true;
155 static int Seek (access_t *access, uint64_t pos)
157 (void) access; (void) pos;
161 static int Control (access_t *access, int query, va_list args)
167 case ACCESS_CAN_SEEK:
168 case ACCESS_CAN_FASTSEEK:
169 case ACCESS_CAN_PAUSE:
170 case ACCESS_CAN_CONTROL_PACE:
171 *va_arg (args, bool *) = false;
174 case ACCESS_GET_PTS_DELAY:
175 *va_arg (args, int64_t *) = DEFAULT_PTS_DELAY * INT64_C(1000);