Пример #1
0
__C_LINK int __DPSCALL DpsCacheMakeIndexes(DPS_AGENT *Indexer, DPS_DB *db) {
    DPS_VARLIST *v = &Indexer->Conf->Vars;
    size_t i, r;
    char *ind;

    r = (size_t) 'l';
    for (i = 0; i < v->Root[r].nvars; i++) {
        if (!strncasecmp("Limit-", v->Root[r].Var[i].name, 6)) {
            ind = v->Root[r].Var[i].val;
            if (!strcasecmp(ind, "category")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Category index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating category index");
                MakeNestedIndex(Indexer, "Category", DPS_LIMFNAME_CAT, DPS_IFIELD_TYPE_HEX8STR, db);
            } else if (!strcasecmp(ind, "tag")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Tag index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating tag index");
                MakeLinearIndex(Indexer, "Tag", DPS_LIMFNAME_TAG, DPS_IFIELD_TYPE_STRCRC32, db);
            } else if (!strcasecmp(ind, "link")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Link index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating link index");
                MakeLinearIndex(Indexer, "link", DPS_LIMFNAME_LINK, DPS_IFIELD_TYPE_INT, db);
            } else if (!strcasecmp(ind, "time")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Time index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating time index");
                MakeLinearIndex(Indexer, "last_mod_time", DPS_LIMFNAME_TIME, DPS_IFIELD_TYPE_HOUR, db);
            } else if (!strcasecmp(ind, "hostname")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Hostname index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating hostname index");
                MakeLinearIndex(Indexer, "url", DPS_LIMFNAME_HOST, DPS_IFIELD_TYPE_HOSTNAME, db);
            } else if (!strcasecmp(ind, "language")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Language index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating language index");
                MakeLinearIndex(Indexer, "Content-Language", DPS_LIMFNAME_LANG, DPS_IFIELD_TYPE_STR2CRC32, db);
            } else if (!strcasecmp(ind, "content")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Content-Type index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating Content-Type index");
                MakeLinearIndex(Indexer, "Content-Type", DPS_LIMFNAME_CTYPE, DPS_IFIELD_TYPE_STRCRC32, db);
            } else if (!strcasecmp(ind, "siteid")) {
                /* To see the URL being indexed in "ps" output on xBSD */
                dps_setproctitle("[%d] Site_id index creation", Indexer->handle);
                DpsLog(Indexer, DPS_LOG_EXTRA, "Creating Site_id index");
                MakeLinearIndex(Indexer, "site_id", DPS_LIMFNAME_SITE, DPS_IFIELD_TYPE_INT, db);
            }
            /* To see the URL being indexed in "ps" output on xBSD */
            dps_setproctitle("[%d] Indexes done.", Indexer->handle);
            DpsLog(Indexer, DPS_LOG_EXTRA, "Done");
        }
    }
    return DPS_OK;
}
Пример #2
0
__C_LINK int __DPSCALL DpsCacheMakeIndexes(DPS_AGENT *Indexer, DPS_DB *db) {
  DPS_UINT8URLIDLIST  L8;
  DPS_UINT4URLIDLIST  L4;
  DPS_VARLIST *v = &Indexer->Conf->Vars;
  size_t i, r;
  char *ind, *nm, *lfname;

  bzero(&L4, sizeof(DPS_UINT4URLIDLIST));
  bzero(&L8, sizeof(DPS_UINT8URLIDLIST));
  
  r = (size_t) 'l';
  for (i = 0; i < v->Root[r].nvars; i++) {
    if (!strncasecmp("Limit-", v->Root[r].Var[i].name, 6)) {
      ind = v->Root[r].Var[i].val;
      lfname = v->Root[r].Var[i].name;
      nm = lfname + 6;
      if (!strcasecmp(ind, "category")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Category index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating category index");
	if (DPS_OK == DpsLimit8(Indexer, &L8, "Category",  DPS_IFIELD_TYPE_HEX8STR, db)) {
	  MakeNestedIndex(Indexer, &L8, DPS_LIMFNAME_CAT, db);
	}

      } else if (!strcasecmp(ind, "tag")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Tag index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating tag index");
	if (DPS_OK == DpsLimit4(Indexer, &L4, "Tag",  DPS_IFIELD_TYPE_STRCRC32, db)) {
	  MakeLinearIndex(Indexer, &L4, DPS_LIMFNAME_TAG, db);
	}

      } else if (!strcasecmp(ind, "link")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Link index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating link index");
	if (DPS_OK == DpsLimit4(Indexer, &L4, "link",  DPS_IFIELD_TYPE_INT, db)) {
	  MakeLinearIndex(Indexer, &L4, DPS_LIMFNAME_LINK, db);
	}

      } else if (!strcasecmp(ind, "time")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Time index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating time index");
	if (DPS_OK == DpsLimit4(Indexer, &L4, "last_mod_time",  DPS_IFIELD_TYPE_HOUR, db)) {
	  MakeLinearIndex(Indexer, &L4, DPS_LIMFNAME_TIME, db);
	}

      } else if (!strcasecmp(ind, "hostname")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Hostname index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating hostname index");
	if (DPS_OK == DpsLimit4(Indexer, &L4, "url",  DPS_IFIELD_TYPE_HOSTNAME, db)) {
	  MakeLinearIndex(Indexer, &L4, DPS_LIMFNAME_HOST, db);
	}

      } else if (!strcasecmp(ind, "language")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Language index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating language index");
	if (DPS_OK == DpsLimit4(Indexer, &L4, "Content-Language",  DPS_IFIELD_TYPE_STR2CRC32, db)) {
	  MakeLinearIndex(Indexer, &L4, DPS_LIMFNAME_LANG, db);
	}

      } else if (!strcasecmp(ind, "content")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Content-Type index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating Content-Type index");
	if (DPS_OK == DpsLimit4(Indexer, &L4, "Content-Type",  DPS_IFIELD_TYPE_STRCRC32, db)) {
	  MakeLinearIndex(Indexer, &L4, DPS_LIMFNAME_CTYPE, db);
	}

      } else if (!strcasecmp(ind, "siteid")) {

	/* To see the URL being indexed in "ps" output on xBSD */
	dps_setproctitle("[%d] Site_id index creation", Indexer->handle);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating Site_id index");
	if (DPS_OK == DpsLimit4(Indexer, &L4, "site_id",  DPS_IFIELD_TYPE_INT, db)) {
	  MakeLinearIndex(Indexer, &L4, DPS_LIMFNAME_SITE, db);
	}

      } else {
	char *buf, *req, *dbaddr;
	DPS_DB ldb, *pdb = &ldb;
	size_t buf_len = dps_strlen(nm) + 16;
	if ((buf = (char*) DpsMalloc(buf_len * sizeof(char))) == NULL) {
	  DpsLog(Indexer, DPS_LOG_ERROR, "Can't alloc %d chars at %s:%d", buf_len, __FILE__, __LINE__);
	  return DPS_ERROR;
	}
	dps_setproctitle("[%d] %s index creation", Indexer->handle, nm);
	DpsLog(Indexer, DPS_LOG_EXTRA, "Creating %s index", nm);
	dps_snprintf(buf, buf_len, "Req-%s", nm);
	req = DpsVarListFindStr(&Indexer->Conf->Vars, buf, NULL);
	if (req != NULL) {
	  dps_snprintf(buf, buf_len, "dbaddr-%s", nm);
	  dbaddr = DpsVarListFindStr(&Indexer->Conf->Vars, buf, NULL);
	  if (dbaddr != NULL) {
	    DpsDBSetAddr(pdb, dbaddr, DPS_OPEN_MODE_READ);
	  } else {
	    pdb = db;
	  }
	  if (!strcasecmp(ind, "nex8str")) {
	    if (DPS_OK == DpsSQLLimit8(Indexer, &L8, req, DPS_IFIELD_TYPE_HEX8STR, pdb)) {
	      MakeNestedIndex(Indexer, &L8, lfname, pdb);
	    }
	  } else {
	    int field_type = DPS_IFIELD_TYPE_INT;
	    if (!strcasecmp(ind, "strcrc32")) field_type = DPS_IFIELD_TYPE_STRCRC32;
	    else if (!strcasecmp(ind, "hour")) field_type = DPS_IFIELD_TYPE_HOUR;
	    else if (!strcasecmp(ind, "hostname")) field_type = DPS_IFIELD_TYPE_HOSTNAME;
	    else if (!strcasecmp(ind, "char2")) field_type = DPS_IFIELD_TYPE_STR2CRC32;
	    else if (!strcasecmp(ind, "int")) field_type = DPS_IFIELD_TYPE_INT;
	    if (DPS_OK == DpsSQLLimit4(Indexer, &L4, req,  field_type, db)) {
	      MakeLinearIndex(Indexer, &L4, lfname, db);
	    }
	  }
	}

      }
      /* To see the URL being indexed in "ps" output on xBSD */
      dps_setproctitle("[%d] Indexes done.", Indexer->handle);
      DpsLog(Indexer, DPS_LOG_EXTRA, "Done");
    }
  }
  return DPS_OK;
}