00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00046 #ifndef XSPF_READER_H
00047 #define XSPF_READER_H
00048
00049
00050 #include "XspfDefines.h"
00051 #include <string>
00052
00053
00054 namespace Xspf {
00055
00056
00058
00059
00060 #define XSPF_READER_TEXT_ONE_ATTRIBUTE_FORBIDDEN _PT("Attribute '%s' not allowed.")
00061 #define XSPF_READER_TEXT_ONE_EXPAT_ERROR _PT("Expat error '%s'")
00062 #define XSPF_READER_TEXT_ONE_ELEMENT_FORBIDDEN _PT("Element '%s' not allowed.")
00063 #define XSPF_READER_TEXT_ONE_ELEMENT_FORBIDDEN_VERSION_ZERO _PT("Element '%s' not allowed in XSPF-0.")
00064 #define XSPF_READER_TEXT_ONE_FILE_READING_ERROR _PT("File '%s' could not be read.")
00065 #define XSPF_READER_TEXT_ONE_WRONG_ROOT_NAME _PT("Root element must be '") XSPF_NS_HOME XSPF_NS_SEP_STRING _PT("playlist', not '%s'.")
00066 #define XSPF_READER_TEXT_ONE_WRONG_VERSION _PT("Version must be '0' or '1', not '%s'.")
00067
00068
00069 #define XSPF_READER_TEXT_ZERO_ATTRIBUTE_MISSING(name) _PT("Attribute '") name _PT("' missing.")
00070 #define XSPF_READER_TEXT_ZERO_ELEMENT_MISSING(ns, name) _PT("Element '") ns XSPF_NS_SEP_STRING name _PT("' missing.")
00071 #define XSPF_READER_TEXT_ZERO_ELEMENT_MISSING_VERSION_ZERO(ns, name) _PT("Element '") ns XSPF_NS_SEP_STRING name _PT("' missing. This is not allowed in XSPF-0.")
00072 #define XSPF_READER_TEXT_ZERO_FILENAME_NULL _PT("Filename must not be NULL.")
00073 #define XSPF_READER_TEXT_ZERO_TOO_MANY_ELEMENTS(ns, name) _PT("Only one '") ns XSPF_NS_SEP_STRING name _PT("' allowed.")
00074 #define XSPF_READER_TEXT_ZERO_WRONG_ATTRIBUTE_TYPE(attr, type) _PT("Attribute '") attr _PT("' is not a valid ") type _PT(".")
00075 #define XSPF_READER_TEXT_ZERO_WRONG_CONTENT_TYPE(ns, elem, type) _PT("Content of '") ns XSPF_NS_SEP_STRING elem _PT("' is not a valid ") type _PT(".")
00076 #define XSPF_READER_TEXT_ZERO_TEXT_FORBIDDEN(ns, elem) _PT("Content of '") ns XSPF_NS_SEP_STRING elem _PT("' must be whitespace or child elements, not text.")
00077 #define XSPF_READER_TEXT_ZERO_KEY_WITHOUT_VERSION(name) _PT("Attribute '") name _PT("' does not carry version information.")
00078 #define XSPF_READER_TEXT_ZERO_KEY_WITH_REL_URI(name) _PT("Attribute '") name _PT("' does not contain an absolute URI.")
00079
00081
00082
00086 enum XspfReaderReturnCode {
00087 XSPF_READER_SUCCESS,
00088
00089 XSPF_READER_ERROR_NO_INPUT,
00090 XSPF_READER_ERROR_ELEMENT_TOOMANY,
00091 XSPF_READER_ERROR_ELEMENT_FORBIDDEN,
00092 XSPF_READER_ERROR_ELEMENT_MISSING,
00093 XSPF_READER_ERROR_ATTRIBUTE_INVALID,
00094 XSPF_READER_ERROR_ATTRIBUTE_MISSING,
00095 XSPF_READER_ERROR_ATTRIBUTE_FORBIDDEN,
00096 XSPF_READER_ERROR_CONTENT_INVALID,
00097 XSPF_READER_ERROR_BASE_URI_USELESS,
00098
00099 XSPF_READER_WARNING_KEY_WITHOUT_VERSION,
00100 XSPF_READER_WARNING_KEY_WITH_REL_URI,
00101
00102 XSPF_READER_ERROR_MALICIOUS_SPACE,
00103 XSPF_READER_ERROR_MALICIOUS_LOOKUP_SUM,
00104 XSPF_READER_ERROR_MALICIOUS_LOOKUP_DEPTH,
00105
00106
00107
00108
00109 XSPF_READER_ERROR_EXPAT = 0x1000
00110 };
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00151 enum XspfTag {
00152
00153 TAG_UNKNOWN,
00154
00155 TAG_PLAYLIST,
00156 TAG_PLAYLIST_TITLE,
00157 TAG_PLAYLIST_CREATOR,
00158 TAG_PLAYLIST_ANNOTATION,
00159 TAG_PLAYLIST_INFO,
00160 TAG_PLAYLIST_LOCATION,
00161 TAG_PLAYLIST_IDENTIFIER,
00162 TAG_PLAYLIST_IMAGE,
00163 TAG_PLAYLIST_DATE,
00164 TAG_PLAYLIST_LICENSE,
00165 TAG_PLAYLIST_ATTRIBUTION,
00166 TAG_PLAYLIST_ATTRIBUTION_LOCATION,
00167 TAG_PLAYLIST_ATTRIBUTION_IDENTIFIER,
00168 TAG_PLAYLIST_LINK,
00169 TAG_PLAYLIST_META,
00170 TAG_PLAYLIST_EXTENSION,
00171 TAG_PLAYLIST_TRACKLIST,
00172 TAG_PLAYLIST_TRACKLIST_TRACK,
00173 TAG_PLAYLIST_TRACKLIST_TRACK_LOCATION,
00174 TAG_PLAYLIST_TRACKLIST_TRACK_IDENTIFIER,
00175 TAG_PLAYLIST_TRACKLIST_TRACK_TITLE,
00176 TAG_PLAYLIST_TRACKLIST_TRACK_CREATOR,
00177 TAG_PLAYLIST_TRACKLIST_TRACK_ANNOTATION,
00178 TAG_PLAYLIST_TRACKLIST_TRACK_INFO,
00179 TAG_PLAYLIST_TRACKLIST_TRACK_IMAGE,
00180 TAG_PLAYLIST_TRACKLIST_TRACK_ALBUM,
00181 TAG_PLAYLIST_TRACKLIST_TRACK_TRACKNUM,
00182 TAG_PLAYLIST_TRACKLIST_TRACK_DURATION,
00183 TAG_PLAYLIST_TRACKLIST_TRACK_LINK,
00184 TAG_PLAYLIST_TRACKLIST_TRACK_META,
00185 TAG_PLAYLIST_TRACKLIST_TRACK_EXTENSION,
00186
00187
00188
00189
00190 TAG_USER = 0x1000
00191 };
00192
00193
00194 class XspfProps;
00195 class XspfDateTime;
00196 class XspfTrack;
00197 class XspfReaderCallback;
00198 template <class T> class XspfStack;
00199 class XspfChunkCallback;
00200
00201 class XspfExtensionReaderFactory;
00202 class XspfExtensionReader;
00203 class XspfReaderPrivate;
00204
00205
00209 class XspfReader {
00210
00211 private:
00213 XspfReaderPrivate * const d;
00214
00215
00216 public:
00222 XspfReader(XspfExtensionReaderFactory * handlerFactory = NULL);
00223
00229 XspfReader(XspfReader const & source);
00230
00236 XspfReader & operator=(XspfReader const & source);
00237
00241 ~XspfReader();
00242
00254 int parseFile(XML_Char const * filename, XspfReaderCallback * callback,
00255 XML_Char const * baseUri);
00256
00269 int parseMemory(char const * memory, int numBytes, XspfReaderCallback * callback,
00270 XML_Char const * baseUri);
00271
00283 int parseChunks(XspfChunkCallback * inputCallback,
00284 XspfReaderCallback * dataCallback, XML_Char const * baseUri);
00285
00294 void limitLengthPerEntityValue(bool enabled);
00295
00304 void limitLookupSumPerEntityValue(bool enabled);
00305
00314 void limitLookupDepthPerEntityValue(bool enabled);
00315
00327 void enableMaliciousXmlDetection(bool enabled);
00328
00337 void setMaxLengthPerEntityValue(int maxLength);
00338
00347 void setMaxLookupSumPerEntityValue(int maxLookupSum);
00348
00357 void setMaxLookupDepthPerEntityValue(int maxLookupDepth);
00358
00359 private:
00363 void makeReusable();
00364
00372 bool handleError(int code, XML_Char const * text);
00373
00382 bool handleError(int code, XML_Char const * format, XML_Char const * param);
00383
00390 void handleFatalError(int code, XML_Char const * text);
00391
00399 void handleFatalError(int code, XML_Char const * format, XML_Char const * param);
00400
00408 bool handleWarning(int code, XML_Char const * text);
00409
00414 void setExpatError();
00415
00419 void stop();
00420
00427 void handleStart(XML_Char const * fullName, XML_Char const ** atts);
00428
00436 bool handleStartOne(XML_Char const * fullName, XML_Char const ** atts);
00437
00445 bool handleStartTwo(XML_Char const * fullName, XML_Char const ** atts);
00446
00454 bool handleStartThree(XML_Char const * fullName, XML_Char const ** atts);
00455
00463 bool handleStartFour(XML_Char const * fullName, XML_Char const ** atts);
00464
00471 void handleCharacters(XML_Char const * s, int len);
00472
00479 void handleEntityDeclaration(XML_Char const * entityName,
00480 XML_Char const * value);
00481
00487 void handleEnd(XML_Char const * fullName);
00488
00495 bool handleEndOne(XML_Char const * fullName);
00496
00503 bool handleEndTwo(XML_Char const * fullName);
00504
00511 bool handleEndThree(XML_Char const * fullName);
00512
00519 bool handleEndFour(XML_Char const * fullName);
00520
00528 bool handlePlaylistAttribs(XML_Char const ** atts);
00529
00538 bool handleMetaLinkAttribs(XML_Char const ** atts, XML_Char const * & rel);
00539
00548 bool handleExtensionAttribs(XML_Char const ** atts,
00549 XML_Char const * & application);
00550
00557 bool handleNoAttribsExceptXmlBase(XML_Char const ** atts);
00558
00562 void clearError();
00563
00571 static void masterStart(void * userData, XML_Char const * fullName, XML_Char const ** atts);
00572
00579 static void masterEnd(void * userData, XML_Char const * fullName);
00580
00588 static void masterCharacters(void * userData, XML_Char const * s, int len);
00589
00603 static void masterEntityDeclaration(void * userData, XML_Char const * entityName,
00604 int is_parameter_entity, XML_Char const * value, int value_length,
00605 XML_Char const * base, XML_Char const * systemId, XML_Char const * publicId,
00606 XML_Char const * notationName);
00607
00615 bool onBeforeParse(XspfReaderCallback * callback,
00616 XML_Char const * baseUri);
00617
00621 void onAfterParse();
00622
00623 public:
00630 static bool isXmlBase(XML_Char const * attributeKey);
00631
00632 private:
00639 bool handleXmlBaseAttribute(XML_Char const * xmlBase);
00640
00648 XML_Char * makeAbsoluteUri(XML_Char const * sourceUri) const;
00649
00655 XspfStack<unsigned int> & getElementStack() const;
00656
00662 XspfStack<std::basic_string<XML_Char> > & getBaseUriStack() const;
00663
00670 void skipFromHere();
00671
00682 bool checkAndSkipNamespace(XML_Char const * fullName,
00683 XML_Char const * & localName);
00684
00689 void notifySuccess() const;
00690
00691 friend class XspfExtensionReader;
00692
00693 };
00694
00695
00696 }
00697
00698 #endif // XSPF_READER_H