]> git.sesse.net Git - vlc/blob - include/vlc_addons.h
7b46dd5266b05fe6b0aa73cce512782fe2cc41d0
[vlc] / include / vlc_addons.h
1 /*****************************************************************************
2  * vlc_addons.h : addons handling and describing
3  *****************************************************************************
4  * Copyright (C) 2013 VideoLAN and authors
5  *
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.
10  *
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.
15  *
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  *****************************************************************************/
20
21 #ifndef VLC_ADDONS_H
22 #define VLC_ADDONS_H 1
23
24 #include <vlc_arrays.h>
25 #include <vlc_events.h>
26
27 # ifdef __cplusplus
28 extern "C" {
29 # endif
30
31 typedef enum addon_type_t
32 {
33     ADDON_UNKNOWN = 0,
34     ADDON_EXTENSION,
35     ADDON_PLAYLIST_PARSER,
36     ADDON_SERVICE_DISCOVERY,
37     ADDON_SKIN2,
38     ADDON_PLUGIN,
39     ADDON_OTHER
40 } addon_type_t;
41
42 typedef enum addon_state_t
43 {
44     ADDON_NOTINSTALLED = 0,
45     ADDON_INSTALLING,
46     ADDON_INSTALLED,
47     ADDON_UNINSTALLING
48 } addon_state_t;
49
50 typedef enum addon_flags_t
51 {
52     ADDON_BROKEN     = 1, /* Have install inconsistency */
53     ADDON_MANAGEABLE = 1 << 1, /* Have manifest, can install or uninstall files */
54     ADDON_UPDATABLE  = 1 << 2,
55 } addon_flags_t;
56
57 #define ADDON_UUID_SIZE 16
58 #define ADDON_UUID_PSZ_SIZE (ADDON_UUID_SIZE * 2 + 4)
59 typedef uint8_t addon_uuid_t[ADDON_UUID_SIZE];
60
61 typedef struct addon_file_t
62 {
63     addon_type_t e_filetype;
64     char *psz_download_uri;
65     char *psz_filename;
66 } addon_file_t;
67
68 struct addon_entry_t
69 {
70     vlc_mutex_t lock;
71
72     addon_type_t e_type;
73     addon_state_t e_state;
74     addon_flags_t e_flags;
75
76     /* data describing addon */
77     addon_uuid_t uuid;
78     char *psz_name;
79     char *psz_summary;
80     char *psz_description;
81     char *psz_author;
82     char *psz_source_uri; /* webpage, ... */
83     char *psz_image_uri;
84     char *psz_image_data; /* base64, png */
85     char *psz_version;
86
87     /* stats */
88     long int i_downloads;
89     long int i_score;
90
91     /* Lister */
92     char *psz_source_module;
93
94     /* files list */
95     char *psz_archive_uri; /* Archive */
96     DECL_ARRAY(addon_file_t *) files;
97
98     /* custom data storage (if needed by module/source) */
99     void * p_custom;
100 };
101
102 typedef struct addons_finder_t addons_finder_t;
103 typedef struct addons_finder_sys_t addons_finder_sys_t;
104 struct addons_finder_t
105 {
106     VLC_COMMON_MEMBERS
107
108     int ( * pf_find )( addons_finder_t * );
109     int ( * pf_retrieve )( addons_finder_t *, addon_entry_t * );
110     DECL_ARRAY( addon_entry_t * ) entries;
111     char *psz_uri;
112
113     addons_finder_sys_t *p_sys;
114 };
115
116 typedef struct addons_storage_t addons_storage_t;
117 typedef struct addons_storage_sys_t addons_storage_sys_t;
118 struct addons_storage_t
119 {
120     VLC_COMMON_MEMBERS
121
122     int ( * pf_install )( addons_storage_t *, addon_entry_t * );
123     int ( * pf_remove )( addons_storage_t *, addon_entry_t * );
124     int ( * pf_catalog ) ( addons_storage_t *, addon_entry_t **, int );
125
126     addons_storage_sys_t *p_sys;
127 };
128
129 typedef struct addons_manager_private_t addons_manager_private_t;
130 struct addons_manager_t
131 {
132     vlc_event_manager_t * p_event_manager;
133
134     addons_manager_private_t *p_priv;
135 };
136 typedef struct addons_manager_t addons_manager_t;
137
138 /**
139  *  addon entry lifecycle
140  */
141 VLC_API addon_entry_t *addon_entry_New( void );
142 VLC_API addon_entry_t *addon_entry_Hold(addon_entry_t *);
143 VLC_API void addon_entry_Release(addon_entry_t *);
144
145 /**
146  * addons manager lifecycle
147  */
148 VLC_API addons_manager_t *addons_manager_New( vlc_object_t * );
149 VLC_API void addons_manager_Delete( addons_manager_t * );
150
151 /**
152  * Charge currently installed, usable and manageable addons
153  * (default "addons storage" module)
154  */
155 VLC_API int addons_manager_LoadCatalog( addons_manager_t * );
156
157 /**
158  * Gather addons info from repository (default "addons finder" module)
159  * If psz_uri is not NULL, only gather info from the pointed package.
160  */
161 VLC_API void addons_manager_Gather( addons_manager_t *, const char *psz_uri );
162
163 /**
164  * Install or Remove the addon identified by its uuid
165  */
166 VLC_API int addons_manager_Install( addons_manager_t *p_manager, const addon_uuid_t uuid );
167 VLC_API int addons_manager_Remove( addons_manager_t *p_manager, const addon_uuid_t uuid );
168
169 /**
170  * String uuid to binary uuid helpers
171  */
172 static inline bool addons_uuid_read( const char *psz_uuid, addon_uuid_t *p_uuid )
173 {
174     if ( !psz_uuid ) return false;
175     if ( strlen( psz_uuid ) < ADDON_UUID_PSZ_SIZE ) return false;
176
177     int i = 0, j = 0;
178     while ( i<ADDON_UUID_PSZ_SIZE )
179     {
180         if ( *( psz_uuid + i ) == '-' )
181             i++;
182         int v;
183         sscanf( psz_uuid + i, "%02x", &v );
184         (*p_uuid)[j++] = v & 0xFF;
185         i+=2;
186     }
187
188     return true;
189 }
190
191 static inline char * addons_uuid_to_psz( const addon_uuid_t * p_uuid )
192 {
193     char *psz = (char*) calloc( ADDON_UUID_PSZ_SIZE + 1 , sizeof(char) );
194     if ( psz )
195     {
196         int i=0;
197         char *p = psz;
198         while ( i < ADDON_UUID_SIZE )
199         {
200             if ( i == 4 || i== 7 || i== 9 || i== 11 )
201                 *p++ = '-';
202             int v = 0xFF & (*p_uuid)[i];
203             sprintf( p, "%02x", v );
204             p += 2;
205             i++;
206         }
207     }
208     return psz;
209 }
210
211 # ifdef __cplusplus
212 }
213 # endif
214
215 #endif