1 /*
2 * libcddb - CDDB Interface Library for xmcd/cda
3 *
4 * This library implements an interface to access the "classic"
5 * CDDB1 services.
6 *
7 * Copyright (C) 1993-2004 Ti Kan
8 * E-mail: xmcd@amb.org
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25 #ifndef lint
26 static char *_urlmanager_c_ident_ = "@(#)urlmanager.c 1.20 03/12/12";
27 #endif
28
29 #include "fcddb.h"
30
31
32 /*
33 * CddbURLManager_GetMenuURLs
34 * Return a list of menu URLS
35 */
36 CddbResult
37 CddbURLManager_GetMenuURLs(
CddbTrack_AddCredit(CddbTrackPtr trackp,CddbConstStr id,CddbConstStr name,CddbCreditPtr * pval)38 CddbURLManagerPtr urlmgrp,
39 CddbDiscPtr discp,
40 CddbURLListPtr *pval
41 )
42 {
43 cddb_urlmanager_t *mp = (cddb_urlmanager_t *) urlmgrp;
44 cddb_disc_t *dp = (cddb_disc_t *) discp;
45 cddb_control_t *cp;
46 cddb_url_t *up,
47 *up2;
48
49 cp = mp->control;
50 if (dp == NULL)
51 up = cp->urllist.urls;
52 else
53 up = dp->urllist.urls;
54
55 for (; up != NULL; up = up->next) {
56 if (up->type != NULL && strcmp(up->type, "menu") != 0)
57 continue;
58
59 if (up->href == NULL || up->displaytext == NULL)
60 continue; /* No HREF or display text */
61
62 /* Don't use fcddb_obj_alloc here because we don't
63 * want CddbReleaseObject to free it.
64 */
65 up2 = (cddb_url_t *) MEM_ALLOC("CddbURL", sizeof(cddb_url_t));
66 if (up2 == NULL)
67 break;
68 (void) memset(up2, 0, sizeof(cddb_url_t));
69 (void) strcpy(up2->objtype, "CddbURL");
70
71 /* Copy contents */
72 up2->type = (CddbStr) fcddb_strdup((char *) up->type);
73 up2->href = (CddbStr) fcddb_strdup((char *) up->href);
74 up2->displaytext =
75 (CddbStr) fcddb_strdup((char *) up->displaytext);
76 if (up->displaylink != NULL)
77 up2->displaylink =
78 (CddbStr) fcddb_strdup((char *) up->displaylink);
79 if (up->category != NULL)
80 up2->category =
81 (CddbStr) fcddb_strdup((char *) up->category);
82 if (up->description != NULL)
83 up2->description =
84 (CddbStr) fcddb_strdup((char *) up->description);
85
86 /* Add to list */
87 up2->next = mp->urllist.urls;
88 mp->urllist.urls = up2;
89 mp->urllist.count++;
90 }
91
92 *pval = (CddbURLListPtr) &mp->urllist;
93 return Cddb_OK;
94 }
95
96
97 /*
98 * CddbURLManager_GotoURL
99 * Spawn browser to the specified URL
CddbTrack_GetArtist(CddbTrackPtr trackp,CddbStr * pval)100 */
101 /*ARGSUSED*/
102 CddbResult
103 CddbURLManager_GotoURL(
104 CddbURLManagerPtr urlmgrp,
105 CddbURLPtr urlp,
106 CddbConstStr rawurl
107 )
108 {
109 cddb_url_t *up = (cddb_url_t *) urlp;
110 char *cmd;
111 int ret;
112
113 if (rawurl == NULL)
114 rawurl = up->href;
115
116 /* Invoke web browser to the specified URL */
117 cmd = (char *) MEM_ALLOC("cmd", strlen(rawurl) + FILE_PATH_SZ + 4);
118 if (cmd == NULL)
119 return CDDBTRNOutOfMemory;
120
121 (void) sprintf(cmd, "%s '%s'", CDDB_GOBROWSER, rawurl);
122
123 ret = fcddb_runcmd(cmd);
124 MEM_FREE(cmd);
125
126 #ifdef __VMS
127 return ((ret == 0 || (ret & 0x1) == 1) ? Cddb_OK : Cddb_E_FAIL);
128 #else
129 return ((ret == 0) ? Cddb_OK : Cddb_E_FAIL);
130 #endif
131 }
132
133
134 /*
135 * CddbURLManager_SubmitURL
136 * Submit a URL to CDDB
137 */
138 /*ARGSUSED*/
139 CddbResult
CddbTrack_GetCredit(CddbTrackPtr trackp,long item,CddbCreditPtr * pval)140 CddbURLManager_SubmitURL(
141 CddbURLManagerPtr urlmgrp,
142 CddbDiscPtr discp,
143 CddbURLPtr urlp
144 )
145 {
146 /* Not supported in CDDB1 */
147 return Cddb_OK;
148 }
149
150
151