Qt: do not show open options in both normal and advanced UI
[vlc.git] / modules / access / htcpcp.c
blob77fbfa8f4eb59398a9508451e9e0f600e8e09d85
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
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>
30 #include <vlc_url.h>
32 #define IPPORT_HTCPCP 80
34 static int Open (vlc_object_t *);
35 static void Close (vlc_object_t *);
37 vlc_module_begin ()
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)
53 vlc_module_end ()
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 );
59 struct access_sys_t
61 int fd;
64 static int Open (vlc_object_t *obj)
66 access_t *access = (access_t *)obj;
68 vlc_url_t url;
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);
73 if (fd == -1)
75 vlc_UrlClean (&url);
76 return VLC_EGENERIC;
79 access_sys_t *sys = malloc (sizeof (*sys));
80 if (unlikely(sys == NULL))
81 goto error;
83 sys->fd = fd;
84 net_Printf (obj, fd, NULL, "BREW %s HTTP/1.1\r\n",
85 url.psz_path ? url.psz_path : "/");
86 if (url.i_port)
87 net_Printf (obj, fd, NULL, "Host: %s:%u\r\n",
88 url.psz_host, url.i_port);
89 else
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"
96 "\r\n");
97 vlc_UrlClean (&url);
99 access->p_sys = sys;
100 access->pf_read = Read;
101 access->pf_seek = Seek;
102 access->pf_control = Control;
103 return VLC_SUCCESS;
105 error:
106 net_Close (fd);
107 free (sys);
108 vlc_UrlClean (&url);
109 return VLC_EGENERIC;
112 static void Close (vlc_object_t *obj)
114 access_t *access = (access_t *)obj;
115 access_sys_t *sys = access->p_sys;
117 net_Close (sys->fd);
118 free (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);
126 if (resp == NULL)
127 goto error;
129 unsigned code;
130 if (sscanf (resp, "HTTP/%*u.%*u %u", &code) != 1)
132 msg_Err (access, "cannot parse response from coffee server");
133 goto error;
135 if ((code / 100) != 2)
137 msg_Err (access, "server error %u", code);
138 if (code == 418)
139 dialog_FatalWait (access, N_("Teapot"), "%s",
140 N_("The server is a teapot. You can't brew coffee with "
141 "a teapot."));
142 else
143 dialog_FatalWait (access, N_("Coffee pot"),
144 N_("The pot failed to brew coffee (server error %u)."), code);
145 goto error;
148 (void) buf; (void) len;
149 dialog_FatalWait (access, N_("Coffee pot"), N_("Coffee is ready."));
150 error:
151 access->info.b_eof = true;
152 return 0;
155 static int Seek (access_t *access, uint64_t pos)
157 (void) access; (void) pos;
158 return VLC_EGENERIC;
161 static int Control (access_t *access, int query, va_list args)
163 (void) access;
165 switch (query)
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;
172 break;
174 case ACCESS_GET_PTS_DELAY:
175 *va_arg (args, int64_t *) = DEFAULT_PTS_DELAY * INT64_C(1000);
176 break;
178 default:
179 return VLC_EGENERIC;
182 return VLC_SUCCESS;