Ejemplo n.º 1
0
Archivo: import.c Proyecto: Aconex/pcp
int
pmiGetHandle(const char *name, const char *instance)
{
    int		sts;
    pmi_handle	tmp;
    pmi_handle	*hp;

    if (current == NULL)
	return PM_ERR_NOCONTEXT;

    sts = make_handle(name, instance, &tmp);
    if (sts != 0)
	return current->last_sts = sts;

    current->nhandle++;
    current->handle = (pmi_handle *)realloc(current->handle, current->nhandle*sizeof(pmi_handle));
    if (current->handle == NULL) {
	__pmNoMem("pmiGetHandle: pmi_handle", current->nhandle*sizeof(pmi_handle), PM_FATAL_ERR);
    }
    hp = &current->handle[current->nhandle-1];
    hp->midx = tmp.midx;
    hp->inst = tmp.inst;

    return current->last_sts = current->nhandle;
}
Ejemplo n.º 2
0
Archivo: import.c Proyecto: Aconex/pcp
int
pmiPutValue(const char *name, const char *instance, const char *value)
{
    pmi_handle	tmp;
    int		sts;

    if (current == NULL)
	return PM_ERR_NOCONTEXT;

    sts = make_handle(name, instance, &tmp);
    if (sts != 0)
	return current->last_sts = sts;

    return current->last_sts = _pmi_stuff_value(current, &tmp, value);
}
Ejemplo n.º 3
0
unsigned int rotor_machine_provider::new_object(tlv_entry& params, tlv_stream *out_stream)
{
    unsigned int result = ERR_OK;
    string new_object_name;
    tlv_entry tlv_handle;
    rotor_machine *machine;
    rotor_machine_proxy *new_object;
    
    make_handle(new_object_name);
    
    do
    {
        // Did we receive a TLV byte array?
        if (params.tag != TAG_BYTE_ARRAY)
        {
            result = out_stream->write_error_tlv(ERR_SYNTAX_INPUT);
            break;
        }
        
        string machine_state((char *)params.value.data(), params.value.length());
        
        // Attempt to restore a rotor_machine object from the state sent by the client
        machine = rmsk::restore_from_data(machine_state);
        
        // Did restoring machine state work?
        if (machine ==  NULL)
        {
            // No
            result = out_stream->write_error_tlv(ERR_OBJECT_CREATE);
            break;            
        }
        
        // Yes        
        new_object = new rotor_machine_proxy(machine);
        
        pair<void *, service_provider *> new_val(new_object, this);
    
        registry->add_object(new_object_name, new_val);
        tlv_handle.to_string(new_object_name);

        // Tell client about the new handle and write end of result stream marker.
        result = out_stream->write_success_tlv(tlv_handle);        
    
    } while(0);
    
    return result;
}
Ejemplo n.º 4
0
unsigned int arithmetic_provider::new_object(tlv_entry& params, tlv_stream *out_stream)
{
    unsigned int result = ERR_OK;
    string new_object_name;
    arithmetic *new_object = new arithmetic();
    tlv_entry tlv_handle;
    
    make_handle(new_object_name);
    pair<void *, service_provider *> new_val(new_object, this);
    
    registry->add_object(new_object_name, new_val);
    tlv_handle.to_string(new_object_name);
    
    // Tell client about the new handle and write end of result stream marker.
    result = out_stream->write_success_tlv(tlv_handle);

    return result;
}
Ejemplo n.º 5
0
void cmex_object_list(int nlhs, mxArray *plhs[], /**< entlist */
					  int nrhs, const mxArray *prhs[] ) /**< () */
{
	OBJECT *obj;
	char criteria[1024]="(undefined)";
	FINDPGM *search = NULL;
	char *fields[] = {"name","class","parent","flags","location","service","rank","clock","handle"};
	FINDLIST *list = NULL;
	if (nrhs>0 && mxGetString(prhs[0],criteria,sizeof(criteria))!=0)
		output_error("gl('list',type='object'): unable to read search criteria (arg 2)");
	else if (nrhs>0 && (search=find_mkpgm(criteria))==NULL)
		output_error("gl('list',type='object'): unable to run search '%s'",criteria);
	else if (search==NULL && (list=find_objects(NULL,NULL))==NULL)
		output_error("gl('list',type='object'): unable to obtain default list");
	else if (list==NULL && (list=find_runpgm(NULL,search))==NULL)
		output_error("gl('list',type='object'): unable search failed");
	else if ((plhs[0] = mxCreateStructMatrix(list->hit_count,1,sizeof(fields)/sizeof(fields[0]),fields))==NULL)
		output_error("gl('list',type='object'): unable to allocate memory for result list");
	else
	{
		unsigned int n;
		for (n=0, obj=find_first(list); obj!=NULL; n++, obj=find_next(list,obj))
		{
			char tmp[1024];
			mxArray *data;
			double *pDouble;
			unsigned int *pInt;
			mxSetFieldByNumber(plhs[0], n, 0, mxCreateString(object_name(obj)));
			mxSetFieldByNumber(plhs[0], n, 1, mxCreateString(obj->oclass->name));
			mxSetFieldByNumber(plhs[0], n, 2, mxCreateString(obj->parent?object_name(obj->parent):NONE));
			mxSetFieldByNumber(plhs[0], n, 3, mxCreateString(convert_from_set(tmp,sizeof(tmp),&(obj->flags),object_flag_property())?tmp:ERROR));
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,2,mxREAL)); pDouble[0] = obj->longitude; pDouble[1] = obj->latitude;
			mxSetFieldByNumber(plhs[0], n, 4, data);
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,2,mxREAL)); pDouble[0] = (double)obj->in_svc/TS_SECOND; pDouble[1] = (double)obj->out_svc/TS_SECOND;
			mxSetFieldByNumber(plhs[0], n, 5, data);
			pInt = (unsigned int*)mxGetPr(data=mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL)); pInt[0] = obj->rank;
			mxSetFieldByNumber(plhs[0], n, 6, data);
			pDouble = mxGetPr(data=mxCreateDoubleMatrix(1,1,mxREAL)); pDouble[0] = (double)obj->clock/TS_SECOND; 
			mxSetFieldByNumber(plhs[0], n, 7, data);
			mxSetFieldByNumber(plhs[0], n, 8, make_handle(MH_OBJECT,obj));
		}
	}
}
Ejemplo n.º 6
0
/* HREF finder implemented in libxml2 but could be any HTML parser */
size_t follow_links(CURLM *multi_handle, memory *mem, char *url)
{
  int opts = HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | \
             HTML_PARSE_NOWARNING | HTML_PARSE_NONET;
  htmlDocPtr doc = htmlReadMemory(mem->buf, mem->size, url, NULL, opts);
  if(!doc)
    return 0;
  xmlChar *xpath = (xmlChar*) "//a/@href";
  xmlXPathContextPtr context = xmlXPathNewContext(doc);
  xmlXPathObjectPtr result = xmlXPathEvalExpression(xpath, context);
  xmlXPathFreeContext(context);
  if(!result)
    return 0;
  xmlNodeSetPtr nodeset = result->nodesetval;
  if(xmlXPathNodeSetIsEmpty(nodeset)) {
    xmlXPathFreeObject(result);
    return 0;
  }
  size_t count = 0;
  for(int i = 0; i < nodeset->nodeNr; i++) {
    double r = rand();
    int x = r * nodeset->nodeNr / RAND_MAX;
    const xmlNode *node = nodeset->nodeTab[x]->xmlChildrenNode;
    xmlChar *href = xmlNodeListGetString(doc, node, 1);
    if(follow_relative_links) {
      xmlChar *orig = href;
      href = xmlBuildURI(href, (xmlChar *) url);
      xmlFree(orig);
    }
    char *link = (char *) href;
    if(!link || strlen(link) < 20)
      continue;
    if(!strncmp(link, "http://", 7) || !strncmp(link, "https://", 8)) {
      curl_multi_add_handle(multi_handle, make_handle(link));
      if(count++ == max_link_per_page)
        break;
    }
    xmlFree(link);
  }
  xmlXPathFreeObject(result);
  return count;
}
Ejemplo n.º 7
0
unsigned int random_provider::new_object(tlv_entry& params, tlv_stream *out_stream)
{
    unsigned int result = ERR_OK;
    string new_object_name;
    tlv_entry tlv_handle;
    alphabet<char> *new_alpha;
    random_proxy *new_object;
    string alpha_spec;
    
    make_handle(new_object_name);
    
    do
    {
        // Did we receive a TLV string?
        if (params.tag != TAG_STRING)
        {
            result = out_stream->write_error_tlv(ERR_SYNTAX_INPUT);
            break;
        }
        
        if (!params.tlv_convert(alpha_spec))
        {
            result = out_stream->write_error_tlv(ERR_SYNTAX_INPUT);
            break;
        }
        
        new_alpha = new alphabet<char>(alpha_spec.c_str(), alpha_spec.length());
        new_object = new random_proxy(new_alpha);
                
        pair<void *, service_provider *> new_val(new_object, this);
    
        registry->add_object(new_object_name, new_val);
        tlv_handle.to_string(new_object_name);

        // Tell client about the new handle and write end of result stream marker.
        result = out_stream->write_success_tlv(tlv_handle);        
    
    } while(0);
    
    return result;
}
Ejemplo n.º 8
0
int main(void)
{
  signal(SIGINT, sighandler);
  LIBXML_TEST_VERSION;
  curl_global_init(CURL_GLOBAL_DEFAULT);
  CURLM *multi_handle = curl_multi_init();
  curl_multi_setopt(multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, max_con);
  curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 6L);

  /* enables http/2 if available */
