bool DVBevents::shortEventDesc( unsigned char *buf, EventDesc *desc ) { QString name, text; int len, len2; ShortEvent *ev; if ( !safeLen( buf+6 ) ) return false; len = getBits(buf,40,8); if ( !safeLen( buf+6+len ) ) return false; name = getText( buf+6, len ); if ( !safeLen( buf+6+len+1 ) ) return false; len2 = getBits(buf+6+len,0,8); if ( !safeLen( buf+7+len+len2 ) ) return false; text = getText( buf+7+len, len2); if ( desc->title.isEmpty() ) { desc->title=name; desc->subtitle=text; return true; } desc->shortEvents.append( new ShortEvent() ); ev = desc->shortEvents.getLast(); ev->name = name; ev->text = text; return true; }
bool DVBevents::extEventDesc( unsigned char *buf, EventDesc *desc ) { int loop, len1, len2; unsigned char *b = buf; QString s; if ( !safeLen( b+7 ) ) return false; loop = getBits(b+6,0,8); b +=7; while ( loop>0 ) { if ( !safeLen( b+1 ) ) return false; len1 = getBits(b,0,8); if ( !safeLen( b+1+len1 ) ) return false; s = getText(b+1,len1); if ( !safeLen( b+1+len1+1 ) ) return false; len2 = getBits(b+1+len1,0,8); if ( !safeLen( buf+2+len1+len2 ) ) return false; if ( !s.isEmpty() ) s = s+" : "; s = s+getText(b+2+len1,len2); desc->extEvents.append( new QString( s ) ); b +=(2+len1+len2); loop -=(2+len1+len2); } if ( !safeLen( b+1 ) ) return false; len1 = getBits(b,0,8); if ( !safeLen( b+1+len1 ) ) return false; s = getText(b+1,len1); desc->extEvents.append( new QString( s ) ); return true; }
static isc_result_t odbc_connect(odbc_instance_t *dbi, odbc_db_t **dbc) { odbc_db_t *ndb = *dbc; SQLRETURN sqlRes; isc_result_t result = ISC_R_SUCCESS; if (ndb != NULL) { /* * if db != null, we have to do some cleanup * if statement handle != null free it */ if (ndb->stmnt != NULL) { SQLFreeHandle(SQL_HANDLE_STMT, ndb->stmnt); ndb->stmnt = NULL; } /* if connection handle != null free it */ if (ndb->dbc != NULL) { SQLFreeHandle(SQL_HANDLE_DBC, ndb->dbc); ndb->dbc = NULL; } } else { ndb = isc_mem_allocate(ns_g_mctx, sizeof(odbc_db_t)); if (ndb == NULL) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Odbc driver unable to allocate memory"); return ISC_R_NOMEMORY; } memset(ndb, 0, sizeof(odbc_db_t)); } sqlRes = SQLAllocHandle(SQL_HANDLE_DBC, dbi->sql_env, &(ndb->dbc)); if (!sqlOK(sqlRes)) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Odbc driver unable to allocate memory"); result = ISC_R_NOMEMORY; goto cleanup; } sqlRes = SQLConnect(ndb->dbc, dbi->dsn, safeLen(dbi->dsn), dbi->user, safeLen(dbi->user), dbi->pass, safeLen(dbi->pass)); if (!sqlOK(sqlRes)) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Odbc driver unable to connect"); result = ISC_R_FAILURE; goto cleanup; } sqlRes = SQLAllocHandle(SQL_HANDLE_STMT, ndb->dbc, &(ndb->stmnt)); if (!sqlOK(sqlRes)) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Odbc driver unable to allocate memory"); result = ISC_R_NOMEMORY; goto cleanup; } *dbc = ndb; return ISC_R_SUCCESS; cleanup: if (ndb != NULL) { /* if statement handle != null free it */ if (ndb->stmnt != NULL) { SQLFreeHandle(SQL_HANDLE_STMT, ndb->stmnt); ndb->stmnt = NULL; } /* if connection handle != null free it */ if (ndb->dbc != NULL) { SQLDisconnect(ndb->dbc); SQLFreeHandle(SQL_HANDLE_DBC, ndb->dbc); ndb->dbc = NULL; } /* free memory holding ndb */ isc_mem_free(ns_g_mctx, ndb); } return result; }
bool DVBevents::tableEIT( unsigned char* buffer ) { unsigned char* buf = buffer; unsigned int length, loop, sid, tid, eid, tsid, sn, lsn, nid; int i, sec; EventDesc *desc=0, *itdesc=0; EventSid *slist; QPtrList<EventDesc> *currentEvents; bool nodesc, parse; QDateTime start, cur, dt; unsigned int cdt = QDateTime::currentDateTime().toTime_t(); tid = getBits(buf,0,8); length = getBits(buf,12,12); sid = getBits(buf,24,16); sn = getBits(buf,48,8); lsn = getBits(buf,56,8); tsid = getBits(buf,64,16); nid = getBits(buf,80,16); length -=11; buf +=14; slist = currentSrc->getEventSid( nid, tsid, sid ); if ( !slist ) return false; slist->lock(); currentEvents = slist->getEvents(); QPtrListIterator<EventDesc> it( *currentEvents ); while ( length>4 ) { nodesc=parse=false; if ( !safeLen( buf+2 ) ) goto stop; eid = getBits(buf,0,16); if ( !safeLen( buf+2+5 ) ) goto stop; start = getDateTime( buf+2 ); nodesc=parse=true; it.toFirst(); while ( (desc=it.current())!=0 ) { if ( desc->sid==sid ) { if ( desc->startDateTime==start || desc->eid==eid ) { if ( desc->tid==0x4e && tid!=0x4e ) { parse = false; nodesc = false; break; } else { nodesc = false; if ( (cdt-desc->loop)<300 ) { // only reparse events every 300 seconds parse = false; } else { desc->extEvents.clear(); desc->shortEvents.clear(); desc->title=desc->subtitle=""; } break; } } } ++it; } if ( nodesc ) desc = new EventDesc(); if ( parse ) { if ( !safeLen( buf+10 ) ) goto stop; desc->duration = getTime( buf+7 ); if ( !safeLen( buf+11 ) ) goto stop; desc->running = getBits(buf,80,3); desc->sid = sid; desc->tid = tid; desc->tsid = tsid; desc->nid = nid; desc->lsn = lsn; desc->sn = sn; desc->eid = eid; desc->loop = cdt; } if ( desc->sn != sn ) { slist->unlock(); return false; } if ( !safeLen( buf+12 ) ) goto stop; loop = getBits(buf,84,12); buf +=12; length -=(12+loop); while ( loop>0 ) { if ( parse ) { if ( !safeLen( buf+1 ) ) goto stop; switch ( getBits(buf,0,8) ) { case 0x4D : if ( !shortEventDesc( buf, desc ) ) goto stop; break; case 0x4E : if ( !extEventDesc( buf, desc ) ) goto stop; break; default : break; } } if ( !safeLen( buf+2 ) ) goto stop; loop -=( getBits(buf,8,8)+2 ); buf +=( getBits(buf,8,8)+2 ); } //out: if ( parse ) { if ( !nodesc ) { if ( start==desc->startDateTime ) goto ifend; currentEvents->take( currentEvents->find( desc ) ); } desc->startDateTime = start; for ( i=0; i<(int)currentEvents->count(); i++ ) { itdesc = currentEvents->at(i); if ( desc->startDateTime<itdesc->startDateTime ) { currentEvents->insert( i, desc ); break; } itdesc = 0; } if ( !itdesc ) currentEvents->append( desc ); } ifend: if ( parse ) ++(desc->sn); if ( nodesc ) { cur = QDateTime::currentDateTime(); dt = desc->startDateTime; sec = desc->duration.hour()*3600+desc->duration.minute()*60+desc->duration.second(); if ( dt.addSecs( sec )<cur || desc->title.length()<3 ) { currentEvents->remove( desc ); } else desc->source = currentSrc->getSource(); } } slist->unlock(); return true; stop: slist->unlock(); fprintf( stderr, "Stop parsing EIT (%d:%d)\n", adapter, tuner ); if ( nodesc ) delete desc; return false; }