예제 #1
0
void CBOINCClientManager::KillClient() {
    ULONG                   cbBuffer = 128*1024;    // 128k initial buffer
    PVOID                   pBuffer = NULL;
    PSYSTEM_PROCESSES       pProcesses = NULL;

    if (m_hBOINCCoreProcess != NULL) {
        kill_program(m_hBOINCCoreProcess);
        return;
    }

    // Get a snapshot of the process and thread information.
    diagnostics_get_process_information(&pBuffer, &cbBuffer);

    // Lets start walking the structures to find the good stuff.
    pProcesses = (PSYSTEM_PROCESSES)pBuffer;
    do {
        if (pProcesses->ProcessId) {
            tstring strProcessName = pProcesses->ProcessName.Buffer;
            if (downcase_string(strProcessName) == tstring(_T("boinc.exe"))) {
                TerminateProcessById(pProcesses->ProcessId);
                break;
           }
        }

        // Move to the next structure if one exists
        if (!pProcesses->NextEntryDelta) {
            break;
        }
        pProcesses = (PSYSTEM_PROCESSES)(((LPBYTE)pProcesses) + pProcesses->NextEntryDelta);
    } while (pProcesses);

    // Release resources
    if (pBuffer) HeapFree(GetProcessHeap(), NULL, pBuffer);
}
예제 #2
0
bool is_image_file(const char* filename) {
    std::string fn = filename;
    downcase_string(fn);
    if (ends_with(fn, std::string(".jpg"))) return true;
    if (ends_with(fn, std::string(".jpeg"))) return true;
    if (ends_with(fn, std::string(".png"))) return true;
    return false;
}
//
// process_parental_fields
//
static void process_parental_fields( indri::api::Parameters parameters, indri::api::IndexEnvironment& env ) { // pto
  std::string parName = "parental";
  std::string subName = "name";
  indri::api::Parameters slice = parameters["field"];
  for( int i=0; i<slice.size(); i++ ) {
    bool isParental = slice[i].get(parName, false);
    if( isParental ) {
      std::string fieldName = slice[i][subName];
      fieldName = downcase_string( fieldName );
      env.setParentalField(fieldName, isParental);
    }
  }
}
예제 #4
0
int HOST_INFO::parse(XML_PARSER& xp, bool benchmarks_only) {
    while (!xp.get_tag()) {
        if (xp.match_tag("/host_info")) return 0;
        if (xp.parse_double("p_fpops", p_fpops)) {
            // fix foolishness that could result in negative value here
            //
            if (p_fpops < 0) p_fpops = -p_fpops;
            continue;
        }
        if (xp.parse_double("p_iops", p_iops)) {
            if (p_iops < 0) p_iops = -p_iops;
            continue;
        }
        if (xp.parse_double("p_membw", p_membw)) {
            if (p_membw < 0) p_membw = -p_membw;
            continue;
        }
        if (xp.parse_double("p_calculated", p_calculated)) continue;
        if (xp.parse_bool("p_vm_extensions_disabled", p_vm_extensions_disabled)) continue;

        if (benchmarks_only) continue;

        // WARNING: NOTHING AFTER HERE IS READ FROM STATE FILE ON THE CLIENT

        if (xp.parse_int("timezone", timezone)) continue;
        if (xp.parse_str("domain_name", domain_name, sizeof(domain_name))) continue;
        if (xp.parse_str("ip_addr", ip_addr, sizeof(ip_addr))) continue;
        if (xp.parse_str("host_cpid", host_cpid, sizeof(host_cpid))) continue;
        if (xp.parse_int("p_ncpus", p_ncpus)) continue;
        if (xp.parse_str("p_vendor", p_vendor, sizeof(p_vendor))) continue;
        if (xp.parse_str("p_model", p_model, sizeof(p_model))) continue;
        if (xp.parse_str("p_features", p_features, sizeof(p_features))) {
            downcase_string(p_features);
            continue;
        }
        if (xp.parse_double("m_nbytes", m_nbytes)) continue;
        if (xp.parse_double("m_cache", m_cache)) continue;
        if (xp.parse_double("m_swap", m_swap)) continue;
        if (xp.parse_double("d_total", d_total)) continue;
        if (xp.parse_double("d_free", d_free)) continue;
        if (xp.parse_str("os_name", os_name, sizeof(os_name))) continue;
        if (xp.parse_str("os_version", os_version, sizeof(os_version))) continue;
        if (xp.parse_str("virtualbox_version", virtualbox_version, sizeof(virtualbox_version))) continue;
        if (xp.match_tag("coprocs")) {
            this->coprocs.parse(xp);
        }
    }
    return ERR_XML_PARSE;
}
예제 #5
0
BOOL TerminateProcessEx( tstring& strProcessName ) {
	unsigned int i,j;
    std::vector<BOINC_PROCESS> ps;
    std::vector<BOINC_PROCESS> tps;

    // Get a list of currently executing processes.
    diagnostics_update_process_list(ps);


    // Find our root process that we are supposed to terminate and
    //   terminate it.
	for (i=0; i < ps.size(); i++) {
		BOINC_PROCESS& p = ps[i];
        if (downcase_string(p.strProcessName) == downcase_string(strProcessName)) {
            if (TerminateProcessById(p.dwProcessId)) {
                tps.push_back(p);
            }
        }
	}


    // Terminate all child processes
	for (i=0; i < tps.size(); i++) {
		BOINC_PROCESS tp = tps[i];
	    for (j=0; j < ps.size(); j++) {
		    BOINC_PROCESS p = ps[j];
            if (tp.dwProcessId == p.dwParentProcessId) {
                if (TerminateProcessById(p.dwProcessId)) {
                    tps.push_back(p);
                }
            }
	    }
	}

    return TRUE;
}
static void process_numeric_fields( indri::api::Parameters parameters, indri::api::IndexEnvironment& env ) {
  std::string numName = "numeric";
  std::string subName = "name";
  indri::api::Parameters slice = parameters["field"];
  for( size_t i=0; i<slice.size(); i++ ) {
    bool isNumeric = slice[i].get(numName, false);
    if( isNumeric ) {
      // let user override default NumericFieldAnnotator for parser
      // enabling numeric fields in offset annotations.
      std::string parserName = slice[i].get("parserName", "NumericFieldAnnotator");
      std::string fieldName = slice[i][subName];
      fieldName = downcase_string( fieldName );
      env.setNumericField(fieldName, isNumeric, parserName);
    }
  }
}
예제 #7
0
int append_table(TABLE **list, char *table_name_in, int multiplicity)
{
  TABLE *table;
  TABLE *item = (TABLE *)calloc(1, sizeof(TABLE));
  char table_name[256];
  int is_this = 0;

  if( strcmp( table_name_in, "THIS" ) == 0) {
    upcase_string( table_name, lc_name );
    strcat( table_name, "_THIS" );
    is_this = 1;
  }
  else {
    strcpy( table_name, table_name_in );
  }

  if (!item)
    return SYSTEM_ERROR;
  item->next = NULL;
  item->multiplicity = multiplicity;
  item->is_this = is_this;
  if (table_name) {
    if (!(item->name = (char *)malloc(strlen(table_name) + 1)))
      return SYSTEM_ERROR;
    strcpy(item->name, table_name);
    if (!(item->lc_name = (char *)malloc(strlen(item->name) + 1)))
      return SYSTEM_ERROR;
    downcase_string(item->lc_name, item->name);
  }
  else {
    free(item);
    fprintf(stderr, "NULL table name in append_table().\n");
    return BAD_DATA_ERROR;
  }
  if (*list == NULL)
    *list = item;
  else {
    for (table = *list; table->next; table = table->next)
      ;
    table->next = item;
  }
  return OK;
}
std::string indri::query::ReformulateQuery::transform(std::string queryText) {
  std::string reform;
  // other potential xforms/parameters here.
  bool stopStructures = params->get("stopStructures", true);
  bool liteStop = params->get("liteStop", true);
  bool genSDM = params->get("genSDM", false);
  bool genFDM = params->get("genFDM", false);
  bool genCMUFDM = params->get("genCMUFDM", false);
  // case normalize
  reform = downcase_string(queryText);
  // remove the stop structures [huston]
  if (stopStructures)
    reform = indri::query::StopStructureRemover::transform(reform);
  // lite stopping [bendersky]
  if (liteStop)
    reform = indri::query::QueryStopper::transform(reform);
  if (reform.size() == 0) return std::string("EMPTYQUERY");
  
  std::vector<std::string> queryTerms = split(reform, ' ');
  std::vector<indri::query::ReformulateQuery::weighted_field> fields;
  if (params->exists("queryField")) {
    indri::api::Parameters queryFields = (*params)[ "queryField" ];
    for( size_t i = 0; i < queryFields.size(); i++ ) {
      std::string name;
      std::string weight;
      name = (std::string) queryFields[i]["name"];
      weight = (std::string) queryFields[i]["weight"];
      fields.push_back(weighted_field(name, weight));
    }
  }
  // SDM or FDM with named page style weights for threadtitle
  if (genSDM)
    reform = generateSDMQuery(queryTerms, fields);
  else if (genFDM)
    reform = generateFDMQuery(queryTerms, fields);
  else if (genCMUFDM)
    reform = generateCMUFDMQuery(queryTerms);
  else 
    reform = generateCombineQuery(queryTerms);
  // additional reformulation steps...
  return reform;
}
예제 #9
0
document* parse_file(const char *file_name) {
  int tallied_length = 0;
  GMimeStream *stream;
  GMimeMessage *msg = 0;
  // struct stat stat_buf;
  const char *author, *subject, *xref, *xref_end;
  time_t date;
  int offset;
  int num_words = 0;
  int file;
  InternetAddress *iaddr;
  InternetAddressList *iaddr_list;
  char *address;

#if DEBUG
  printf("%s\n", file_name);
#endif

  /*
  if ((file = stat(file_name, &stat_buf)) == -1) {
    perror("tokenizer");
    return NULL;
  }
  */

  // |O_STREAMING
  if ((file = open(file_name, O_RDONLY|O_STREAMING)) == -1) {
    perror("tokenizer");
    return NULL;
  }

#ifdef POSIX_FADV_NOREUSE
  no_reuse(file);
#endif

  stream = g_mime_stream_fs_new(file);
  msg = g_mime_parser_construct_message(stream);
  g_mime_stream_unref(stream);

  if (msg != 0) {
    table = g_hash_table_new(g_str_hash, g_str_equal);
    bufp = buffer;
    dword_table[0].word = NULL;
    bzero(saved_body, MAX_SAVED_BODY_LENGTH);
    saved_body_length = 0;
    author = g_mime_message_get_sender(msg);
    subject = g_mime_message_get_subject(msg);
    xref = g_mime_message_get_header(msg, "Xref");
    g_mime_message_get_date(msg, &date, &offset);
    if (author != NULL && subject != NULL && xref != NULL) {
      tallied_length = tally_string(author, tallied_length);
      strncpy(doc.author, author, MAX_HEADER_LENGTH-1);

      /* Get the address from the From header. */
      if ((iaddr_list = internet_address_parse_string(author)) != NULL) {
	iaddr = iaddr_list->address;
	internet_address_set_name(iaddr, NULL);
	address = internet_address_to_string(iaddr, FALSE);
	strncpy(doc.address, address, MAX_HEADER_LENGTH-1);
	downcase_string(doc.address);
	free(address);
	internet_address_list_destroy(iaddr_list);
      } else {
	*doc.address = 0;
      }

      tallied_length = tally_string(subject, tallied_length);
      strncpy(doc.subject, subject, MAX_HEADER_LENGTH-1);

      doc.time = date;

      if ((xref = strchr(xref, ' ')) != NULL) {
	xref++;
	xref_end = strchr(xref, ':');
	*doc.group = 0;
	strncat(doc.group, xref, min(xref_end-xref, MAX_HEADER_LENGTH-1));
	xref_end++;
	sscanf(xref_end, "%d", &doc.article);
      }

      g_mime_message_foreach_part(msg, partFound, (gpointer) &tallied_length);

      strncpy(doc.body, saved_body, MAX_SAVED_BODY_LENGTH);

      g_hash_table_foreach(table, add_word_to_table, (gpointer) &num_words);
      dword_table[num_words].word = NULL;
      g_hash_table_destroy(table);
      g_mime_object_unref(GMIME_OBJECT(msg));
    } else {
      close(file);
      return NULL;
    }
  }
  close(file);
  doc.words = dword_table;
  doc.num_words = num_words;

  return &doc;
}
static void downcase_string_vector (std::vector<std::string>& vec) {
  for( size_t i=0; i<vec.size(); i++ ) {
    vec[i] = downcase_string( vec[i] );
  }
}