~ubuntu-branches/ubuntu/precise/libmusicbrainz/precise-updates

« back to all changes in this revision

Viewing changes to src/c-int-query-source.inc

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-02-01 17:18:10 UTC
  • Revision ID: package-import@ubuntu.com-20120201171810-jzz90w51dx6shdr1
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* --------------------------------------------------------------------------
 
2
 
 
3
   libmusicbrainz4 - Client library to access MusicBrainz
 
4
 
 
5
   Copyright (C) 2011 Andrew Hawkins
 
6
 
 
7
   This file is part of libmusicbrainz4.
 
8
 
 
9
   This library is free software; you can redistribute it and/or
 
10
   modify it under the terms of v2 of the GNU Lesser General Public
 
11
   License as published by the Free Software Foundation.
 
12
 
 
13
   Flactag is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
   Lesser General Public License for more details.
 
17
 
 
18
   You should have received a copy of the GNU General Public License
 
19
   along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
     $Id: c-int-query-source.inc 13259 2011-08-10 12:02:50Z adhawkins $
 
22
 
 
23
----------------------------------------------------------------------------*/
 
24
 
 
25
Mb4Query mb4_query_new(const char *UserAgent, const char *Server, int Port)
 
26
{
 
27
        return new MusicBrainz4::CQuery(UserAgent, Server ? Server : "musicbrainz.org", Port!=0 ? Port : 80);
 
28
}
 
29
 
 
30
MB4_C_STR_SETTER(Query,query,UserName,username)
 
31
MB4_C_STR_SETTER(Query,query,Password,password)
 
32
MB4_C_STR_SETTER(Query,query,ProxyHost,proxyhost)
 
33
MB4_C_INT_SETTER(Query,query,ProxyPort,proxyport)
 
34
MB4_C_STR_SETTER(Query,query,ProxyUserName,proxyusername)
 
35
MB4_C_STR_SETTER(Query,query,ProxyPassword,proxypassword)
 
36
 
 
37
Mb4ReleaseList mb4_query_lookup_discid(Mb4Query Query, const char *DiscID)
 
38
{
 
39
        if (Query)
 
40
        {
 
41
                try
 
42
                {
 
43
                        MusicBrainz4::CQuery *TheQuery=reinterpret_cast<MusicBrainz4::CQuery *>(Query);
 
44
                        if (TheQuery)
 
45
                                return new MusicBrainz4::CReleaseList(TheQuery->LookupDiscID(DiscID));
 
46
                }
 
47
 
 
48
                catch(...)
 
49
                {
 
50
                }
 
51
        }
 
52
 
 
53
        return 0;
 
54
}
 
55
 
 
56
Mb4Release mb4_query_lookup_release(Mb4Query Query, const char *Release)
 
57
{
 
58
        if (Query)
 
59
        {
 
60
                try
 
61
                {
 
62
                        MusicBrainz4::CQuery *TheQuery=reinterpret_cast<MusicBrainz4::CQuery *>(Query);
 
63
                        if (TheQuery)
 
64
                                return new MusicBrainz4::CRelease(TheQuery->LookupRelease(Release));
 
65
                }
 
66
 
 
67
                catch(...)
 
68
                {
 
69
                }
 
70
        }
 
71
 
 
72
        return 0;
 
73
}
 
74
 
 
75
Mb4Metadata mb4_query_query(Mb4Query Query, const char *Entity, const char *ID, const char *Resource, int NumParams, char **ParamName, char **ParamValue)
 
76
{
 
77
        if (Query)
 
78
        {
 
79
                try
 
80
                {
 
81
                        MusicBrainz4::CQuery::tParamMap Params;
 
82
 
 
83
                        for (int count=0;count<NumParams;count++)
 
84
                        {
 
85
                                if (ParamName[count] && ParamValue[count])
 
86
                                        Params[ParamName[count]]=ParamValue[count];
 
87
                        }
 
88
 
 
89
                        MusicBrainz4::CQuery *TheQuery=reinterpret_cast<MusicBrainz4::CQuery *>(Query);
 
90
                        if (TheQuery)
 
91
                                return new MusicBrainz4::CMetadata(TheQuery->Query(Entity?Entity:"",
 
92
                                                                                                                                                                                                                        ID?ID:"",
 
93
                                                                                                                                                                                                                        Resource?Resource:"",
 
94
                                                                                                                                                                                                                        Params));
 
95
                }
 
96
 
 
97
                catch(...)
 
98
                {
 
99
                }
 
100
        }
 
101
 
 
102
        return 0;
 
103
}
 
104
 
 
105
unsigned char mb4_query_add_collection_entries(Mb4Query Query, const char *Collection, int NumEntries, const char **Entries)
 
106
{
 
107
        if (Query)
 
108
        {
 
109
                try
 
110
                {
 
111
                        std::vector<std::string> VecEntries;
 
112
 
 
113
                        MusicBrainz4::CQuery *TheQuery=reinterpret_cast<MusicBrainz4::CQuery *>(Query);
 
114
                        if (TheQuery)
 
115
                        {
 
116
                                for (int count=0;count<NumEntries;count++)
 
117
                                {
 
118
                                        if (Entries && Entries[count])
 
119
                                        {
 
120
                                                VecEntries.push_back(Entries[count]);
 
121
                                        }
 
122
                                }
 
123
 
 
124
                                return TheQuery->AddCollectionEntries(Collection,VecEntries)?1:0;
 
125
                        }
 
126
                }
 
127
 
 
128
                catch(...)
 
129
                {
 
130
                }
 
131
        }
 
132
 
 
133
        return 0;
 
134
}
 
135
 
 
136
unsigned char mb4_query_delete_collection_entries(Mb4Query Query, const char *Collection, int NumEntries, const char **Entries)
 
137
{
 
138
        if (Query)
 
139
        {
 
140
                try
 
141
                {
 
142
                        std::vector<std::string> VecEntries;
 
143
 
 
144
                        MusicBrainz4::CQuery *TheQuery=reinterpret_cast<MusicBrainz4::CQuery *>(Query);
 
145
                        if (TheQuery)
 
146
                        {
 
147
                                for (int count=0;count<NumEntries;count++)
 
148
                                {
 
149
                                        if (Entries && Entries[count])
 
150
                                        {
 
151
                                                VecEntries.push_back(Entries[count]);
 
152
                                        }
 
153
                                }
 
154
 
 
155
                                return TheQuery->AddCollectionEntries(Collection,VecEntries)?1:0;
 
156
                        }
 
157
                }
 
158
 
 
159
                catch(...)
 
160
                {
 
161
                }
 
162
        }
 
163
 
 
164
        return 0;
 
165
}
 
166
 
 
167
tQueryResult mb4_query_get_lastresult(Mb4Query o)
 
168
{
 
169
        if (o)
 
170
        {
 
171
                try
 
172
                {
 
173
                        return (tQueryResult)((MusicBrainz4::CQuery *)o)->LastResult();
 
174
                }
 
175
 
 
176
                catch (...)
 
177
                {
 
178
                }
 
179
        }
 
180
 
 
181
        return eQuery_FetchError;
 
182
}
 
183