int http_match(const struct ipt_weburl_info* info, const unsigned char* packet_data, int packet_length) { int test = 0; /* printk("found a http web page request\n"); */ char path[625] = ""; char host[625] = ""; int path_start_index; int path_end_index; int last_header_index; char last_two_buf[2]; int end_found; char* host_match; char* test_prefixes[6]; int prefix_index; /* get path portion of URL */ path_start_index = (int)(strstr((char*)packet_data, " ") - (char*)packet_data); while( packet_data[path_start_index] == ' ') { path_start_index++; } path_end_index= (int)(strstr( (char*)(packet_data+path_start_index), " ") - (char*)packet_data); if(path_end_index > 0) { int path_length = path_end_index-path_start_index; path_length = path_length < 625 ? path_length : 624; /* prevent overflow */ memcpy(path, packet_data+path_start_index, path_length); path[ path_length] = '\0'; } /* get header length */ last_header_index = 2; memcpy(last_two_buf,(char*)packet_data, 2); end_found = 0; while(end_found == 0 && last_header_index < packet_length) { char next = (char)packet_data[last_header_index]; if(next == '\n') { end_found = last_two_buf[1] == '\n' || (last_two_buf[0] == '\n' && last_two_buf[1] == '\r') ? 1 : 0; } if(end_found == 0) { last_two_buf[0] = last_two_buf[1]; last_two_buf[1] = next; last_header_index++; } } /* get host portion of URL */ host_match = strnistr( (char*)packet_data, "Host:", last_header_index); if(host_match != NULL) { int host_end_index; host_match = host_match + 5; /* character after "Host:" */ while(host_match[0] == ' ') { host_match = host_match+1; } host_end_index = 0; while( host_match[host_end_index] != '\n' && host_match[host_end_index] != '\r' && host_match[host_end_index] != ' ' && host_match[host_end_index] != ':' && ((char*)host_match - (char*)packet_data)+host_end_index < last_header_index ) { host_end_index++; } memcpy(host, host_match, host_end_index); host_end_index = host_end_index < 625 ? host_end_index : 624; /* prevent overflow */ host[host_end_index] = '\0'; } /* printk("host = \"%s\", path =\"%s\"\n", host, path); */ switch(info->match_part) { case WEBURL_DOMAIN_PART: test = do_match_test(info->match_type, info->test_str, host); if(!test && strstr(host, "www.") == host) { test = do_match_test(info->match_type, info->test_str, ((char*)host+4) ); } break; case WEBURL_PATH_PART: test = do_match_test(info->match_type, info->test_str, path); if( !test && path[0] == '/' ) { test = do_match_test(info->match_type, info->test_str, ((char*)path+1) ); } break; case WEBURL_ALL_PART: test_prefixes[0] = "http://"; test_prefixes[1] = ""; test_prefixes[2] = NULL; for(prefix_index=0; test_prefixes[prefix_index] != NULL && test == 0; prefix_index++) { char test_url[1250]; test_url[0] = '\0'; strcat(test_url, test_prefixes[prefix_index]); strcat(test_url, host); if(strcmp(path, "/") != 0) { strcat(test_url, path); } test = do_match_test(info->match_type, info->test_str, test_url); if(!test && strcmp(path, "/") == 0) { strcat(test_url, path); test = do_match_test(info->match_type, info->test_str, test_url); } /* printk("test_url = \"%s\", test=%d\n", test_url, test); */ } if(!test && strstr(host, "www.") == host) { char* www_host = ((char*)host+4); for(prefix_index=0; test_prefixes[prefix_index] != NULL && test == 0; prefix_index++) { char test_url[1250]; test_url[0] = '\0'; strcat(test_url, test_prefixes[prefix_index]); strcat(test_url, www_host); if(strcmp(path, "/") != 0) { strcat(test_url, path); } test = do_match_test(info->match_type, info->test_str, test_url); if(!test && strcmp(path, "/") == 0) { strcat(test_url, path); test = do_match_test(info->match_type, info->test_str, test_url); } /* printk("test_url = \"%s\", test=%d\n", test_url, test); */ } } break; } /* * If invert flag is set, return true if it didn't match */ test = info->invert ? !test : test; return test; }
bool CPlaylist::LoadParam() { DWORD dwIndex; DWORD dwFileSize; DWORD dwFileAttrib; const char * pszASXFile; const char * pszParam; HANDLE hFile; HANDLE hMap; bool bLastEntry = false; bool bGenerator = false; enum {E_INVALID = 0, E_NOERROR, E_EOF, E_BADMATCH} eError = E_NOERROR; if (m_bHidden) { dwFileAttrib = FILE_ATTRIBUTE_HIDDEN; } else { dwFileAttrib = FILE_ATTRIBUTE_NORMAL; } hFile = CreateFileForMapping(m_pszPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, dwFileAttrib, NULL); if (INVALID_HANDLE_VALUE == hFile) { return false; } hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); if (NULL == hMap) { CloseHandle(hFile); return false; } dwFileSize = GetFileSize(hFile, NULL); pszASXFile = (char*)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0); if (NULL == pszASXFile) { CloseHandle(hMap); CloseHandle(hFile); return false; } // find the occurance of "LAST ENTRY" (case insensitive) pszParam = (char*)strnistr(pszASXFile, dwFileSize, "LAST ENTRY"); if((((DWORD)pszParam)-(DWORD)pszASXFile) > (DWORD)pszASXFile) { CloseHandle(hMap); CloseHandle(hFile); return false; } dwIndex = (DWORD)pszParam - (DWORD)pszASXFile; if (pszParam) { dwIndex += strlen("LAST ENTRY"); // skip the trailing quote if (dwIndex < dwFileSize) { if ('\"' == pszASXFile[dwIndex]) { dwIndex++; } } else if (E_NOERROR == eError) { eError = E_EOF; } // skip spaces while (E_NOERROR == eError && dwIndex < dwFileSize && isspace(pszASXFile[dwIndex])) { dwIndex++; } if (dwIndex >= dwFileSize && E_NOERROR == eError) { eError = E_EOF; } // match "VALUE" if (E_NOERROR == eError && dwIndex < dwFileSize && 0 == _strnicmp(pszASXFile + dwIndex, "VALUE", 5)) { dwIndex += strlen("VALUE"); } else if (E_NOERROR == eError && dwIndex > dwFileSize) { eError = E_EOF; } // skip spaces while (E_NOERROR == eError && dwIndex < dwFileSize && isspace(pszASXFile[dwIndex])) { dwIndex++; } if (dwIndex >= dwFileSize && E_NOERROR == eError) { eError = E_EOF; } // match "=" if (dwIndex < dwFileSize && E_NOERROR == eError) { if ('=' == pszASXFile[dwIndex]) { dwIndex++; } else { eError = E_BADMATCH; } } else if (E_NOERROR == eError) { eError = E_EOF; } // skip spaces while (E_NOERROR == eError && dwIndex < dwFileSize && isspace(pszASXFile[dwIndex])) { dwIndex++; } if (dwIndex >= dwFileSize && E_NOERROR == eError) { eError = E_EOF; } // match quote if (dwIndex < dwFileSize && E_NOERROR == eError) { if ('\"' == pszASXFile[dwIndex]) { dwIndex++; } } else if (E_NOERROR == eError) { eError = E_EOF; } // get the number if (E_NOERROR == eError && dwIndex < dwFileSize && 1 == sscanf(pszASXFile + dwIndex, "%d", &m_iCurrentTrack)) { bLastEntry = true; } else if (E_NOERROR == eError && dwIndex >= dwFileSize) { eError = E_BADMATCH; SetCurrent(-1); } } // find the occurance of "GENERATOR" (case insensitive) pszParam = (char*)strnistr(pszASXFile, dwFileSize, "GENERATOR"); dwIndex = (DWORD)pszParam - (DWORD)pszASXFile; if (pszParam) { dwIndex += strlen("GENERATOR"); // skip the trailing quote if (dwIndex < dwFileSize) { if ('\"' == pszASXFile[dwIndex]) { dwIndex++; } } else if (E_NOERROR == eError) { eError = E_EOF; } // skip spaces while (E_NOERROR == eError && dwIndex < dwFileSize && isspace(pszASXFile[dwIndex])) { dwIndex++; } if (dwIndex >= dwFileSize && E_NOERROR == eError) { eError = E_EOF; } // match "VALUE" if (E_NOERROR == eError && dwIndex < dwFileSize && 0 == _strnicmp(pszASXFile + dwIndex, "VALUE", 5)) { dwIndex += strlen("VALUE"); } else if (E_NOERROR == eError && dwIndex > dwFileSize) { eError = E_EOF; } // skip spaces while (E_NOERROR == eError && dwIndex < dwFileSize && isspace(pszASXFile[dwIndex])) { dwIndex++; } if (dwIndex >= dwFileSize && E_NOERROR == eError) { eError = E_EOF; } // match "=" if (dwIndex < dwFileSize && E_NOERROR == eError) { if ('=' == pszASXFile[dwIndex]) { dwIndex++; } else { eError = E_BADMATCH; } } else if (E_NOERROR == eError) { eError = E_EOF; } // skip spaces while (E_NOERROR == eError && dwIndex < dwFileSize && isspace(pszASXFile[dwIndex])) { dwIndex++; } if (dwIndex >= dwFileSize && E_NOERROR == eError) { eError = E_EOF; } // match quote if (dwIndex < dwFileSize && E_NOERROR == eError) { if ('\"' == pszASXFile[dwIndex]) { dwIndex++; } } else if (E_NOERROR == eError) { eError = E_EOF; } // examine the value if (E_NOERROR == eError && dwIndex < dwFileSize && 0 == _strnicmp(pszASXFile + dwIndex, "CEPLAYER", 8)) { bGenerator = true; m_bCEPlaylist = true; } else if (E_NOERROR == eError && dwIndex >= dwFileSize) { eError = E_BADMATCH; } } UnmapViewOfFile(pszASXFile); CloseHandle(hMap); CloseHandle(hFile); return bLastEntry && bGenerator; }