#ifdef CURLPIPE_MULTIPLEX
  curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
#endif

  /* sets html start page */
  curl_multi_add_handle(multi_handle, make_handle(start_page));

  int msgs_left;
  int pending = 0;
  int complete = 0;
  int still_running = 1;
  while(still_running && !pending_interrupt) {
    int numfds;
    curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
    curl_multi_perform(multi_handle, &still_running);

    /* See how the transfers went */
    CURLMsg *m = NULL;
    while((m = curl_multi_info_read(multi_handle, &msgs_left))) {
      if(m->msg == CURLMSG_DONE) {
        CURL *handle = m->easy_handle;
        char *url;
        memory *mem;
        curl_easy_getinfo(handle, CURLINFO_PRIVATE, &mem);
        curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
        if(m->data.result == CURLE_OK) {
          long res_status;
          curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &res_status);
          if(res_status == 200) {
            char *ctype;
            curl_easy_getinfo(handle, CURLINFO_CONTENT_TYPE, &ctype);
            printf("[%d] HTTP 200 (%s): %s\n", complete, ctype, url);
            if(is_html(ctype) && mem->size > 100) {
              if(pending < max_requests && (complete + pending) < max_total) {
                pending += follow_links(multi_handle, mem, url);
                still_running = 1;
              }
            }
          }
          else {
            printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url);
          }
        }
        else {
          printf("[%d] Connection failure: %s\n", complete, url);
        }
        curl_multi_remove_handle(multi_handle, handle);
        curl_easy_cleanup(handle);
        free(mem->buf);
        free(mem);
        complete++;
        pending--;
      }
    }
  }
  curl_multi_cleanup(multi_handle);
  curl_global_cleanup();
  return 0;
}