Exemple #1
0
DWORD CRestApiManager::GetSearchEvent(string param, HTTP_STREAM* sendParam, CEpgDBManager* epgDB)
{
	DWORD ret = NO_ERR;

	map<string,string> paramMap;
	while(param.size()>0){
		string buff;
		Separate(param, "&", buff, param);
		if(buff.size()>0){
			string key;
			string val;
			Separate(buff, "=", key, val);
			paramMap.insert(pair<string,string>(key, val));
		}
	}

	map<string,string>::iterator itr;
	WORD network = 0xFFFF;
	itr = paramMap.find("network");
	if( itr != paramMap.end() ){
		network = (WORD)atoi(itr->second.c_str());
	}
	WORD days = 0;
	itr = paramMap.find("days");
	if( itr != paramMap.end() ){
		days = (WORD)atoi(itr->second.c_str());
	}

	wstring andkey;
	itr = paramMap.find("andkey");
	if( itr != paramMap.end() ){
		string utf8;
		UrlDecode(itr->second.c_str(), (DWORD)itr->second.size(), utf8);
		UTF8toW(utf8, andkey);
	}
	wstring notkey;
	itr = paramMap.find("notkey");
	if( itr != paramMap.end() ){
		string utf8;
		UrlDecode(itr->second.c_str(), (DWORD)itr->second.size(), utf8);
		UTF8toW(utf8, notkey);
	}
	vector<DWORD> genru;
	itr = paramMap.find("genru");
	if( itr != paramMap.end() ){
		string val = itr->second;
		string id;
		while(val.size() > 0 ){
			Separate(val, "-", id, val);
			genru.push_back((DWORD)atoi(id.c_str()));
		}
	}

	DWORD index = 0;
	itr = paramMap.find("index");
	if( itr != paramMap.end() ){
		index = (DWORD)atoi(itr->second.c_str());
	}
	DWORD count = 200;
	itr = paramMap.find("count");
	if( itr != paramMap.end() ){
		count = (DWORD)atoi(itr->second.c_str());
	}
	WORD basicOnly = 1;
	itr = paramMap.find("basic");
	if( itr != paramMap.end() ){
		basicOnly = (WORD)atoi(itr->second.c_str());
	}

	//検索条件
	EPGDB_SEARCH_KEY_INFO searchKey;
	searchKey.andKey = andkey;
	searchKey.notKey = notkey;
	for( size_t i=0; i<genru.size(); i++){
		EPGDB_CONTENT_DATA item;
		item.content_nibble_level_1 = (BYTE)(genru[i]>>8);
		item.content_nibble_level_2 = (BYTE)(genru[i]&0x00FF);
		searchKey.contentList.push_back(item);
	}
	//対象サービス
	vector<EPGDB_SERVICE_INFO> list;
	if( epgDB->GetServiceList(&list) == TRUE ){
		if( network != 0xFFFF ){
			for( size_t i=0; i<list.size(); i++ ){
				__int64 key = _Create64Key(list[i].ONID,list[i].TSID, list[i].SID);

				if( 0x7880 <= list[i].ONID && list[i].ONID<= 0x7FE8 ){
					//地デジ
					if( (network & 0x0001) > 0 ){
						searchKey.serviceList.push_back(key);
					}
				}else
				if( list[i].ONID == 0x0004 ){
					//BS
					if( (network & 0x0002) > 0 ){
						searchKey.serviceList.push_back(key);
					}
				}else
				if( list[i].ONID == 0x0006 || list[i].ONID == 0x0007 ){
					//CS
					if( (network & 0x0004) > 0 ){
						searchKey.serviceList.push_back(key);
					}
				}else{
					//その他
					if( (network & 0x0008) > 0 ){
						searchKey.serviceList.push_back(key);
					}
				}
			}
		}
	}

	//対象期間
	__int64 chkTime = 0;
	if( days > 0 ){
		SYSTEMTIME now;
		GetLocalTime(&now);
		now.wHour = 0;
		now.wMinute = 0;
		now.wSecond = 0;
		now.wMilliseconds = 0;

		chkTime = ConvertI64Time(now);
		chkTime += days*(29*60*60*I64_1SEC);
	}

	vector<EPGDB_SEARCH_KEY_INFO> keyList;
	keyList.push_back(searchKey);
	vector<EPGDB_EVENT_INFO*> resultList;
	wstring xml = L"";
	string utf8 = "";
	epgDB->SearchEpg(&keyList, &resultList);
	map<__int64, __int64> addID;
	map<__int64, __int64>::iterator itrAdd;
	if ( resultList.size() > 0 ){
		xml += L"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><entry>";
		DWORD total = 0;
		DWORD findCount = 0;

		wstring serviceinfo = L"<items>";
		wstring buff;
		for( size_t i = 0; i<resultList.size(); i++){
			if( days > 0 ){
				if( chkTime < ConvertI64Time(resultList[i]->start_time)){
					continue;
				}
			}
			if( resultList[i]->eventGroupInfo != NULL ){
				BOOL find = FALSE;
				for( size_t j=0; j<resultList[i]->eventGroupInfo->eventDataList.size(); j++ ){
					__int64 evid = _Create64Key2(resultList[i]->eventGroupInfo->eventDataList[j].original_network_id,
						resultList[i]->eventGroupInfo->eventDataList[j].transport_stream_id,
						resultList[i]->eventGroupInfo->eventDataList[j].service_id,
						resultList[i]->eventGroupInfo->eventDataList[j].event_id);
					itrAdd = addID.find(evid);
					if( itrAdd != addID.end() ){
						find = TRUE;
					}
				}
				if( find == TRUE ){
					continue;
				}
			}
			__int64 evid = _Create64Key2(resultList[i]->original_network_id,
				resultList[i]->transport_stream_id,
				resultList[i]->service_id,
				resultList[i]->event_id);
			addID.insert(pair<__int64, __int64>(evid,evid));
			if( total < index ){
				total++;
				continue;
			}
			if( index + count <= total ){
				total++;
				continue;
			}
			total++;
			findCount++;

			EPGDB_EVENT_INFO* eventInfo = resultList[i];

			serviceinfo += L"<eventinfo>";
			Format(buff, L"<ONID>%d</ONID>", eventInfo->original_network_id);
			serviceinfo += buff;
			Format(buff, L"<TSID>%d</TSID>", eventInfo->transport_stream_id);
			serviceinfo += buff;
			Format(buff, L"<SID>%d</SID>", eventInfo->service_id);
			serviceinfo += buff;
			Format(buff, L"<eventID>%d</eventID>", eventInfo->event_id);
			serviceinfo += buff;
			if( eventInfo->StartTimeFlag == 1 ){
				Format(buff, L"<startDate>%04d/%02d/%02d</startDate>", eventInfo->start_time.wYear, eventInfo->start_time.wMonth, eventInfo->start_time.wDay);
				serviceinfo += buff;
				Format(buff, L"<startTime>%02d:%02d:%02d</startTime>", eventInfo->start_time.wHour, eventInfo->start_time.wMinute, eventInfo->start_time.wSecond);
				serviceinfo += buff;
				Format(buff, L"<startDayOfWeek>%d</startDayOfWeek>", eventInfo->start_time.wDayOfWeek);
				serviceinfo += buff;
			}
			if( eventInfo->DurationFlag == 1 ){
				Format(buff, L"<duration>%d</duration>", eventInfo->durationSec);
				serviceinfo += buff;
			}
			if( eventInfo->shortInfo != NULL ){
				wstring chk = eventInfo->shortInfo->event_name;
				CheckXMLChar(chk);
				Format(buff, L"<event_name>%s</event_name>", chk.c_str());
				serviceinfo += buff;

				chk = eventInfo->shortInfo->text_char;
				CheckXMLChar(chk);
				Format(buff, L"<event_text>%s</event_text>", chk.c_str());
				serviceinfo += buff;
			}
			if( eventInfo->contentInfo != NULL ){
				serviceinfo += L"";
				for( size_t k=0; k<eventInfo->contentInfo->nibbleList.size(); k++){
					wstring nibble = L"";
					Format(nibble,L"<contentInfo><nibble1>%d</nibble1><nibble2>%d</nibble2></contentInfo>", 
						eventInfo->contentInfo->nibbleList[k].content_nibble_level_1,
						eventInfo->contentInfo->nibbleList[k].content_nibble_level_2);
					serviceinfo += nibble;
				}
			}
			if( eventInfo->eventGroupInfo != NULL ){
				for( size_t k=0; k<eventInfo->eventGroupInfo->eventDataList.size(); k++){
					wstring group = L"";
					Format(group,L"<groupInfo><ONID>%d</ONID><TSID>%d</TSID><SID>%d</SID><eventID>%d</eventID></groupInfo>", 
						eventInfo->eventGroupInfo->eventDataList[k].original_network_id,
						eventInfo->eventGroupInfo->eventDataList[k].transport_stream_id,
						eventInfo->eventGroupInfo->eventDataList[k].service_id,
						eventInfo->eventGroupInfo->eventDataList[k].event_id
						);
					serviceinfo += group;
				}
			}

			Format(buff, L"<freeCAFlag>%d</freeCAFlag>", eventInfo->freeCAFlag);
			serviceinfo += buff;

			if( basicOnly == 0 ){
				if( eventInfo->extInfo != NULL ){
					wstring chk = eventInfo->extInfo->text_char;
					CheckXMLChar(chk);
					Format(buff, L"<event_ext_text>%s</event_ext_text>", chk.c_str());
					serviceinfo += buff;
				}
				if( eventInfo->componentInfo != NULL ){
					Format(buff, L"<videoInfo><stream_content>%d</stream_content><component_type>%d</component_type><component_tag>%d</component_tag><text>%s</text></videoInfo>", 
						eventInfo->componentInfo->stream_content,
						eventInfo->componentInfo->component_type,
						eventInfo->componentInfo->component_tag,
						eventInfo->componentInfo->text_char.c_str()
						);
					serviceinfo += buff;
				}
				if( eventInfo->audioInfo != NULL ){
					for( size_t k=0; k<eventInfo->audioInfo->componentList.size(); k++ ){
						Format(buff, L"<audioInfo><stream_content>%d</stream_content><component_type>%d</component_type><component_tag>%d</component_tag><stream_type>%d</stream_type><simulcast_group_tag>%d</simulcast_group_tag><ES_multi_lingual_flag>%d</ES_multi_lingual_flag><main_component_flag>%d</main_component_flag><quality_indicator>%d</quality_indicator><sampling_rate>%d</sampling_rate><text>%s</text></audioInfo>", 
							eventInfo->audioInfo->componentList[k].stream_content,
							eventInfo->audioInfo->componentList[k].component_type,
							eventInfo->audioInfo->componentList[k].component_tag,
							eventInfo->audioInfo->componentList[k].stream_type,
							eventInfo->audioInfo->componentList[k].simulcast_group_tag,
							eventInfo->audioInfo->componentList[k].ES_multi_lingual_flag,
							eventInfo->audioInfo->componentList[k].main_component_flag,
							eventInfo->audioInfo->componentList[k].quality_indicator,
							eventInfo->audioInfo->componentList[k].sampling_rate,
							eventInfo->audioInfo->componentList[k].text_char.c_str()
							);
						serviceinfo += buff;
					}
				}
				if( eventInfo->eventRelayInfo != NULL ){
					for( size_t k=0; k<eventInfo->eventRelayInfo->eventDataList.size(); k++){
						wstring group = L"";
						Format(group,L"<relayInfo><ONID>%d</ONID><TSID>%d</TSID><SID>%d</SID><eventID>%d</eventID></relayInfo>", 
							eventInfo->eventRelayInfo->eventDataList[k].original_network_id,
							eventInfo->eventRelayInfo->eventDataList[k].transport_stream_id,
							eventInfo->eventRelayInfo->eventDataList[k].service_id,
							eventInfo->eventRelayInfo->eventDataList[k].event_id
							);
						serviceinfo += group;
					}
				}
			}
			serviceinfo += L"</eventinfo>";
		}
		serviceinfo += L"</items>";

		Format(buff, L"<total>%d</total><index>%d</index><count>%d</count>", total, index, findCount);
		xml += buff;
		xml += serviceinfo;
		xml += L"</entry>";
	}else{
		xml += L"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><entry>";
		xml += L"<err>EPGデータを読み込み中、または存在しません</err>";
		xml += L"</entry>";
	}

	WtoUTF8(xml, utf8);

	sendParam->dataSize = (DWORD)utf8.size();
	sendParam->data = new BYTE[sendParam->dataSize];
	memcpy(sendParam->data, utf8.c_str(), sendParam->dataSize);
	if( sendParam->dataSize > 0 ){
		Format(sendParam->httpHeader, "HTTP/1.0 200 OK\r\nContent-Type: text/xml\r\nContent-Length: %d\r\nConnection: close\r\n\r\n", sendParam->dataSize);
	}else{
		sendParam->httpHeader = "HTTP/1.0 400 Bad Request\r\nConnection: close\r\n\r\n";
	}

	return ret;
}
Exemple #2
0
void CEpgDBManager::SearchEvent(EPGDB_SEARCH_KEY_INFO* key, map<ULONGLONG, SEARCH_RESULT_EVENT>* resultMap)
{
	if( key == NULL || resultMap == NULL ){
		return ;
	}
	
	if( key->andKey.size() == 0 && key->notKey.size() == 0 && key->contentList.size() == 0 && key->videoList.size() == 0 && key->audioList.size() == 0){
		//キーワードもジャンル指定もないので検索しない
		return ;
	}
	
	//キーワード分解
	vector<wstring> andKeyList;
	vector<wstring> notKeyList;

	if( key->regExpFlag == FALSE ){
		//正規表現ではないのでキーワードの分解
		wstring buff = L"";
		if( key->andKey.size() > 0 ){
			wstring andBuff = key->andKey;
			Replace(andBuff, L" ", L" ");
			do{
				Separate(andBuff, L" ", buff, andBuff);
				chgText.ChgText(buff);
				if( buff.size() > 0 ){
					andKeyList.push_back(buff);
				}
			}while( andBuff.size() != 0 );
		}
		
		if( key->notKey.size() > 0 ){
			wstring notBuff = key->notKey;
			Replace(notBuff, L" ", L" ");
			do{
				Separate(notBuff, L" ", buff, notBuff);
				chgText.ChgText(buff);
				if( buff.size() > 0 ){
					notKeyList.push_back(buff);
				}
			}while( notBuff.size() != 0 );
		}
	}else{
		if( key->andKey.size() > 0 ){
			andKeyList.push_back(key->andKey);
		}
		if( key->notKey.size() > 0 ){
			notKeyList.push_back(key->notKey);
		}
	}

	//時間分解
	vector<TIME_SEARCH> timeList;
	for( size_t i=0; i<key->dateList.size(); i++ ){
		DWORD start = key->dateList[i].startHour*60 + key->dateList[i].startMin;
		DWORD end = key->dateList[i].endHour*60 + key->dateList[i].endMin;
		if( key->dateList[i].startDayOfWeek == key->dateList[i].endDayOfWeek ){
			if( start < end ){
				//通常
				TIME_SEARCH item;
				item.week = key->dateList[i].startDayOfWeek;
				item.start = start;
				item.end = end;
				timeList.push_back(item);
			}else{
				//1週間回す
				for( BYTE j=0; j<7; j++ ){
					if( j== key->dateList[i].startDayOfWeek){
						TIME_SEARCH item1;
						item1.week = j;
						item1.start = 0;
						item1.end = end;
						timeList.push_back(item1);
						TIME_SEARCH item2;
						item2.week = j;
						item2.start = start;
						item2.end = 23*60+59;
						timeList.push_back(item2);
					}else{
						TIME_SEARCH item;
						item.week = j;
						item.start = 0;
						item.end = 23*60+59;
						timeList.push_back(item);
					}
				}
			}
		}else{
			BYTE chkWeek = key->dateList[i].startDayOfWeek;
			for( BYTE j=0; j<7; j++ ){
				if( chkWeek == key->dateList[i].startDayOfWeek ){
					TIME_SEARCH item;
					item.week = chkWeek;
					item.start = start;
					item.end = 23*60+59;
					timeList.push_back(item);
				}else if( chkWeek == key->dateList[i].endDayOfWeek ){
					TIME_SEARCH item;
					item.week = chkWeek;
					item.start = 0;
					item.end = end;
					timeList.push_back(item);
					break;
				}else{
					TIME_SEARCH item;
					item.week = chkWeek;
					item.start = 0;
					item.end = 23*60+59;
					timeList.push_back(item);
				}
				chkWeek++;
				if( chkWeek >= 7 ){
					chkWeek = 0;
				}
			}
		}
	}
	
	//サービスごとに検索
	for( size_t i=0; i<key->serviceList.size(); i++ ){
		map<LONGLONG, EPGDB_SERVICE_DATA*>::iterator itrService;
		itrService = this->epgMap.find(key->serviceList[i]);
		if( itrService != this->epgMap.end() ){
			//サービス発見
			map<WORD, EPGDB_EVENT_INFO*>::iterator itrEvent;
			for( itrEvent = itrService->second->eventMap.begin(); itrEvent != itrService->second->eventMap.end(); itrEvent++ ){
				wstring matchKey = L"";
				if( key->freeCAFlag == 1 ){
					//無料放送のみ
					if(itrEvent->second->freeCAFlag == 1 ){
						//有料放送
						continue;
					}
				}else if( key->freeCAFlag == 2 ){
					//有料放送のみ
					if(itrEvent->second->freeCAFlag == 0 ){
						//無料放送
						continue;
					}
				}
				//ジャンル確認
				if( key->contentList.size() > 0 ){
					//ジャンル指定あるのでジャンルで絞り込み
					if( itrEvent->second->contentInfo == NULL ){
						if( itrEvent->second->shortInfo == NULL ){
							//2つめのサービス?対象外とする
							continue;
						}
						//ジャンル情報ない
						BOOL findNo = FALSE;
						for( size_t j=0; j<key->contentList.size(); j++ ){
							if( key->contentList[j].content_nibble_level_1 == 0xFF && 
								key->contentList[j].content_nibble_level_2 == 0xFF
								){
									//ジャンルなしの指定あり
									findNo = TRUE;
									break;
							}
						}
						if( key->notContetFlag == 0 ){
							if( findNo == FALSE ){
								continue;
							}
						}else{
							//NOT条件扱い
							if( findNo == TRUE ){
								continue;
							}
						}
					}else{
						BOOL equal = IsEqualContent(&(key->contentList), &(itrEvent->second->contentInfo->nibbleList));
						if( key->notContetFlag == 0 ){
							if( equal == FALSE ){
								//ジャンル違うので対象外
								continue;
							}
						}else{
							//NOT条件扱い
							if( equal == TRUE ){
								continue;
							}
						}
					}
				}

				//映像確認
				if( key->videoList.size() > 0 ){
					if( itrEvent->second->componentInfo == NULL ){
						continue;
					}
					BOOL findContent = FALSE;
					WORD type = ((WORD)itrEvent->second->componentInfo->stream_content) << 8 | itrEvent->second->componentInfo->component_type;
					for( size_t j=0; j<key->videoList.size(); j++ ){
						if( type == key->videoList[j]){
							findContent = TRUE;
							break;
						}
					}
					if( findContent == FALSE ){
						continue;
					}
				}

				//音声確認
				if( key->audioList.size() > 0 ){
					if( itrEvent->second->audioInfo == NULL ){
						continue;
					}
					BOOL findContent = FALSE;
					for( size_t j=0; j<itrEvent->second->audioInfo->componentList.size(); j++){
						WORD type = ((WORD)itrEvent->second->audioInfo->componentList[j].stream_content) << 8 | itrEvent->second->audioInfo->componentList[j].component_type;
						for( size_t k=0; k<key->audioList.size(); k++ ){
							if( type == key->audioList[k]){
								findContent = TRUE;
								break;
							}
						}
					}
					if( findContent == FALSE ){
						continue;
					}
				}

				//時間確認
				if( timeList.size() > 0 ){
					if( itrEvent->second->StartTimeFlag == FALSE ){
						//開始時間不明なので対象外
						continue;
					}
					BOOL inTime = IsInDateTime(&timeList, itrEvent->second->start_time);
					if( key->notDateFlag == 0 ){
						if( inTime == FALSE ){
							//時間範囲外なので対象外
							continue;
						}
					}else{
						//NOT条件扱い
						if( inTime == TRUE ){
							continue;
						}
					}
				}

				//キーワード確認
				if( notKeyList.size() != 0 ){
					if( IsFindKeyword(key->regExpFlag, key->titleOnlyFlag, &notKeyList, itrEvent->second->shortInfo, itrEvent->second->extInfo, FALSE) == TRUE ){
						//notキーワード見つかったので対象外
						continue;
					}

					//if( key->regExpFlag == FALSE && key->aimaiFlag == 1){
					//	//あいまい検索
					//	if( IsFindLikeKeyword(key->titleOnlyFlag, &notKeyList, itrEvent->second->shortInfo, itrEvent->second->extInfo, FALSE) == TRUE ){
					//		//notキーワード見つかったので対象外
					//		continue;
					//	}
					//}else{
					//	if( IsFindKeyword(key->regExpFlag, key->titleOnlyFlag, &notKeyList, itrEvent->second->shortInfo, itrEvent->second->extInfo, FALSE) == TRUE ){
					//		//notキーワード見つかったので対象外
					//		continue;
					//	}
					//}
				}
				if( andKeyList.size() != 0 ){
					//if( IsFindKeyword(key->regExpFlag, key->titleOnlyFlag, &andKeyList, itrEvent->second->shortInfo, itrEvent->second->extInfo, TRUE) == FALSE ){
					//	//andキーワード見つからなかったので対象外
					//	continue;
					//}
					if( key->regExpFlag == FALSE && key->aimaiFlag == 1){
						//あいまい検索
						if( IsFindLikeKeyword(key->titleOnlyFlag, &andKeyList, itrEvent->second->shortInfo, itrEvent->second->extInfo, TRUE, &matchKey) == FALSE ){
							//andキーワード見つからなかったので対象外
							continue;
						}
					}else{
						if( IsFindKeyword(key->regExpFlag, key->titleOnlyFlag, &andKeyList, itrEvent->second->shortInfo, itrEvent->second->extInfo, TRUE, &matchKey) == FALSE ){
							//andキーワード見つからなかったので対象外
							continue;
						}
					}
				}

				ULONGLONG mapKey = _Create64Key2(
					itrEvent->second->original_network_id,
					itrEvent->second->transport_stream_id,
					itrEvent->second->service_id,
					itrEvent->second->event_id);

				SEARCH_RESULT_EVENT addItem;
				addItem.findKey = matchKey;
				addItem.info = itrEvent->second;
				resultMap->insert(pair<ULONGLONG, SEARCH_RESULT_EVENT>(mapKey, addItem));

			}
		}
	}
/*
	for( itrService = this->epgMap.begin(); itrService != this->epgMap.end(); itrService++ ){
		map<WORD, EPGDB_EVENT_INFO*>::iterator itrEvent;
		for( itrEvent = itrService->second->eventMap.begin(); itrEvent != itrService->second->eventMap.end(); itrEvent++ ){
			if( itrEvent->second->shortInfo != NULL ){
				if( itrEvent->second->shortInfo->search_event_name.find(key->andKey) != string::npos ){
					ULONGLONG mapKey = _Create64Key2(
						itrEvent->second->original_network_id,
						itrEvent->second->transport_stream_id,
						itrEvent->second->service_id,
						itrEvent->second->event_id);

					resultMap->insert(pair<ULONGLONG, EPGDB_EVENT_INFO*>(mapKey, itrEvent->second));
				}
			}
		}
	}
*/
}