コード例 #1
0
ファイル: curl_request.c プロジェクト: ewmailing/OAuth2
char* curl_make_request(char* url, char* params)
{
    data* storage;
    data* curr_storage;
    CURL* handle;
    int data_len;
    char* retVal;

    assert(url != 0);
    assert(*url != 0);

    storage = malloc(sizeof(data));
    storage->idx = 0;
    storage->next = 0;

    handle = curl_easy_init();
    curl_easy_setopt(handle, CURLOPT_URL, url);
    curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, curl_callback);
    curl_easy_setopt(handle, CURLOPT_WRITEDATA, storage);

    //Do we need to add the POST parameters?
    if(params != NULL)
    {
        curl_easy_setopt(handle, CURLOPT_POST, 1);
        curl_easy_setopt(handle, CURLOPT_COPYPOSTFIELDS, params); //Copy them just incase
                                                                  //the user does something stupid
    }

    if(curl_easy_perform(handle) != 0)
    {
        //Error!
        curl_easy_cleanup(handle);
        data_clean(storage);
        return NULL;
    }

    //Everything went OK.
    //How long is the data?
    data_len = 0;
    curr_storage = storage;
    while(curr_storage)
    {
        data_len += curr_storage->idx;
        curr_storage = curr_storage->next;
    }

    //Allocate storage
    retVal = malloc(sizeof(char)*data_len);
    
    //Now copy in the data
    curr_storage = storage;
    data_len = 0;
    while(curr_storage)
    {
        memcpy(retVal+data_len, curr_storage->d, curr_storage->idx);
        curr_storage = curr_storage->next;
    }

    //Cleanup
    curl_easy_cleanup(handle);
    data_clean(storage);
    
    return retVal;
}
コード例 #2
0
ファイル: stdhep2itape.c プロジェクト: noemi8a/sim-recon
/********************
 * write_mc_parts
 *******************/
int write_mc_parts(FILE *fp, mc_evt_t *mc_evt){
  int i,ret;
  static itape_header_t *buffer=NULL;
  esr_nparticle_t *esr;
  int group=802; /* esrGroup*/
  int nparticles;
  esr_particle_t esrp[MAX_ESR_PARTS];
  
  if(!buffer){
    buffer=(itape_header_t *)malloc(BUFSIZE);
    data_newItape(buffer);
  }
  /* 
   * write header info 
   */
  buffer->runNo=mc_evt->runNo;
  buffer->eventNo= mc_evt->eventNo;
  buffer->spillNo= 0;
  buffer->trigger= 1;
  if(Debug)
      fprintf(fp,"%d  %d\n", mc_evt->runNo, mc_evt->eventNo);
  
  esr=data_addGroup(buffer,BUFSIZE,802,sizeof(esr_nparticle_t)+
		     (mc_evt->nparts)*sizeof(esr_particle_t));
  esr->nparticles = mc_evt->nparts;
  /* 
   * now loop over the particle in the event and fill the esr
   */
  /*
   * Kludged Beam */
  esr->beam.space.x=0;
  esr->beam.space.y=0;
  esr->beam.space.z=KludgedBeam;
  esr->beam.t = KludgedBeam;

  for(i=0;i<mc_evt->nparts;i++){
    esr->p[i].particleType =mc_evt->part[i].pid;
    esr->p[i].charge = getCharge( mc_evt->part[i].pid);
    esr->p[i].p.space.x=mc_evt->part[i].p.space.x;/* float = double */
    esr->p[i].p.space.y=mc_evt->part[i].p.space.y;
    esr->p[i].p.space.z=mc_evt->part[i].p.space.z;
    esr->p[i].p.t=mc_evt->part[i].p.t;

    if(Debug)
      fprintf(fp,"%d %d %lf \n",(i+1), 
	      mc_evt->part[i].pid, mc_evt->part[i].mass);
    if(Debug)
      fprintf(fp,"   %d %lf %lf %lf %lf\n",
	       getCharge( mc_evt->part[i].pid),
	      /*mc_evt->part[i].pid/abs(mc_evt->part[i].pid),*/
	      mc_evt->part[i].p.space.x,
	      mc_evt->part[i].p.space.y,
	      mc_evt->part[i].p.space.z,
	      mc_evt->part[i].p.t);
  }
  data_saveGroups(buffer,1,&group);
  data_clean(buffer);
  data_write(fileno(fp),buffer);

  return 1;
}