• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdemultimedia API Reference
  • KDE Home
  • Contact Us
 

libkcddb

  • sources
  • kde-4.14
  • kdemultimedia
  • libkcddb
  • libkcddb
httplookup.cpp
Go to the documentation of this file.
1 /*
2  Copyright ( C ) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
3  Copyright ( C ) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
4  Copyright ( C ) 2002 Nadeem Hasan <nhasan@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or ( at your option ) any later version.
10 
11  This library 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 GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "httplookup.h"
23 
24 #include <kio/job.h>
25 #include <kdebug.h>
26 
27 namespace KCDDB
28 {
29  HTTPLookup::HTTPLookup()
30  : Lookup(),
31  block_( true ), state_( Idle ), result_( Success )
32  {
33  }
34 
35  HTTPLookup::~HTTPLookup()
36  {
37  }
38 
39  Result
40  HTTPLookup::sendQuery()
41  {
42  QString cmd = QString::fromLatin1( "cddb query %1 %2" )
43  .arg( trackOffsetListToId(), trackOffsetListToString() ) ;
44 
45  makeURL( cmd );
46  Result result = fetchURL();
47 
48  return result;
49  }
50 
51  Result
52  HTTPLookup::sendRead( const CDDBMatch & match )
53  {
54  category_ = match.first;
55  discid_ = match.second;
56 
57  QString cmd = QString::fromLatin1( "cddb read %1 %2" )
58  .arg( category_, discid_ );
59 
60  makeURL( cmd );
61  Result result = fetchURL();
62 
63  return result;
64  }
65 
66  void
67  HTTPLookup::initURL( const QString & hostName, uint port )
68  {
69  cgiURL_.setProtocol( QLatin1String( "http" ) );
70  cgiURL_.setHost( hostName );
71  cgiURL_.setPort( port );
72  cgiURL_.setPath( QLatin1String( "/~cddb/cddb.cgi" ) );
73 
74  return;
75  }
76 
77  void
78  HTTPLookup::makeURL( const QString & cmd )
79  {
80  // The whole query has to constructed each time as the
81  // CDDB CGI script expects the parameters in strict order
82 
83  cgiURL_.setQuery( QString::null ); //krazy:exclude=nullstrassign for old broken gcc
84 
85  QString hello = QString::fromLatin1("%1 %2 %3 %4")
86  .arg(user_, localHostName_, clientName(), clientVersion());
87 
88  cgiURL_.addQueryItem( QLatin1String( "cmd" ), cmd );
89  cgiURL_.addQueryItem( QLatin1String( "hello" ), hello );
90  cgiURL_.addQueryItem( QLatin1String( "proto" ), QLatin1String( "6" ) );
91  }
92 
93  void
94  HTTPLookup::jobFinished()
95  {
96  QStringList lineList = QString::fromUtf8(data_, data_.size()).split( QLatin1String( "\n" ), QString::SkipEmptyParts );
97  QStringList::ConstIterator it = lineList.constBegin();
98 
99  switch ( state_ )
100  {
101  case WaitingForQueryResponse:
102 
103  if ( it != lineList.constEnd() )
104  {
105  QString line( *it );
106 
107  result_ = parseQuery( line );
108 
109  switch ( result_ )
110  {
111  case Success:
112 
113  if ( !block_ )
114  emit queryReady();
115  break;
116 
117  case MultipleRecordFound:
118 
119  ++it;
120  while ( it != lineList.constEnd() )
121  {
122  QString line( *it );
123 
124  if ( QLatin1Char( '.' ) == line[ 0 ] )
125  {
126  result_ = Success;
127 
128  if ( !block_ )
129  emit queryReady();
130  break;
131  }
132 
133  parseExtraMatch( line );
134  ++it;
135  }
136 
137  break;
138 
139  case ServerError:
140  case NoRecordFound:
141  if ( !block_ )
142  emit queryReady();
143 
144  return;
145  break;
146 
147  default:
148 
149  break;
150  }
151 
152  }
153 
154  break;
155 
156  case WaitingForReadResponse:
157 
158  {
159  CDInfo info;
160 
161  if ( info.load( QString::fromUtf8(data_,data_.size()) ) )
162  {
163  info.set( QLatin1String( "category" ), category_ );
164  info.set( QLatin1String( "discid" ), discid_ );
165  info.set( QLatin1String( "source" ), QLatin1String( "freedb" ) );
166  cdInfoList_.append( info );
167  }
168 
169  if ( !block_ )
170  emit readReady();
171  }
172 
173  return;
174 
175  break;
176 
177  default:
178 
179  break;
180  }
181 
182  result_ = Success;
183  }
184 }
185 
186 #include "httplookup.moc"
187 
188 // vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
KCDDB::Lookup::cdInfoList_
CDInfoList cdInfoList_
Definition: lookup.h:60
KCDDB::CDDB::clientName
static QString clientName()
Definition: cddb.h:41
KCDDB::NoRecordFound
Definition: kcddb.h:43
httplookup.h
KCDDB::HTTPLookup::queryReady
void queryReady()
KCDDB::Lookup::discid_
QString discid_
Definition: lookup.h:63
KCDDB::HTTPLookup::fetchURL
virtual Result fetchURL()=0
KCDDB::Lookup
Definition: lookup.h:36
KCDDB::CDDB::trackOffsetListToId
QString trackOffsetListToId()
Definition: cddb.cpp:48
KCDDB::CDDB::clientVersion
static QString clientVersion()
Definition: cddb.h:42
QList::append
void append(const T &value)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
KCDDB::HTTPLookup::initURL
void initURL(const QString &, uint)
Definition: httplookup.cpp:67
KCDDB::CDInfo
Information about a CD.
Definition: cdinfo.h:117
KCDDB::Success
Definition: kcddb.h:39
KCDDB::Lookup::parseQuery
Result parseQuery(const QString &)
Definition: lookup.cpp:39
KCDDB::HTTPLookup::WaitingForReadResponse
Definition: httplookup.h:47
KCDDB::HTTPLookup::readReady
void readReady()
KCDDB::CDInfo::set
void set(const QString &type, const QVariant &data)
Set any data from this disc.
Definition: cdinfo.cpp:522
KCDDB::ServerError
Definition: kcddb.h:40
KCDDB::CDDB::user_
QString user_
Definition: cddb.h:52
KCDDB::HTTPLookup::data_
QByteArray data_
Definition: httplookup.h:73
KCDDB::HTTPLookup::HTTPLookup
HTTPLookup()
Definition: httplookup.cpp:29
QString
KCDDB::HTTPLookup::WaitingForQueryResponse
Definition: httplookup.h:46
KCDDB::Lookup::category_
QString category_
Definition: lookup.h:62
KCDDB::MultipleRecordFound
Definition: kcddb.h:44
QStringList
KCDDB::HTTPLookup::state_
State state_
Definition: httplookup.h:74
QPair
KCDDB::CDDB::localHostName_
QString localHostName_
Definition: cddb.h:53
QLatin1Char
QLatin1String
KCDDB::HTTPLookup::sendRead
Result sendRead(const CDDBMatch &)
Definition: httplookup.cpp:52
KCDDB::HTTPLookup::result_
Result result_
Definition: httplookup.h:75
KCDDB::HTTPLookup::sendQuery
Result sendQuery()
Definition: httplookup.cpp:40
KCDDB::Result
Result
Definition: kcddb.h:37
KCDDB::HTTPLookup::cgiURL_
KUrl cgiURL_
Definition: httplookup.h:72
QList::ConstIterator
typedef ConstIterator
KCDDB::HTTPLookup::block_
bool block_
Definition: httplookup.h:71
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KCDDB::CDDB::trackOffsetListToString
QString trackOffsetListToString()
Definition: cddb.cpp:81
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
KCDDB::HTTPLookup::jobFinished
void jobFinished()
Definition: httplookup.cpp:94
KCDDB::CDInfo::load
bool load(const QString &string)
Load CDInfo from a string that is CDDB compatible.
Definition: cdinfo.cpp:282
QByteArray::size
int size() const
KCDDB::Lookup::parseExtraMatch
void parseExtraMatch(const QString &)
Definition: lookup.cpp:62
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
KCDDB::HTTPLookup::makeURL
void makeURL(const QString &)
Definition: httplookup.cpp:78
KCDDB::HTTPLookup::~HTTPLookup
virtual ~HTTPLookup()
Definition: httplookup.cpp:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkcddb

Skip menu "libkcddb"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdemultimedia API Reference

Skip menu "kdemultimedia API Reference"
  • libkcddb
  • libkcompactdisc

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal