/************************************************************************* * Copyright 2009 Ralph Spitzner (rasp@spitzner.org) * * This file is part of Yahdr. * * Yahdr is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Yahdr is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Yahdr. If not, see . **************************************************************************/ #include "defs.hpp" #include "rconf.h" extern string channelselect; extern sql::mysql::MySQL_Driver *driver; extern sql::Connection *con; extern sql::Statement *stmt; CHANNEL *readchans(string *channelselect) { CHANNEL *fchan,*chanp,*jp; APID *apidp; CPIDS *cpidp; char sql[256]; sql::ResultSet *res,*respid; sql::Statement *pstmt; uint16_t ppid; pstmt = con->createStatement(); sprintf(sql,"select * from channels %s;",channelselect->data()); // printf("SQL: %s\n",sql); res = stmt->executeQuery(sql); fchan = chanp = new CHANNEL; memset(fchan,0,sizeof(CHANNEL)); if (res->next() ) { do { chanp->tpnum = res->getInt("tpnum"); chanp->freq = res->getInt("freq"); chanp->bw = res->getInt("bw"); chanp->tsid = res->getInt("tsid"); chanp->qam = (fe_modulation_t)res->getInt("qam"); chanp->pnum = res->getInt("service_id"); chanp->channum = res->getInt("ichan"); chanp->stype = (unsigned char *)strdup(res->getString("s_type").data()); chanp->epg_sched = res->getInt("eit_sched"); chanp->epg_pf = res->getInt("eit_pf"); chanp->provider = (unsigned char *)strdup(res->getString("provider").data()); chanp->name = (unsigned char *)strdup(res->getString("name").data()); ppid = res->getInt("ppid"); sprintf(sql,"select * from pids where intchan=%d ;",chanp->channum); //printf("SQL:%s\n",sql); respid = pstmt->executeQuery(sql); int tcount = 0; if (respid->next()) { int p,t; do { p = respid->getInt("pid"); t = respid->getInt("type"); if (p != 0) { printf("%s adding pid #%d\n",chanp->name,tcount ++); if (!chanp->cpids) { chanp->cpids = new CPIDS [0]; //chanp->cpids->pid = ppid; // PMT pid cpidp = chanp->cpids; //cpidp->next = new CPIDS [0]; /********* it's impossible to get vlc to play this even with NIT et.al ********/ /* cpidp->pid = 0; // NIT pid cpidp = cpidp->next; cpidp->next = new CPIDS [0]; cpidp->pid = 1; // PMT pid cpidp = cpidp->next; cpidp->pid = 16; // PMT pid cpidp->next = new CPIDS [0]; cpidp = cpidp->next; cpidp->pid = 17; // PMT pid cpidp->next = new CPIDS [0]; cpidp = cpidp->next; cpidp->pid = 18; // PMT pid cpidp->next = new CPIDS [0]; cpidp = cpidp->next; cpidp->pid = 20; // PMT pid cpidp->next = new CPIDS [0];*/ //cpidp = cpidp->next; //cpidp = chanp->cpids; cpidp->next = NULL; } else { cpidp = chanp->cpids; while (cpidp->next) cpidp = cpidp->next; cpidp->next = new CPIDS[0]; cpidp = cpidp->next; cpidp->next = NULL; } cpidp->pid = p; cpidp->type = t; /*memset(cpidp->lang,0,4); if(!respid->getString("lang").empty()) strncpy(cpidp->lang,respid->getString("lang").data(),3);*/ } } while (respid->next()); } chanp->next = new CHANNEL; chanp->next->cpids = NULL; chanp->next->next = NULL; chanp = chanp->next; } while (res->next()); } else { printf("No channels in db,go pub, have beer. (run 'Yahdr s' to scan)\n"); exit(0); } jp = fchan; while (jp->next != chanp) { jp = jp->next; } jp->next = NULL; return fchan; }