00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030 #include <stdio.h>
00031 #include "expat.h"
00032 #include "browserTypes.h"
00033 #include "indexFileHandler.h"
00034 #include "browserLog.h"
00035 #include <libermanifest/ermanifest.h>
00036
00037 #define BUFFER_SIZE 256
00038 #define MAX_LEN 1024
00039 #define INDEX_DEBUG 0
00040
00041 #if (INDEX_DEBUG)
00042 #define TRACE(x, args...) fprintf(stderr, "(BR_TRACE)" __FILE__ ":%d,%s() " x "\n", __LINE__, __func__ , ##args)
00043 #else
00044 #define TRACE(x...) do {} while(0)
00045 #endif
00046
00047 #if 0
00048
00049 static int url_compare(char *abs_url1, char *url2);
00050
00051 static XML_Parser parser_create(void);
00052 static void parser_destroy(XML_Parser p);
00053
00054 static void XMLCALL page_list_start_element(void *userData, const char *name, const char **atts);
00055 static void XMLCALL page_list_end_element(void *userData, const char *name);
00056
00057 static void XMLCALL page_nmbr_start_element(void *userData, const char *name, const char **atts);
00058 static void XMLCALL page_nmbr_end_element(void *userData, const char *name);
00059
00060 static void XMLCALL page_url_start_element(void *userData, const char *name, const char **atts);
00061 static void XMLCALL page_url_end_element(void *userData, const char *name);
00062
00063 static XML_Parser parser_create(void)
00064 {
00065 XML_Parser p = XML_ParserCreate(NULL);
00066
00067 if (!p)
00068 {
00069 BR_ERRORPRINTF("Couldn't allocate memory for parser");
00070 }
00071
00072 return p;
00073 }
00074
00075 static void parser_destroy(XML_Parser p)
00076 {
00077
00078 XML_ParserFree(p);
00079 }
00080
00081 void index_file_close(FILE * indexFile)
00082 {
00083 if (indexFile != NULL)
00084 {
00085 BR_MANIFESTPRINTF("0x%x", (unsigned int) indexFile);
00086 fclose(indexFile);
00087 indexFile = NULL;
00088 }
00089 }
00090
00091 FILE *index_file_init(char *file)
00092 {
00093 FILE *indexFile = NULL;
00094
00095 BR_MANIFESTPRINTF("location %s", file);
00096
00097 if ((indexFile = fopen(file, "r")) == NULL)
00098 {
00099 BR_WARNPRINTF("Couldn't open %s", file);
00100 }
00101 else
00102 {
00103 BR_MANIFESTPRINTF("index_file_init 0x%x", (unsigned int) indexFile);
00104 }
00105
00106 return indexFile;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 char *index_file_get_page_location(FILE * indexFile, char *type, int number)
00116 {
00117 XML_Parser theParser;
00118 char buf[BUFFER_SIZE];
00119 int done;
00120 char *returnValue = NULL;
00121 PageUrlInfo *pageUrlInfo;
00122
00123 BR_MANIFESTPRINTF("index_file_get_page_location file 0x%x type %s url %d", indexFile, type, number);
00124
00125 if (type && indexFile)
00126 {
00127 theParser = parser_create();
00128 pageUrlInfo = g_new0(PageUrlInfo, 1);
00129
00130
00131 pageUrlInfo->searchedNmbr = number;
00132 pageUrlInfo->currentNmbr = INVALID_PAGE_NMBR;
00133
00134 pageUrlInfo->searchedType = type;
00135 pageUrlInfo->currentType = NULL;
00136
00137 pageUrlInfo->searchedPage = NULL;
00138 pageUrlInfo->currentPage = NULL;
00139
00140 XML_SetUserData(theParser, pageUrlInfo);
00141 XML_SetElementHandler(theParser, page_url_start_element, page_url_end_element);
00142
00143 rewind(indexFile);
00144
00145 while ((!feof(indexFile)) && (pageUrlInfo->searchedPage == NULL))
00146 {
00147 size_t len = fread(buf, 1, sizeof(buf), indexFile);
00148
00149 done = len < sizeof(buf);
00150 if (XML_Parse(theParser, buf, len, done) == XML_STATUS_ERROR)
00151 {
00152 BR_MANIFESTPRINTF("%s at line %d", XML_ErrorString(XML_GetErrorCode(theParser)), XML_GetCurrentLineNumber(theParser));
00153 return NULL;
00154 }
00155 }
00156
00157 returnValue = pageUrlInfo->searchedPage;
00158
00159
00160 if (pageUrlInfo->currentType)
00161 {
00162 g_free(pageUrlInfo->currentType);
00163 pageUrlInfo->currentType = NULL;
00164 }
00165
00166 if (pageUrlInfo->currentPage)
00167 {
00168 g_free(pageUrlInfo->currentPage);
00169 pageUrlInfo->currentPage = NULL;
00170 }
00171 g_free(pageUrlInfo);
00172
00173 parser_destroy(theParser);
00174 }
00175 return returnValue;
00176 }
00177
00178 static void XMLCALL page_url_start_element(void *userData, const char *name, const char **attr)
00179 {
00180 gint result = -1;
00181 PageUrlInfo *pageUrlInfo = (PageUrlInfo *) userData;
00182 gint i;
00183
00184 BR_MANIFESTPRINTF("page_url_start_element -- %s", name);
00185
00186 result = strcmp("page", name);
00187
00188 if (result == 0)
00189 {
00190 if ((pageUrlInfo->currentType != NULL)
00191 && (pageUrlInfo->searchedType != NULL) && (strcmp(pageUrlInfo->currentType, pageUrlInfo->searchedType) == 0))
00192 {
00193
00194 for (i = 0; attr[i]; i += 2)
00195 {
00196 BR_MANIFESTPRINTF("%s='%s'", attr[i], attr[i + 1]);
00197
00198 result = strcmp(attr[i], "number");
00199
00200 if (result == 0)
00201 {
00202 pageUrlInfo->currentNmbr = atoi(attr[i + 1]);
00203 BR_MANIFESTPRINTF("page_url_start_element-- update of the currentNmbr to %d", pageUrlInfo->currentNmbr);
00204 }
00205
00206 result = strcmp(attr[i], "url");
00207
00208 if (result == 0)
00209 {
00210 pageUrlInfo->currentPage = g_strdup(attr[i + 1]);
00211 BR_MANIFESTPRINTF("page_url_start_element -- found %s page url attribute\n", attr[i + 1]);
00212 }
00213
00214 }
00215 }
00216 }
00217 else
00218 {
00219 result = strcmp("pagelist", name);
00220
00221 if (result == 0)
00222 {
00223 BR_MANIFESTPRINTF("page_url_start_element -- found %s tag", name);
00224
00225 for (i = 0; attr[i]; i += 2)
00226 {
00227 BR_MANIFESTPRINTF(" %s='%s'", attr[i], attr[i + 1]);
00228
00229 result = strcmp(attr[i], "type");
00230 if (result == 0)
00231 {
00232 pageUrlInfo->currentType = g_strdup(attr[i + 1]);
00233 BR_MANIFESTPRINTF("page_url_start_element -- found %s type attribute", pageUrlInfo->currentType);
00234 }
00235 }
00236 }
00237 }
00238
00239 }
00240
00241 static void XMLCALL page_url_end_element(void *userData, const char *name)
00242 {
00243 gint result = -1;
00244 PageUrlInfo *pageUrlInfo = (PageUrlInfo *) userData;
00245
00246 BR_MANIFESTPRINTF("page_url_end_element -- page %s with %d", pageUrlInfo->currentType, pageUrlInfo->currentNmbr);
00247
00248 if ((pageUrlInfo->currentType != NULL) && (pageUrlInfo->searchedType != NULL))
00249 {
00250 result = strcmp(pageUrlInfo->currentType, pageUrlInfo->searchedType);
00251 }
00252
00253 if (result == 0)
00254 {
00255 result = strcmp("page", name);
00256
00257 if (result == 0)
00258 {
00259 BR_MANIFESTPRINTF("page_url_end_element -- found %s tag -- compare %d with %d", name, pageUrlInfo->currentNmbr,
00260 pageUrlInfo->searchedNmbr);
00261
00262 if (pageUrlInfo->currentNmbr == pageUrlInfo->searchedNmbr)
00263 {
00264 pageUrlInfo->searchedPage = g_strdup(pageUrlInfo->currentPage);
00265 BR_MANIFESTPRINTF("**** page_url_end_element -- found %s type (nmbr %d) => url %s ******", pageUrlInfo->currentType,
00266 pageUrlInfo->currentNmbr, pageUrlInfo->searchedPage);
00267 }
00268 }
00269 }
00270 }
00271
00272
00273
00274
00275
00276
00277 int index_file_get_page_number(FILE * indexFile, char *type, char *url)
00278 {
00279 XML_Parser theParser;
00280 char buf[BUFFER_SIZE];
00281 int done;
00282 int returnValue = 1;
00283 PageNmbrInfo *pageNmbrInfo;
00284
00285 if (url && indexFile)
00286 {
00287 theParser = parser_create();
00288 pageNmbrInfo = g_new0(PageNmbrInfo, 1);
00289
00290
00291 pageNmbrInfo->searchedNmbr = INVALID_PAGE_NMBR;
00292 pageNmbrInfo->currentNmbr = INVALID_PAGE_NMBR;
00293
00294 pageNmbrInfo->searchedPage = url;
00295 pageNmbrInfo->currentPage = NULL;
00296
00297 XML_SetUserData(theParser, pageNmbrInfo);
00298 XML_SetElementHandler(theParser, page_nmbr_start_element, page_nmbr_end_element);
00299
00300 rewind(indexFile);
00301
00302 while ((!feof(indexFile)) && (pageNmbrInfo->searchedNmbr == INVALID_PAGE_NMBR))
00303 {
00304 size_t len = fread(buf, 1, sizeof(buf), indexFile);
00305
00306 done = len < sizeof(buf);
00307 if (XML_Parse(theParser, buf, len, done) == XML_STATUS_ERROR)
00308 {
00309 BR_MANIFESTPRINTF("%s at line %d", XML_ErrorString(XML_GetErrorCode(theParser)), XML_GetCurrentLineNumber(theParser));
00310 return INVALID_PAGE_NMBR;
00311 }
00312 }
00313 returnValue = pageNmbrInfo->searchedNmbr;
00314
00315
00316 g_free(pageNmbrInfo);
00317
00318 parser_destroy(theParser);
00319 }
00320 return returnValue;
00321 }
00322
00323 static void XMLCALL page_nmbr_start_element(void *userData, const char *name, const char **attr)
00324 {
00325 gint result = -1;
00326 PageNmbrInfo *pageNmbrInfo = (PageNmbrInfo *) userData;
00327 gint i;
00328
00329 BR_MANIFESTPRINTF("page_nmbr_start_element -- %s", name);
00330 result = strcmp("page", name);
00331
00332 if (result == 0)
00333 {
00334 BR_MANIFESTPRINTF("page_nmbr_start_element -- found %s tag", name);
00335
00336 for (i = 0; attr[i]; i += 2)
00337 {
00338 BR_MANIFESTPRINTF(" %s='%s'", attr[i], attr[i + 1]);
00339
00340 result = strcmp(attr[i], "url");
00341 if (result == 0)
00342 {
00343 pageNmbrInfo->currentPage = g_strdup(attr[i + 1]);
00344 BR_MANIFESTPRINTF("page_nmbr_start_element -- found %s url attribute", attr[i + 1]);
00345 }
00346
00347 result = strcmp(attr[i], "number");
00348 if (result == 0)
00349 {
00350 pageNmbrInfo->currentNmbr = atoi(attr[i + 1]);
00351 BR_MANIFESTPRINTF("page_nmbr_start_element-- update of the currentNmbr to %d", pageNmbrInfo->currentNmbr);
00352 }
00353 }
00354 }
00355 }
00356
00357 static void XMLCALL page_nmbr_end_element(void *userData, const char *name)
00358 {
00359 gint result = -1;
00360 PageNmbrInfo *pageNmbrInfo = (PageNmbrInfo *) userData;
00361
00362 BR_MANIFESTPRINTF("page_nmbr_end_element -- page %s with %d", pageNmbrInfo->currentPage, pageNmbrInfo->currentNmbr);
00363
00364 result = strcmp("page", name);
00365
00366 if (result == 0)
00367 {
00368 BR_MANIFESTPRINTF("page_nmbr_end_element -- found %s tag", name);
00369
00370
00371 result = url_compare(pageNmbrInfo->searchedPage, pageNmbrInfo->currentPage);
00372
00373 if (result == 0)
00374 {
00375 pageNmbrInfo->searchedNmbr = pageNmbrInfo->currentNmbr;
00376 BR_MANIFESTPRINTF("**** page_nmbr_end_element -- found %s type => count %d ******", pageNmbrInfo->searchedPage,
00377 pageNmbrInfo->searchedNmbr);
00378 }
00379
00380
00381 if (pageNmbrInfo->currentPage)
00382 {
00383 g_free(pageNmbrInfo->currentPage);
00384 pageNmbrInfo->currentPage = NULL;
00385 }
00386 }
00387 }
00388
00389
00390
00391
00392
00393
00394
00395 int index_file_get_page_count(FILE * indexFile, char *type)
00396 {
00397 XML_Parser theParser;
00398 char buf[BUFFER_SIZE];
00399 int done;
00400 int returnValue = DEFAULT_PAGE_COUNT;
00401 PageTypeInfo *pageTypeInfo;
00402
00403 if (type && indexFile)
00404 {
00405 theParser = parser_create();
00406 pageTypeInfo = g_new0(PageTypeInfo, 1);
00407
00408
00409 pageTypeInfo->searchedCount = INVALID_PAGE_COUNT;
00410 pageTypeInfo->currentCount = INVALID_PAGE_COUNT;
00411
00412 pageTypeInfo->searchedType = type;
00413 pageTypeInfo->currentType = NULL;
00414
00415 BR_MANIFESTPRINTF("index_file_get_page_count -- searchedType = %s", pageTypeInfo->searchedType);
00416
00417 XML_SetUserData(theParser, pageTypeInfo);
00418 XML_SetElementHandler(theParser, page_list_start_element, page_list_end_element);
00419
00420 rewind(indexFile);
00421
00422 while ((!feof(indexFile)) && (pageTypeInfo->searchedCount == INVALID_PAGE_COUNT))
00423 {
00424 size_t len = fread(buf, 1, sizeof(buf), indexFile);
00425
00426 BR_MANIFESTPRINTF("buffer %s", buf);
00427
00428 done = len < sizeof(buf);
00429 if (XML_Parse(theParser, buf, len, done) == XML_STATUS_ERROR)
00430 {
00431 BR_MANIFESTPRINTF("%s at line %d", XML_ErrorString(XML_GetErrorCode(theParser)), XML_GetCurrentLineNumber(theParser));
00432 return INVALID_PAGE_COUNT;
00433 }
00434 }
00435
00436 returnValue = pageTypeInfo->searchedCount;
00437
00438
00439 if (pageTypeInfo->currentType)
00440 {
00441 g_free(pageTypeInfo->currentType);
00442 pageTypeInfo->currentType = NULL;
00443 }
00444 g_free(pageTypeInfo);
00445
00446 parser_destroy(theParser);
00447 }
00448 return returnValue;
00449 }
00450
00451 static void XMLCALL page_list_start_element(void *userData, const char *name, const char **attr)
00452 {
00453 gint result = -1;
00454 PageTypeInfo *pageTypeInfo = (PageTypeInfo *) userData;
00455 gint i;
00456
00457 BR_MANIFESTPRINTF("page_list_start_element -- %s", name);
00458 result = strcmp("pagelist", name);
00459
00460 if (result == 0)
00461 {
00462 BR_MANIFESTPRINTF("page_list_start_element -- found %s tag", name);
00463
00464 for (i = 0; attr[i]; i += 2)
00465 {
00466 BR_MANIFESTPRINTF(" %s='%s'", attr[i], attr[i + 1]);
00467
00468 result = strcmp(attr[i], "type");
00469 if (result == 0)
00470 {
00471 pageTypeInfo->currentType = g_strdup(attr[i + 1]);
00472 BR_MANIFESTPRINTF("page_list_start_element -- found %s type attribute", attr[i + 1]);
00473 }
00474
00475 result = strcmp(attr[i], "count");
00476 if (result == 0)
00477 {
00478 pageTypeInfo->currentCount = atoi(attr[i + 1]);
00479 BR_MANIFESTPRINTF("page_list_start_element-- update of the current type pagecount to %d", pageTypeInfo->currentCount);
00480 }
00481 }
00482 }
00483 }
00484
00485 static void XMLCALL page_list_end_element(void *userData, const char *name)
00486 {
00487 gint result = -1;
00488 PageTypeInfo *pageTypeInfo = (PageTypeInfo *) userData;
00489
00490 BR_MANIFESTPRINTF("page_list_end_element -- pagelist %s with %d", pageTypeInfo->currentType, pageTypeInfo->currentCount);
00491
00492 result = strcmp("pagelist", name);
00493
00494 if (result == 0)
00495
00496 {
00497 BR_MANIFESTPRINTF("page_list_end_element -- found %s tag", name);
00498
00499 result = strcmp(pageTypeInfo->searchedType, pageTypeInfo->currentType);
00500
00501 if (result == 0)
00502 {
00503 pageTypeInfo->searchedCount = pageTypeInfo->currentCount;
00504 BR_MANIFESTPRINTF("**** page_list_end_element -- found %s type => count %d ******", pageTypeInfo->searchedType,
00505 pageTypeInfo->searchedCount);
00506 }
00507 }
00508 }
00509
00510
00511
00512
00513
00514
00515
00516
00517 static int url_compare(char *abs_url1, char *url2)
00518 {
00519 gchar *ptr = url2;
00520
00521 if ((abs_url1) && (url2))
00522 {
00523 while (*ptr == '.' || *ptr == '/')
00524 {
00525 ptr++;
00526 }
00527
00528
00529 if (strstr(abs_url1, ptr) != 0)
00530 {
00531 BR_MANIFESTPRINTF("curently identical URL's %s - %s", abs_url1, ptr);
00532 return 0;
00533 }
00534
00535 }
00536 return -1;
00537 }
00538
00539 #endif
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575 static int contain_url(const char *first , const char *second)
00576 {
00577 if (NULL == first || NULL == second) return 1;
00578 int len1 = strlen(first), len2 = strlen(second);
00579 int min = len1;
00580 if (min > len2) min = len2;
00581
00582 first += len1; second += len2;
00583 for(int i = 0; i <min; ++i)
00584 {
00585 if (*first-- != *second--)
00586 {
00587 return 0;
00588 }
00589 }
00590 return 1;
00591 }
00592
00593
00594 int get_pagelist_length(erManifest * manifest)
00595 {
00596 char xpath[MAX_LEN] = {0};
00597 char type[MAX_LEN] = {0};
00598 int i = 0;
00599 int ret = RET_OK;
00600 while (1)
00601 {
00602 snprintf(xpath, MAX_LEN, "/package/index/pagelist[%d]", i + 1);
00603 ret = ermXmlGetAttributeString(manifest, xpath, "type", type, MAX_LEN);
00604 if (RET_ERR == ret) break;
00605 ++i;
00606 }
00607 return i;
00608 }
00609
00610
00611 PageListItem * pageListItem_create(erManifest * manifest, const int index)
00612 {
00613 char url[MAX_LEN] = {0};
00614 char type[MAX_LEN] = {0};
00615 char xpath[MAX_LEN] = {0};
00616 int ret = RET_OK;
00617 int count = 0;
00618
00619 snprintf(xpath, MAX_LEN, "/package/index/pagelist[%d]", index);
00620 ret = ermXmlGetAttributeString(manifest, xpath, "type", type, MAX_LEN);
00621 ret = ermXmlGetAttributeInt(manifest, xpath, "count", &count);
00622 if (RET_ERR == ret)
00623 {
00624 TRACE("Could not read attribute!");
00625 return NULL;
00626 }
00627
00628
00629 PageListItem *pItem = (PageListItem *)malloc(sizeof(PageListItem));
00630 pItem->type = (char *)malloc(strnlen(type, MAX_LEN) + 1);
00631 strcpy(pItem->type, type);
00632 pItem->type[strlen(pItem->type)] = 0;
00633 pItem->count = count;
00634 pItem->page = (PageInfo **)malloc(sizeof(PageInfo *) * count);
00635
00636
00637 for(int i = 1; i <= pItem->count; ++i)
00638 {
00639
00640 snprintf(xpath, MAX_LEN, "/package/index/pagelist[%d]/page[%d]", index, i);
00641 ermXmlGetAttributeString(manifest, xpath, "url", url, MAX_LEN);
00642 ermXmlGetAttributeInt(manifest, xpath, "number", &count);
00643
00644 pItem->page[i - 1] = (PageInfo *)malloc(sizeof(PageInfo));
00645 pItem->page[i - 1]->number = count;
00646 pItem->page[i - 1]->url = (char *)malloc(strnlen(url, MAX_LEN) + 1);
00647 strcpy(pItem->page[i - 1]->url, url);
00648 pItem->page[i - 1]->url[strlen(pItem->page[i - 1]->url)] = 0;
00649 }
00650 return pItem;
00651 }
00652
00653 void pageInfo_release(PageInfo *pInfo)
00654 {
00655 if (pInfo->url)
00656 {
00657 free(pInfo->url);
00658 pInfo->url = NULL;
00659 }
00660 pInfo->number = INVALID_PAGE_NMBR;
00661 }
00662
00663 void pageListItem_release(PageListItem *pItem)
00664 {
00665 for(int i = 0; i < pItem->count; ++i)
00666 {
00667
00668 pageInfo_release(pItem->page[i]);
00669 free(pItem->page[i]);
00670 }
00671 free(pItem->type);
00672 pItem->type = NULL;
00673 pItem->count = 0;
00674 }
00675
00676
00677
00678 void index_file_close(IndexInfo *index)
00679 {
00680 if (NULL == index)
00681 {
00682 TRACE("Invalid IndexInfo pointer!");
00683 return;
00684 }
00685
00686 if (NULL == index->pagelist || 0 >= index->length)
00687 {
00688
00689 return;
00690 }
00691
00692
00693 for(int i = 0; i < index->length; ++i)
00694 {
00695 pageListItem_release(index->pagelist[i]);
00696 }
00697 free(index->pagelist);
00698 }
00699
00700 int index_file_init(const char* pathName, IndexInfo* pIndex)
00701 {
00702 pIndex->pagelist = NULL;
00703 pIndex->length = 0;
00704 erManifest manifest;
00705 if (RET_OK != ermXmlOpenFile(pathName, &manifest))
00706 {
00707 TRACE("Could not open manifest file %s", pathName);
00708 return -1;
00709 }
00710
00711 pIndex->length = get_pagelist_length(&manifest);
00712 if (0 >= pIndex->length)
00713 {
00714 TRACE("No Pagelist item!");
00715 return 0;
00716 }
00717
00718
00719 pIndex->pagelist = (PageListItem **)malloc(pIndex->length * sizeof(PageListItem *));
00720 for(int i = 0; i < pIndex->length; ++i)
00721 {
00722 pIndex->pagelist[i] = pageListItem_create(&manifest, i + 1);
00723 }
00724 ermXmlClose(&manifest);
00725
00726 #if (INDEX_DEBUG)
00727 dump(pIndex);
00728 #endif
00729
00730 return 0;
00731 }
00732
00733 int index_file_get_page_count(IndexInfo * index, const char* type)
00734 {
00735 if (NULL == index)
00736 {
00737 TRACE("Invalid index pointer!");
00738 return INVALID_PAGE_COUNT;
00739 }
00740
00741 if (NULL == type)
00742 {
00743 TRACE("Invalid type pointer!");
00744 return INVALID_PAGE_COUNT;
00745 }
00746
00747 for(int i = 0; i < index->length; ++i)
00748 {
00749 if (0 == strcmp(index->pagelist[i]->type, type))
00750 {
00751 return index->pagelist[i]->count;
00752 }
00753 }
00754 return INVALID_PAGE_COUNT;
00755 }
00756
00757
00758
00759
00760 int index_file_get_page_number(IndexInfo * index, const char* type, const char* url)
00761 {
00762 if (NULL == index)
00763 {
00764 TRACE("Invalid index pointer!");
00765 return INVALID_PAGE_COUNT;
00766 }
00767
00768 if (NULL == type)
00769 {
00770 TRACE("Invalid type pointer!");
00771 return INVALID_PAGE_COUNT;
00772 }
00773
00774 if (NULL == url)
00775 {
00776 TRACE("Invalid url pointer!");
00777 return INVALID_PAGE_COUNT;
00778 }
00779
00780 for(int i = 0; i < index->length; ++i)
00781 {
00782 if (0 == strcmp(index->pagelist[i]->type, type))
00783 {
00784 PageListItem *pItem = index->pagelist[i];
00785 for(int j = 0; j < pItem->count; ++j)
00786 {
00787
00788 if (contain_url(url, pItem->page[j]->url))
00789 {
00790 return pItem->page[j]->number;
00791 }
00792 }
00793 }
00794 }
00795 return INVALID_PAGE_NMBR;
00796 }
00797
00798 char* index_file_get_page_location(IndexInfo * index, const char* type, const int number)
00799 {
00800 if (NULL == index)
00801 {
00802 TRACE("Invalid index pointer!");
00803 return NULL;
00804 }
00805
00806 if (NULL == type)
00807 {
00808 TRACE("Invalid type pointer!");
00809 return NULL;
00810 }
00811
00812
00813 for(int i = 0; i < index->length; ++i)
00814 {
00815 if (0 == strcmp(index->pagelist[i]->type, type))
00816 {
00817 PageListItem *pItem = index->pagelist[i];
00818 for(int j = 0; j < pItem->count; ++j)
00819 {
00820 if (number == pItem->page[j]->number)
00821 {
00822 return pItem->page[j]->url;
00823 }
00824 }
00825 }
00826 }
00827 return NULL;
00828 }
00829
00830 void dump(IndexInfo *index)
00831 {
00832 if (NULL == index) return;
00833
00834 printf("=======================Index file information=======================\n");
00835 printf("length %d\n", index->length);
00836 for(int i = 0; i <index->length; ++i)
00837 {
00838 PageListItem *pItem = index->pagelist[i];
00839 printf("\titem type: %s\tcount: %d\n", pItem->type, pItem->count);
00840
00841 for(int j = 0; j < pItem->count; ++j)
00842 {
00843 PageInfo *pInf = pItem->page[j];
00844 printf("\t\tpage number: %d\turl: %s\n", pInf->number, pInf->url);
00845 }
00846 }
00847 printf("====================================================================\n");
00848 }
00849