summaryrefslogtreecommitdiff
path: root/p2pvr/lib/siParsers/table.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/lib/siParsers/table.cpp')
-rw-r--r--p2pvr/lib/siParsers/table.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/p2pvr/lib/siParsers/table.cpp b/p2pvr/lib/siParsers/table.cpp
new file mode 100644
index 0000000..48efd0a
--- /dev/null
+++ b/p2pvr/lib/siParsers/table.cpp
@@ -0,0 +1,76 @@
+#include "table.h"
+#include <string.h>
+#include <stdio.h>
+#include <glibmm.h>
+#include <exceptions.h>
+#include <logger.h>
+
+SimpleMessageException(ErrorReadingData);
+SimpleMessageException(TimeoutReadingData);
+SimpleMessageException(DemuxOpenFailure);
+
+const std::string SiTableParserBase::ISO10646("ISO-10646");
+const std::string SiTableParserBase::EitEncoding("ISO6937");
+const std::string SiTableParserBase::UTF8("UTF8");
+
+SiTableParserBase::SiTableParserBase() :
+ startTime(time(NULL)),
+ incomplete(0)
+{
+}
+
+SiTableParserBase::~SiTableParserBase()
+{
+}
+
+bool
+SiTableParserBase::NewData(const P2PVR::Data & bytes, const Ice::Current&)
+{
+ //Logger()->messagebf(LOG_DEBUG, "%s: Got %d bytes", __PRETTY_FUNCTION__, bytes.size());
+ return ParseInfoTable(&bytes.front(), bytes.size());
+}
+
+SiTableParserBase::StrPtr
+SiTableParserBase::convert(const char * txt, size_t len)
+{
+ if (len == 0) {
+ return boost::shared_ptr<Glib::ustring>(new Glib::ustring());
+ }
+ char enc[20];
+ switch (*txt) {
+ default:
+ EitEncoding.copy(enc, EitEncoding.length());
+ enc[EitEncoding.length()] = '\0';
+ break;
+ case 0x01 ... 0x05:
+ snprintf(enc, sizeof(enc), "ISO-8859-%d\n", txt[0] + 4);
+ txt += 1;
+ len -= 1;
+ break;
+ case 0x10:
+ snprintf(enc, sizeof(enc), "ISO-8859-%02x%02x\n", txt[1], txt[2]);
+ txt += 3;
+ len -= 3;
+ break;
+ case 0x11:
+ ISO10646.copy(enc, ISO10646.length());
+ enc[ISO10646.length()] = '\0';
+ break;
+ case 0x1F:
+ // Values for the first byte of "0x00", "0x06" to "0x0F", and "0x12" to "0x1F" are reserved for future use.
+ //fprintf(stderr, "Reserved encoding: %02x\n", txt[0]);
+ //fprintf(stderr, "%d: %.*s\n", txt[1], len - 2, txt + 2);
+ case 0x06 ... 0x0F:
+ case 0x12 ... 0x1E:
+ case 0x00: // empty string
+ return boost::shared_ptr<Glib::ustring>(new Glib::ustring());
+ }
+ size_t used = 0, newlen = 0;
+ GError * err = NULL;
+ boost::shared_ptr<gchar> utf8 = boost::shared_ptr<gchar>(g_convert(txt, len, "utf-8", enc, &used, &newlen, &err), g_free);
+ if (err) {
+ throw Glib::ConvertError(err);
+ }
+ return boost::shared_ptr<Glib::ustring>(new Glib::ustring(utf8.get()));
+}
+