Пример #1
0
static int create_audiobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
	int flags;
	int sample_rate;
	int desired_buffer;

	int stereo;
	int bitsize;
	int compressed;

	int format;

	if (!mve_audio_enabled)
		return 1;

	if (audiobuf_created)
		return 1;
	else
		audiobuf_created = 1;

	flags = get_ushort(data + 2);
	sample_rate = get_ushort(data + 4);
	desired_buffer = get_int(data + 6);

	stereo = (flags & MVE_AUDIO_FLAGS_STEREO) ? 1 : 0;
	bitsize = (flags & MVE_AUDIO_FLAGS_16BIT) ? 1 : 0;

	if (minor > 0) {
		compressed = flags & MVE_AUDIO_FLAGS_COMPRESSED ? 1 : 0;
	} else {
		compressed = 0;
	}

	mve_audio_compressed = compressed;

	if (bitsize == 1) {
#ifdef WORDS_BIGENDIAN
		format = AUDIO_S16MSB;
#else
		format = AUDIO_S16LSB;
#endif
	} else {
		format = AUDIO_U8;
	}

#ifdef USE_SDLMIXER
	if (GameArg.SndDisableSdlMixer)
#endif
	{
		con_printf(CON_CRITICAL, "creating audio buffers:\n");
		con_printf(CON_CRITICAL, "sample rate = %d, desired buffer = %d, stereo = %d, bitsize = %d, compressed = %d\n",
				sample_rate, desired_buffer, stereo, bitsize ? 16 : 8, compressed);
	}

	mve_audio_spec = (SDL_AudioSpec *)mve_alloc(sizeof(SDL_AudioSpec));
	mve_audio_spec->freq = sample_rate;
	mve_audio_spec->format = format;
	mve_audio_spec->channels = (stereo) ? 2 : 1;
	mve_audio_spec->samples = 4096;
	mve_audio_spec->callback = mve_audio_callback;
	mve_audio_spec->userdata = NULL;

	// MD2211: if using SDL_Mixer, we never reinit the sound system
#ifdef USE_SDLMIXER
	if (GameArg.SndDisableSdlMixer)
#endif
	{
		if (SDL_OpenAudio(mve_audio_spec, NULL) >= 0) {
			con_printf(CON_CRITICAL, "   success\n");
			mve_audio_canplay = 1;
		}
		else {
			con_printf(CON_CRITICAL, "   failure : %s\n", SDL_GetError());
			mve_audio_canplay = 0;
		}
	}

#ifdef USE_SDLMIXER
	else {
		// MD2211: using the same old SDL audio callback as a postmixer in SDL_mixer
		Mix_SetPostMix(mve_audio_spec->callback, mve_audio_spec->userdata);
		mve_audio_canplay = 1;
	}
#endif

	memset(mve_audio_buffers, 0, sizeof(mve_audio_buffers));
	memset(mve_audio_buflens, 0, sizeof(mve_audio_buflens));

	return 1;
}
Пример #2
0
int dmpTask::initialize()
{
double freq;
int i;
int ans = 999;

  start_time_ = 0.0;
  
  // Make sure that everything is clear
  if (vnames_CBi != NULL)
  {
    for (i = 1; i <= dof_CBi; i++)
      free((void *) vnames_CBi[i]);
    free((void *) vnames_CBi);
    vnames_CBi = NULL;
  }
  if (units_CBi != NULL)
  {
    for (i = 1; i <= dof_CBi; i++)
      free((void *) units_CBi[i]);
    free((void *) units_CBi);
    units_CBi = NULL;
  }
  if (CBi_traj != NULL)
  {
    my_free_matrix(CBi_traj, 1, n_CBi, 1, dof_CBi);
    CBi_traj = NULL;
  }
  if (vnames_Kinect != NULL)
  {
    for (i = 1; i <= dof_Kinect; i++)
      free((void *) vnames_Kinect[i]);
    free((void *) vnames_Kinect);
    vnames_Kinect = NULL;
  }
  vnames_Kinect = NULL;
  if (units_Kinect != NULL)
  {
    for (i = 1; i <= dof_Kinect; i++)
      free((void *) units_Kinect[i]);
    free((void *) units_Kinect);
    units_Kinect = NULL;
  }
  if (Kinect_traj != NULL)
  {
    my_free_matrix(Kinect_traj, 1, n_Kinect, 1, dof_Kinect);
    Kinect_traj = NULL;
  }
  if (DMP_object != NULL)
  {
    delete DMP_object;
    DMP_object = NULL;
  }

  // Read robot trajectory
  // mrdplot_convert(CBi_traj_file, &CBi_traj, &vnames_CBi, &units_CBi, &freq, &dof_CBi, &n_CBi);
  mrdplot_read(CBi_traj_file, &CBi_traj, &vnames_CBi, &units_CBi, &freq, &dof_CBi, &n_CBi);
  if (!set_active_dofs(vnames_CBi, dof_CBi, active_dofs))
    return FALSE;

  printf("%d active DoFs:", active_dofs[0]);
  for (i = 2; i <= active_dofs[0]+1; i++)
  {
    if (!((i-2)%8))
      printf("\n");
    printf("%s, ", vnames_CBi[i]);
  }
  printf("\n\n");

  // Read Kinect trajectory
  // mrdplot_convert(Kinect_traj_file, &Kinect_traj, &vnames_Kinect, &units_Kinect, &freq, &dof_Kinect, &n_Kinect);
  mrdplot_read(Kinect_traj_file, &Kinect_traj, &vnames_Kinect, &units_Kinect, &freq, &dof_Kinect, &n_Kinect);

  // Filter Kinect trajectory if desired
  if (Kinect_traj != NULL && filter_Kinect_data)
  {
    if (!init_filters())
      return FALSE;
    for (int i = 1; i <= 19; i++)
      fth[i].cutoff = 9;
    for (int i = 1; i <= 19; i++)
    {
      fth[i].raw[0] = fth[i].raw[1] = fth[i].raw[2] = Kinect_traj[1][i+1];
      fth[i].filt[0] = fth[i].filt[1] = fth[i].filt[2] = Kinect_traj[1][i+1];
    }
    for (int j = 1; j <= n_Kinect; j++)
      for (int i = 1; i <= 19; i++)
        Kinect_traj[j][i+1] = filt(Kinect_traj[j][i+1], &fth[i]);
  }

  // Compute DMP for robot trajectory
  if (DMP_object != NULL)
    delete DMP_object;
  // DMP_object = new DMP_structure(DMP_file);
  DMP_object = new DMP_structure(active_dofs[0], 50, 2.0, 12.0, 3.0);
  printf("\n");
  if (!DMP_object->example_Matrix(CBi_traj, n_CBi, dof_CBi))
    return FALSE;
  DMP_object->DMP_estimate(0);
  // DMP_object->DMP_param_print();
  printf("\n");

  // Initialize DMP integration
  for (int i = 1; i <= active_dofs[0]; i++)
  {
    initial_positions[i] = CBi_traj[1][i+1];
    initial_velocities[i] = 0.0;
  }
  DMP_object->set_initial_DMP_state(&(initial_positions[1]), &(initial_velocities[1]));

  // include this file to define contact points (needed to compute center of pressure)
#include "LEKin_contact.h"
  
  // prepare going to the default posture
  bzero((char *)&(target_[1]),N_DOFS*sizeof(target_[1]));
  for (i = 1; i <= N_DOFS; i++)
    target_[i] = joint_default_state[i];
  target_[L_EB].th = target_[R_EB].th = 0.05;
  target_[B_TFE].th = 0.2;  

  for (int i = 1; i <= active_dofs[0]; i++)
  {
    target_[active_dofs[i]].th = initial_positions[i];
    target_[active_dofs[i]].thd = 0.0;
    target_[active_dofs[i]].thdd = 0.0;
    target_[active_dofs[i]].uff = 0.0;
  }

  bool there = true;
  for (int i = 1; i <= B_HR; i++)
    if (fabs(target_[i].th - joint_des_state[i].th) > 1.0e-3)
    {
      there = false;
      break;
    }
  // go to the target using inverse dynamics (ID)int SampleTask::changeParameters()
  if (!there)
  {
    if (!go_target_wait_ID(target_))
    {
      return FALSE;
    }
  }

  // ready to go
  while (ans == 999)
  {
    if (!get_int(const_cast<char*>("Enter 1 to start or anthing else to abort ..."), ans, &ans))
    {
      return FALSE;
    }
  }
  
  // only go when user really types the right thing
  if (ans != 1) 
  {
    return FALSE;
  }

  start_time_ = task_servo_time;
  printf("start time = %.3f, task_servo_time = %.3f\n", start_time_, task_servo_time);

  return TRUE;
}
Пример #3
0
int
main (void)
{

  graphStruct *aGraph;
  int keepLooking,code;

  bsdSignal(SIGPIPE,brokenPipe,DontRestartSystemCalls);
#if defined(BSDplatform) || defined (MACOSXplatform)
  bsdSignal(SIGCHLD,endChild,RestartSystemCalls);
#else
  bsdSignal(SIGCLD,endChild,RestartSystemCalls);
#endif
  bsdSignal(SIGTERM,goodbye,DontRestartSystemCalls);

  /* Connect up to AXIOM server */
  spadSock = connect_to_local_server(SpadServer,ViewportServer,Forever);
  if (spadSock == NULL) {
    fprintf(stderr,"The viewport manager couldn't connect to FriCAS\n");
    exit(-1);
  }
#ifdef DEBUG
  else
    fprintf(stderr,"viewman: Connected to FriCAS\n");
#endif

  /******** initialize ********/
  viewports = 0;
  graphList = 0;

  /******** getting stuff from spad and viewports ********
  *********   the viewports have priority over    ****
  ***   AXIOM.                              ***/
  while (1) {
    FD_ZERO(&filedes); /* zero out file descriptor */
    FD_SET(spadSock->socket,&filedes);
    slot = viewports;
    while (slot) {
      FD_SET(slot->viewIn,&filedes);
      slot = slot->nextViewport;
    }

#ifdef DEBUG
    fprintf(stderr,"Selection for filedes of %x \n",filedes);
#endif
    code = check(superSelect(FD_SETSIZE,(void *) &filedes,0,0,0));
    for (;code<=0;)
      code = check(superSelect(FD_SETSIZE,(void *)&filedes,0,0,0));

    slot = viewports;
    keepLooking = 1;
    while (keepLooking && slot) {
      if (FD_ISSET(slot->viewIn,&filedes)) {
        keepLooking = 0;
#ifdef DEBUG
        fprintf(stderr,"Reading child viewport...\n");
#endif
        viewCommand = viewportClosing;
        readViewport(slot,&viewCommand,intSize);

        switch (viewCommand) {

        case pick2D:
#ifdef DEBUG
          fprintf(stderr,"viewman: Doing 2D pick\n");
#endif
          picked = yes;

          readViewport(slot,&currentGraph,intSize); /* get the graph to pick */
          readViewport(slot,&currentGraphState,sizeof(graphStateStruct));
          break;

        case drop2D:
#ifdef DEBUG
          fprintf(stderr,"viewman: Doing 2D drop\n");
#endif
          if (picked) {
            write(slot->viewOut,&viewOkay,intSize);
            write(slot->viewOut,&currentGraph,intSize);
            sendGraphToView2D(0,currentGraph,slot,&currentGraphState);
          } else {
            write(slot->viewOut,&viewError,intSize);
            fprintf(stderr,"The viewport manager cannot drop a graph because nothing has been picked yet.\n");
          }
          break;

        case viewportClosing:
#ifdef DEBUG
          fprintf(stderr,"viewman: closing viewport\n");
#endif
          closeChildViewport(slot);
          break;

        };  /* switch */

      };  /* if reading slot->viewIn */
      stepSlot = slot;
      slot = slot->nextViewport;
    };  /* while */

    if (keepLooking) {   /* if  1 => slots not read, read from spad */
#ifdef DEBUG
      fprintf(stderr,"viewman: still looking\n");
#endif
      viewType = get_int(spadSock);
      if (viewType == -1) goodbye(-1);
      viewCommand = get_int(spadSock);

      switch (viewType) {

      case view3DType:
#ifdef DEBUG
        fprintf(stderr,"viewman: making 3D viewport\n");
#endif
        if (viewCommand == makeViewport)
          forkView3D(view3DType);
        else
          funView3D(viewCommand);

        break;

      case viewTubeType:
#ifdef DEBUG
        fprintf(stderr,"viewman: viewing a tube\n");
#endif
        if (viewCommand == makeViewport)
          forkView3D(viewTubeType);
        else
          funView3D(viewCommand);

        break;

      case viewGraphType:
#ifdef DEBUG
        fprintf(stderr,"viewman: making a graph\n");
#endif
        if (viewCommand == makeGraph) {
          aGraph            = makeGraphFromSpadData();
          aGraph->nextGraph = graphList;
          graphList         = aGraph;
        }
        break;

      case view2DType:
#ifdef DEBUG
        fprintf(stderr,"viewman: forking 2D\n");
#endif
        if (viewCommand == makeViewport) {
          forkView2D();
        } else {
          funView2D(viewCommand);
        }
        break;

      }   /* switch on viewType */
    }   /* if (keepLooking) */
  }   /* while (1) */
}
Пример #4
0
static int fb_set_depth(void)
{
    int status;
    char *device = get_string("device");
    int depth = get_int("depth");

    // Open fb device
    status = open_device(device);
    if (status != 0)
        return status;

    switch (depth)
    {
        case 8:
        case 16:
        case 24:
        case 32:
            break;
        default:
            log_error("depth must be 8, 16, 24 or 32");
            return 1;
    }

    // Set color depth
    fb.vinfo.bits_per_pixel = depth;

    // Set color encoding
    switch (fb.vinfo.bits_per_pixel)
    {
        case 8:
            // RGB332
            fb.vinfo.red.offset    = 0;
            fb.vinfo.red.length    = 3;
            fb.vinfo.green.offset  = 3;
            fb.vinfo.green.length  = 3;
            fb.vinfo.blue.offset   = 6;
            fb.vinfo.blue.length   = 2;
            fb.vinfo.transp.offset = 0;
            fb.vinfo.transp.length = 0;
            break;
        case 16: // RGB 565
            fb.vinfo.red.offset    = 0;
            fb.vinfo.red.length    = 5;
            fb.vinfo.green.offset  = 5;
            fb.vinfo.green.length  = 6;
            fb.vinfo.blue.offset   = 11;
            fb.vinfo.blue.length   = 5;
            fb.vinfo.transp.offset = 0;
            fb.vinfo.transp.length = 0;
            break;
        case 24: // RGB 888
            fb.vinfo.red.offset    = 0;
            fb.vinfo.red.length    = 8;
            fb.vinfo.green.offset  = 8;
            fb.vinfo.green.length  = 8;
            fb.vinfo.blue.offset   = 16;
            fb.vinfo.blue.length   = 8;
            fb.vinfo.transp.offset = 0;
            fb.vinfo.transp.length = 0;
            break;
        case 32: // RGBA 8888
            fb.vinfo.red.offset    = 0;
            fb.vinfo.red.length    = 8;
            fb.vinfo.green.offset  = 8;
            fb.vinfo.green.length  = 8;
            fb.vinfo.blue.offset   = 16;
            fb.vinfo.blue.length   = 8;
            fb.vinfo.transp.offset = 24;
            fb.vinfo.transp.length = 8;
            break;
    }

    // Set variable screen information
    if (ioctl(fb.fd, FBIOPUT_VSCREENINFO, &fb.vinfo))
    {
        log_error("Could not set variable screen information in %s (%s)", device, strerror(errno));
        return 1;
    }

    // Close device
    status = close_device();
    if (status != 0)
        return status;

    return 0;
}
Пример #5
0
void xsim_topology_load_info(char *file, int nb_node)
{
	FILE *fptr = fopen(file, "r");
	if (fptr == NULL) {
		EMSG("Error when loading file: %s.\n", file);
		return;
	}

	int current = 0;
	int i       = 0;
	int j       = 0;
    int time    = 1;
    int line_nb = 0;
    char *line = (char*)malloc(sizeof(char) * LINESIZE);
	while (fgets(line, LINESIZE, fptr) != NULL) {
        line_nb++;
		current = 0;
		SKIP_SPACE;

		if ((line[current] == '#')           /* It is a commentaire */
				|| (line[current] == '\n'))  /* It is an empty line */
			continue;

		i = get_int(&current, line, line_nb); 
        if (i < 0)
            continue;
		if (i >= nb_node) {/* This node does not match the configuration */
			EMSG("line %d: the node number is too high compare to the configuration given as parameters: got %d .\n", line_nb, i);
			continue;
		}

        NEXT_TOKEN;

        if (current > LINESIZE-2) {
            EMSG("line %d: line too long: max characters in one line: %d\n", line_nb, LINESIZE);
            continue;
        }
		if ((line[current] != '-') || (line[current+1] != '>')) {
			EMSG("line %d: Token \"->\" expected. Find: %c%c.\n", line_nb, line[current], line[current+1]);
			continue;
		}
        current += 2;
        
        NEXT_TOKEN;

        j = get_int(&current, line, line_nb);
        if (j < 0)
            continue;
		if (j >= nb_node) {/* This node does not match the configuration */
			EMSG("line %d: the node number is too high compare to the configuration given as parameters: got %d.\n", line_nb, j);
			continue;
		}

        NEXT_TOKEN;

        if (line[current] != ':') {
            EMSG("line %d: Token ':' expected. Find: %c.\n", line_nb, line[current]);
            continue;
        }
        current++;
        
        NEXT_TOKEN;

        time = get_int(&current, line, line_nb);
		if (time <= 0) {/* This travel time is not possible */
			EMSG("line %d: the travel time read is not possible: %d.\n", line_nb, time);
			continue;
		}

        /* The rest of the line is not important - skip it and memorized the result*/
        topology[i][j] = time;
	}
    free(line);

	fclose(fptr);
	return;
}
Пример #6
0
float input::get_float() {
    auto t = get_int();
    return *(float*)&t;
}
Пример #7
0
static int create_audiobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
#ifdef AUDIO
	int flags;
	int sample_rate;
	int desired_buffer;

	int stereo;
	int bitsize;
	int compressed;

	int format;

	if (!mve_audio_enabled)
		return 1;

	if (audiobuf_created)
		return 1;
	else
		audiobuf_created = 1;

	flags = get_ushort(data + 2);
	sample_rate = get_ushort(data + 4);
	desired_buffer = get_int(data + 6);

	stereo = (flags & MVE_AUDIO_FLAGS_STEREO) ? 1 : 0;
	bitsize = (flags & MVE_AUDIO_FLAGS_16BIT) ? 1 : 0;

	if (minor > 0) {
		compressed = flags & MVE_AUDIO_FLAGS_COMPRESSED ? 1 : 0;
	} else {
		compressed = 0;
	}

	mve_audio_compressed = compressed;

	if (bitsize == 1) {
#ifdef WORDS_BIGENDIAN
		format = AUDIO_S16MSB;
#else
		format = AUDIO_S16LSB;
#endif
	} else {
		format = AUDIO_U8;
	}

	fprintf(stderr, "creating audio buffers:\n");
	fprintf(stderr, "sample rate = %d, stereo = %d, bitsize = %d, compressed = %d\n",
			sample_rate, stereo, bitsize ? 16 : 8, compressed);

	mve_audio_spec = (SDL_AudioSpec *)d_malloc(sizeof(SDL_AudioSpec));
	mve_audio_spec->freq = sample_rate;
	mve_audio_spec->format = format;
	mve_audio_spec->channels = (stereo) ? 2 : 1;
	mve_audio_spec->samples = 4096;
	mve_audio_spec->callback = mve_audio_callback;
	mve_audio_spec->userdata = NULL;
	if (SDL_OpenAudio(mve_audio_spec, NULL) >= 0)
	{
		fprintf(stderr, "   success\n");
		mve_audio_canplay = 1;
	}
	else
	{
		fprintf(stderr, "   failure : %s\n", SDL_GetError());
		mve_audio_canplay = 0;
	}

	memset(mve_audio_buffers, 0, sizeof(mve_audio_buffers));
	memset(mve_audio_buflens, 0, sizeof(mve_audio_buflens));
#endif

	return 1;
}
Пример #8
0
BOOL read_file_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13],c,cmd[LEN_CMD+1];
	short	i,j,n;
	long	offset=0,t;
	FILE	*instream;

	strcpy(fname,"file.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE); 
	}

	get_int(cfg->min_dspace,instream);
	get_int(cfg->max_batup,instream);

	get_int(cfg->max_batdn,instream);

	get_int(cfg->max_userxfer,instream);

	get_int(t,instream);	/* unused - was cdt_byte_value */
	get_int(cfg->cdt_up_pct,instream);
	get_int(cfg->cdt_dn_pct,instream);
	get_int(t,instream);	/* unused - was temp_ext */
	get_str(cmd,instream);	/* unused - was temp_cmd */
	get_int(cfg->leech_pct,instream);
	get_int(cfg->leech_sec,instream);
	get_int(cfg->file_misc,instream);

	for(i=0;i<30;i++)
		get_int(n,instream);

	/**************************/
	/* Extractable File Types */
	/**************************/

	get_int(cfg->total_fextrs,instream);

	if(cfg->total_fextrs) {
		if((cfg->fextr=(fextr_t **)malloc(sizeof(fextr_t *)*cfg->total_fextrs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fextr_t*)*cfg->total_fextrs); 
	} else
		cfg->fextr=NULL;

	for(i=0; i<cfg->total_fextrs; i++) {
		if(feof(instream))
			break;
		if((cfg->fextr[i]=(fextr_t *)malloc(sizeof(fextr_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fextr_t));
		memset(cfg->fextr[i],0,sizeof(fextr_t));
		get_str(cfg->fextr[i]->ext,instream);
		get_str(cfg->fextr[i]->cmd,instream);
		get_str(cfg->fextr[i]->arstr,instream);
		cfg->fextr[i]->ar=ARSTR(cfg->fextr[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_fextrs=i;

	/***************************/
	/* Compressable File Types */
	/***************************/

	get_int(cfg->total_fcomps,instream);

	if(cfg->total_fcomps) {
		if((cfg->fcomp=(fcomp_t **)malloc(sizeof(fcomp_t *)*cfg->total_fcomps))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fcomp_t*)*cfg->total_fcomps); 
	} else
		cfg->fcomp=NULL;

	for(i=0; i<cfg->total_fcomps; i++) {
		if(feof(instream))
			break;
		if((cfg->fcomp[i]=(fcomp_t *)malloc(sizeof(fcomp_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fcomp_t));
		memset(cfg->fcomp[i],0,sizeof(fcomp_t));
		get_str(cfg->fcomp[i]->ext,instream);
		get_str(cfg->fcomp[i]->cmd,instream);
		get_str(cfg->fcomp[i]->arstr,instream);
		cfg->fcomp[i]->ar=ARSTR(cfg->fcomp[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_fcomps=i;

	/***********************/
	/* Viewable File Types */
	/***********************/

	get_int(cfg->total_fviews,instream);

	if(cfg->total_fviews) {
		if((cfg->fview=(fview_t **)malloc(sizeof(fview_t *)*cfg->total_fviews))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fview_t*)*cfg->total_fviews); 
	} else
		cfg->fview=NULL;

	for(i=0; i<cfg->total_fviews; i++) {
		if(feof(instream)) break;
		if((cfg->fview[i]=(fview_t *)malloc(sizeof(fview_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fview_t));
		memset(cfg->fview[i],0,sizeof(fview_t));
		get_str(cfg->fview[i]->ext,instream);
		get_str(cfg->fview[i]->cmd,instream);
		get_str(cfg->fview[i]->arstr,instream);
		cfg->fview[i]->ar=ARSTR(cfg->fview[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_fviews=i;

	/***********************/
	/* Testable File Types */
	/***********************/

	get_int(cfg->total_ftests,instream);

	if(cfg->total_ftests) {
		if((cfg->ftest=(ftest_t **)malloc(sizeof(ftest_t *)*cfg->total_ftests))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(ftest_t*)*cfg->total_ftests); 
	} else
		cfg->ftest=NULL;

	for(i=0; i<cfg->total_ftests; i++) {
		if(feof(instream)) break;
		if((cfg->ftest[i]=(ftest_t *)malloc(sizeof(ftest_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(ftest_t));
		memset(cfg->ftest[i],0,sizeof(ftest_t));
		get_str(cfg->ftest[i]->ext,instream);
		get_str(cfg->ftest[i]->cmd,instream);
		get_str(cfg->ftest[i]->workstr,instream);
		get_str(cfg->ftest[i]->arstr,instream);
		cfg->ftest[i]->ar=ARSTR(cfg->ftest[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_ftests=i;

	/*******************/
	/* Download events */
	/*******************/

	get_int(cfg->total_dlevents,instream);

	if(cfg->total_dlevents) {
		if((cfg->dlevent=(dlevent_t **)malloc(sizeof(dlevent_t *)*cfg->total_dlevents))
			==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dlevent_t*)*cfg->total_dlevents); 
	} else
		cfg->dlevent=NULL;

	for(i=0; i<cfg->total_dlevents; i++) {
		if(feof(instream)) break;
		if((cfg->dlevent[i]=(dlevent_t *)malloc(sizeof(dlevent_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dlevent_t));
		memset(cfg->dlevent[i],0,sizeof(dlevent_t));
		get_str(cfg->dlevent[i]->ext,instream);
		get_str(cfg->dlevent[i]->cmd,instream);
		get_str(cfg->dlevent[i]->workstr,instream);
		get_str(cfg->dlevent[i]->arstr,instream);
		cfg->dlevent[i]->ar=ARSTR(cfg->dlevent[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_dlevents=i;


	/***************************/
	/* File Transfer Protocols */
	/***************************/

	get_int(cfg->total_prots,instream);

	if(cfg->total_prots) {
		if((cfg->prot=(prot_t **)malloc(sizeof(prot_t *)*cfg->total_prots))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(prot_t*)*cfg->total_prots); 
	} else
		cfg->prot=NULL;

	for(i=0;i<cfg->total_prots;i++) {
		if(feof(instream)) break;
		if((cfg->prot[i]=(prot_t *)malloc(sizeof(prot_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(prot_t));
		memset(cfg->prot[i],0,sizeof(prot_t));

		get_int(cfg->prot[i]->mnemonic,instream);
		get_str(cfg->prot[i]->name,instream);
		get_str(cfg->prot[i]->ulcmd,instream);
		get_str(cfg->prot[i]->dlcmd,instream);
		get_str(cfg->prot[i]->batulcmd,instream);
		get_str(cfg->prot[i]->batdlcmd,instream);
		get_str(cfg->prot[i]->blindcmd,instream);
		get_str(cfg->prot[i]->bicmd,instream);
		get_int(cfg->prot[i]->misc,instream);
		get_str(cfg->prot[i]->arstr,instream);
		cfg->prot[i]->ar=ARSTR(cfg->prot[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_prots=i;

	/************************/
	/* Alternate File Paths */
	/************************/

	get_int(cfg->altpaths,instream);

	if(cfg->altpaths) {
		if((cfg->altpath=(char **)malloc(sizeof(char *)*cfg->altpaths))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(char *)*cfg->altpaths); 
	} else
		cfg->altpath=NULL;

	for(i=0;i<cfg->altpaths;i++) {
		if(feof(instream)) break;
		fread(str,LEN_DIR+1,1,instream);
		offset+=LEN_DIR+1;
		backslash(str);
		j=LEN_DIR+1;
		if((cfg->altpath[i]=(char *)malloc(j))==NULL)
			return allocerr(instream,error,offset,fname,j);
		memset(cfg->altpath[i],0,j);
		strcpy(cfg->altpath[i],str);
		for(j=0;j<8;j++)
			get_int(n,instream);
		}

	cfg->altpaths=i;

	/******************/
	/* File Libraries */
	/******************/

	get_int(cfg->total_libs,instream);

	if(cfg->total_libs) {
		if((cfg->lib=(lib_t **)malloc(sizeof(lib_t *)*cfg->total_libs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(lib_t *)*cfg->total_libs);
	} else
		cfg->lib=NULL;

	for(i=0;i<cfg->total_libs;i++) {
		if(feof(instream)) break;
		if((cfg->lib[i]=(lib_t *)malloc(sizeof(lib_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(lib_t));
		memset(cfg->lib[i],0,sizeof(lib_t));
		cfg->lib[i]->offline_dir=INVALID_DIR;

		get_str(cfg->lib[i]->lname,instream);
		get_str(cfg->lib[i]->sname,instream);

		get_str(cfg->lib[i]->arstr,instream);
		cfg->lib[i]->ar=ARSTR(cfg->lib[i]->arstr,cfg);

		get_str(cfg->lib[i]->parent_path,instream);

		get_str(cfg->lib[i]->code_prefix,instream);

		get_int(c,instream);

		for(j=0;j<3;j++)
			get_int(n,instream);	/* 0x0000 */

		for(j=0;j<16;j++)
			get_int(n,instream);	/* 0xffff */
	}
	cfg->total_libs=i;

	/********************/
	/* File Directories */
	/********************/

	cfg->sysop_dir=cfg->user_dir=cfg->upload_dir=INVALID_DIR;
	get_int(cfg->total_dirs,instream);

	if(cfg->total_dirs) {
		if((cfg->dir=(dir_t **)malloc(sizeof(dir_t *)*(cfg->total_dirs+1)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dir_t *)*(cfg->total_dirs+1));
	} else
		cfg->dir=NULL;

	for(i=0;i<cfg->total_dirs;i++) {
		if(feof(instream)) break;
		if((cfg->dir[i]=(dir_t *)malloc(sizeof(dir_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dir_t));
		memset(cfg->dir[i],0,sizeof(dir_t));

		get_int(cfg->dir[i]->lib,instream);
		get_str(cfg->dir[i]->lname,instream);
		get_str(cfg->dir[i]->sname,instream);

		if(!stricmp(cfg->dir[i]->sname,"SYSOP"))			/* Sysop upload directory */
			cfg->sysop_dir=i;
		else if(!stricmp(cfg->dir[i]->sname,"USER"))		/* User to User xfer dir */
			cfg->user_dir=i;
		else if(!stricmp(cfg->dir[i]->sname,"UPLOADS"))  /* Upload directory */
			cfg->upload_dir=i;
		else if(!stricmp(cfg->dir[i]->sname,"OFFLINE"))	/* Offline files dir */
			cfg->lib[cfg->dir[i]->lib]->offline_dir=i;

		get_str(cfg->dir[i]->code_suffix,instream);

		get_str(cfg->dir[i]->data_dir,instream);

		get_str(cfg->dir[i]->arstr,instream);
		get_str(cfg->dir[i]->ul_arstr,instream);
		get_str(cfg->dir[i]->dl_arstr,instream);
		get_str(cfg->dir[i]->op_arstr,instream);

		cfg->dir[i]->ar=ARSTR(cfg->dir[i]->arstr,cfg);
		cfg->dir[i]->ul_ar=ARSTR(cfg->dir[i]->ul_arstr,cfg);
		cfg->dir[i]->dl_ar=ARSTR(cfg->dir[i]->dl_arstr,cfg);
		cfg->dir[i]->op_ar=ARSTR(cfg->dir[i]->op_arstr,cfg);

		get_str(cfg->dir[i]->path,instream);

		get_str(cfg->dir[i]->upload_sem,instream);

		get_int(cfg->dir[i]->maxfiles,instream);
		if(cfg->dir[i]->maxfiles>MAX_FILES)
			cfg->dir[i]->maxfiles=MAX_FILES;
		get_str(cfg->dir[i]->exts,instream);
		get_int(cfg->dir[i]->misc,instream);
		get_int(cfg->dir[i]->seqdev,instream);
		get_int(cfg->dir[i]->sort,instream);
		get_str(cfg->dir[i]->ex_arstr,instream);
		cfg->dir[i]->ex_ar=ARSTR(cfg->dir[i]->ex_arstr,cfg);

		get_int(cfg->dir[i]->maxage,instream);
		get_int(cfg->dir[i]->up_pct,instream);
		get_int(cfg->dir[i]->dn_pct,instream);
		get_int(c,instream);
		for(j=0;j<24;j++)
			get_int(n,instream); 
	}

	cfg->total_dirs=i;

	/**********************/
	/* Text File Sections */
	/**********************/

	get_int(cfg->total_txtsecs,instream);


	if(cfg->total_txtsecs) {
		if((cfg->txtsec=(txtsec_t **)malloc(sizeof(txtsec_t *)*cfg->total_txtsecs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(txtsec_t *)*cfg->total_txtsecs); 
	} else
		cfg->txtsec=NULL;

	for(i=0;i<cfg->total_txtsecs;i++) {
		if(feof(instream)) break;
		if((cfg->txtsec[i]=(txtsec_t *)malloc(sizeof(txtsec_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(txtsec_t));
		memset(cfg->txtsec[i],0,sizeof(txtsec_t));

		get_str(cfg->txtsec[i]->name,instream);
		get_str(cfg->txtsec[i]->code,instream);
		get_str(cfg->txtsec[i]->arstr,instream);
		cfg->txtsec[i]->ar=ARSTR(cfg->txtsec[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_txtsecs=i;

	fclose(instream);
	return(TRUE);
}
Пример #9
0
BOOL read_chat_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13];
	short	i,j,n;
	long	offset=0;
	FILE	*instream;

	strcpy(fname,"chat.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE);
	}

	/*********/
	/* Gurus */
	/*********/

	get_int(cfg->total_gurus,instream);

	if(cfg->total_gurus) {
		if((cfg->guru=(guru_t **)malloc(sizeof(guru_t *)*cfg->total_gurus))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(guru_t *)*cfg->total_gurus);
	} else
		cfg->guru=NULL;

	for(i=0;i<cfg->total_gurus;i++) {
		if(feof(instream)) break;
		if((cfg->guru[i]=(guru_t *)malloc(sizeof(guru_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(guru_t));
		memset(cfg->guru[i],0,sizeof(guru_t));

		get_str(cfg->guru[i]->name,instream);
		get_str(cfg->guru[i]->code,instream);

		get_str(cfg->guru[i]->arstr,instream);
		cfg->guru[i]->ar=ARSTR(cfg->guru[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_chans=i;


	/********************/
	/* Chat Action Sets */
	/********************/

	get_int(cfg->total_actsets,instream);

	if(cfg->total_actsets) {
		if((cfg->actset=(actset_t **)malloc(sizeof(actset_t *)*cfg->total_actsets))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(actset_t *)*cfg->total_actsets);
	} else
		cfg->actset=NULL;

	for(i=0;i<cfg->total_actsets;i++) {
		if(feof(instream)) break;
		if((cfg->actset[i]=(actset_t *)malloc(sizeof(actset_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(actset_t));
		get_str(cfg->actset[i]->name,instream);
	}
	cfg->total_actsets=i;


	/****************/
	/* Chat Actions */
	/****************/

	get_int(cfg->total_chatacts,instream);

	if(cfg->total_chatacts) {
		if((cfg->chatact=(chatact_t **)malloc(sizeof(chatact_t *)*cfg->total_chatacts))
			==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chatact_t *)*cfg->total_chatacts);
	} else
		cfg->chatact=NULL;

	for(i=0;i<cfg->total_chatacts;i++) {
		if(feof(instream)) break;
		if((cfg->chatact[i]=(chatact_t *)malloc(sizeof(chatact_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chatact_t));
		memset(cfg->chatact[i],0,sizeof(chatact_t));

		get_int(cfg->chatact[i]->actset,instream);
		get_str(cfg->chatact[i]->cmd,instream);
		get_str(cfg->chatact[i]->out,instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}

	cfg->total_chatacts=i;


	/***************************/
	/* Multinode Chat Channels */
	/***************************/

	get_int(cfg->total_chans,instream);

	if(cfg->total_chans) {
		if((cfg->chan=(chan_t **)malloc(sizeof(chan_t *)*cfg->total_chans))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chan_t *)*cfg->total_chans);
	} else
		cfg->chan=NULL;

	for(i=0;i<cfg->total_chans;i++) {
		if(feof(instream)) break;
		if((cfg->chan[i]=(chan_t *)malloc(sizeof(chan_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chan_t));
		memset(cfg->chan[i],0,sizeof(chan_t));

		get_int(cfg->chan[i]->actset,instream);
		get_str(cfg->chan[i]->name,instream);

		get_str(cfg->chan[i]->code,instream);

		get_str(cfg->chan[i]->arstr,instream);
		cfg->chan[i]->ar=ARSTR(cfg->chan[i]->arstr,cfg);

		get_int(cfg->chan[i]->cost,instream);
		get_int(cfg->chan[i]->guru,instream);
		get_int(cfg->chan[i]->misc,instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_chans=i;


	/**************/
	/* Chat Pages */
	/**************/

	get_int(cfg->total_pages,instream);

	if(cfg->total_pages) {
		if((cfg->page=(page_t **)malloc(sizeof(page_t *)*cfg->total_pages))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(page_t *)*cfg->total_pages);
	} else
		cfg->page=NULL;

	for(i=0;i<cfg->total_pages;i++) {
		if(feof(instream)) break;
		if((cfg->page[i]=(page_t *)malloc(sizeof(page_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(page_t));
		memset(cfg->page[i],0,sizeof(page_t));

		get_str(cfg->page[i]->cmd,instream);

		get_str(cfg->page[i]->arstr,instream);
		cfg->page[i]->ar=ARSTR(cfg->page[i]->arstr,cfg);

		get_int(cfg->page[i]->misc,instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_pages=i;


	fclose(instream);
	return(TRUE);
}
Пример #10
0
static void
view_ast(BaseAST* ast, bool number = false, int mark = -1, int indent = 0) {
  if (!ast)
    return;
  if (Expr* expr = toExpr(ast)) {
    printf("\n");
    for (int i = 0; i < indent; i++)
      printf(" ");
    printf("(");
    if (ast->id == mark)
      printf("***");
    if (number)
      printf("%d ", ast->id);
    printf("%s", expr->astTagAsString());

    if (isBlockStmt(expr))
      if (FnSymbol* fn = toFnSymbol(expr->parentSymbol))
        if (expr == fn->where)
          printf(" where");

    if (GotoStmt *gs= toGotoStmt(ast)) {
      printf( " ");
      view_ast(gs->label, number, mark, indent+1);
    }

    if (CallExpr* call = toCallExpr(expr))
      if (call->primitive)
        printf(" %s", call->primitive->name);

    if (NamedExpr* named = toNamedExpr(expr))
      printf(" \"%s\"", named->name);

    if (toDefExpr(expr))
      printf(" ");

    int64_t i;
    const char *str;
    if (get_int(expr, &i)) {
      printf(" %" PRId64, i);
    } else if (get_string(expr, &str)) {
      printf(" \"%s\"", str);
    }

    if (SymExpr* sym = toSymExpr(expr)) {
      printf(" ");
      view_sym(sym->var, number, mark);
    } else if (UnresolvedSymExpr* sym = toUnresolvedSymExpr(expr)) {
      printf(" '%s'", sym->unresolved);
    }
  }

  if (Symbol* sym = toSymbol(ast)) {
    view_sym(sym, number, mark);
  }

  AST_CHILDREN_CALL(ast, view_ast, number, mark, indent+2);

  if (DefExpr* def = toDefExpr(ast)) {
    printf(" ");
    writeFlags(stdout, def->sym);
  }

  if (toExpr(ast))
    printf(")");
}
Пример #11
0
BOOL read_xtrn_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13],c;
	short	i,j,n;
	long	offset=0;
	FILE	*instream;

	strcpy(fname,"xtrn.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE); 
	}

	/*************/
	/* Swap list */
	/*************/

	get_int(cfg->total_swaps,instream);

	if(cfg->total_swaps) {
		if((cfg->swap=(swap_t **)malloc(sizeof(swap_t *)*cfg->total_swaps))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(swap_t *)*cfg->total_swaps); 
	} else
		cfg->swap=NULL;

	for(i=0;i<cfg->total_swaps;i++) {
		if(feof(instream)) break;
		if((cfg->swap[i]=(swap_t *)malloc(sizeof(swap_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(swap_t));
		get_str(cfg->swap[i]->cmd,instream); 
	}
	cfg->total_swaps=i;

	/********************/
	/* External Editors */
	/********************/

	get_int(cfg->total_xedits,instream);

	if(cfg->total_xedits) {
		if((cfg->xedit=(xedit_t **)malloc(sizeof(xedit_t *)*cfg->total_xedits))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xedit_t *)*cfg->total_xedits); 
	} else
		cfg->xedit=NULL;

	for(i=0;i<cfg->total_xedits;i++) {
		if(feof(instream)) break;
		if((cfg->xedit[i]=(xedit_t *)malloc(sizeof(xedit_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xedit_t));
		memset(cfg->xedit[i],0,sizeof(xedit_t));

		get_str(cfg->xedit[i]->name,instream);
		get_str(cfg->xedit[i]->code,instream);
		get_str(cfg->xedit[i]->lcmd,instream);
		get_str(cfg->xedit[i]->rcmd,instream);

		get_int(cfg->xedit[i]->misc,instream);
		get_str(cfg->xedit[i]->arstr,instream);
		cfg->xedit[i]->ar=ARSTR(cfg->xedit[i]->arstr,cfg);

		get_int(cfg->xedit[i]->type,instream);
		get_int(c,instream);
		for(j=0;j<7;j++)
			get_int(n,instream);
	}
	cfg->total_xedits=i;


	/*****************************/
	/* External Program Sections */
	/*****************************/

	get_int(cfg->total_xtrnsecs,instream);

	if(cfg->total_xtrnsecs) {
		if((cfg->xtrnsec=(xtrnsec_t **)malloc(sizeof(xtrnsec_t *)*cfg->total_xtrnsecs))
			==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrnsec_t *)*cfg->total_xtrnsecs);
	} else
		cfg->xtrnsec=NULL;

	for(i=0;i<cfg->total_xtrnsecs;i++) {
		if(feof(instream)) break;
		if((cfg->xtrnsec[i]=(xtrnsec_t *)malloc(sizeof(xtrnsec_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrnsec_t));
		memset(cfg->xtrnsec[i],0,sizeof(xtrnsec_t));

		get_str(cfg->xtrnsec[i]->name,instream);
		get_str(cfg->xtrnsec[i]->code,instream);
		get_str(cfg->xtrnsec[i]->arstr,instream);
		cfg->xtrnsec[i]->ar=ARSTR(cfg->xtrnsec[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_xtrnsecs=i;


	/*********************/
	/* External Programs */
	/*********************/

	get_int(cfg->total_xtrns,instream);

	if(cfg->total_xtrns) {
		if((cfg->xtrn=(xtrn_t **)malloc(sizeof(xtrn_t *)*cfg->total_xtrns))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrn_t *)*cfg->total_xtrns);
	} else
		cfg->xtrn=NULL;

	for(i=0;i<cfg->total_xtrns;i++) {
		if(feof(instream)) break;
		if((cfg->xtrn[i]=(xtrn_t *)malloc(sizeof(xtrn_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrn_t));
		memset(cfg->xtrn[i],0,sizeof(xtrn_t));

		get_int(cfg->xtrn[i]->sec,instream);
		get_str(cfg->xtrn[i]->name,instream);
		get_str(cfg->xtrn[i]->code,instream);
		get_str(cfg->xtrn[i]->arstr,instream);
		get_str(cfg->xtrn[i]->run_arstr,instream);
		cfg->xtrn[i]->ar=ARSTR(cfg->xtrn[i]->arstr,cfg);
		cfg->xtrn[i]->run_ar=ARSTR(cfg->xtrn[i]->run_arstr,cfg);

		get_int(cfg->xtrn[i]->type,instream);
		get_int(cfg->xtrn[i]->misc,instream);
		get_int(cfg->xtrn[i]->event,instream);
		get_int(cfg->xtrn[i]->cost,instream);
		get_str(cfg->xtrn[i]->cmd,instream);
		get_str(cfg->xtrn[i]->clean,instream);
		get_str(cfg->xtrn[i]->path,instream);
		get_int(cfg->xtrn[i]->textra,instream);
		get_int(cfg->xtrn[i]->maxtime,instream);
		for(j=0;j<7;j++)
			get_int(n,instream);
	}
	cfg->total_xtrns=i;


	/****************/
	/* Timed Events */
	/****************/

	get_int(cfg->total_events,instream);

	if(cfg->total_events) {
		if((cfg->event=(event_t **)malloc(sizeof(event_t *)*cfg->total_events))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(event_t *)*cfg->total_events);
	} else
		cfg->event=NULL;

	for(i=0;i<cfg->total_events;i++) {
		if(feof(instream)) break;
		if((cfg->event[i]=(event_t *)malloc(sizeof(event_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(event_t));
		memset(cfg->event[i],0,sizeof(event_t));

		get_str(cfg->event[i]->code,instream);
		get_str(cfg->event[i]->cmd,instream);
		get_int(cfg->event[i]->days,instream);
		get_int(cfg->event[i]->time,instream);
		get_int(cfg->event[i]->node,instream);
		get_int(cfg->event[i]->misc,instream);
		get_str(cfg->event[i]->dir,instream);
		get_int(cfg->event[i]->freq,instream);
		get_int(cfg->event[i]->mdays,instream);

		for(j=0;j<5;j++)
			get_int(n,instream);
	}
	cfg->total_events=i;

	/********************************/
	/* Native (32-bit) Program list */
	/********************************/

	get_int(cfg->total_natvpgms,instream);

	if(cfg->total_natvpgms) {
		if((cfg->natvpgm=(natvpgm_t **)malloc(sizeof(natvpgm_t *)*cfg->total_natvpgms))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(natvpgm_t *)*cfg->total_natvpgms);
	} else
		cfg->natvpgm=NULL;

	for(i=0;i<cfg->total_natvpgms;i++) {
		if(feof(instream)) break;
		if((cfg->natvpgm[i]=(natvpgm_t *)malloc(sizeof(natvpgm_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(natvpgm_t));
		get_str(cfg->natvpgm[i]->name,instream);
		cfg->natvpgm[i]->misc=0; 
	}
	cfg->total_natvpgms=i;
	for(i=0;i<cfg->total_natvpgms;i++) {
		if(feof(instream)) break;
		get_int(cfg->natvpgm[i]->misc,instream);
	}

	/*******************/
	/* Global Hot Keys */
	/*******************/

	get_int(cfg->total_hotkeys,instream);

	if(cfg->total_hotkeys) {
		if((cfg->hotkey=(hotkey_t **)malloc(sizeof(hotkey_t *)*cfg->total_hotkeys))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(hotkey_t *)*cfg->total_hotkeys);
	} else
		cfg->hotkey=NULL;

	for(i=0;i<cfg->total_hotkeys;i++) {
		if(feof(instream)) break;
		if((cfg->hotkey[i]=(hotkey_t *)malloc(sizeof(hotkey_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(hotkey_t));
		memset(cfg->hotkey[i],0,sizeof(hotkey_t));

		get_int(cfg->hotkey[i]->key,instream);
		get_str(cfg->hotkey[i]->cmd,instream);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_hotkeys=i;

	/************************************/
	/* External Program-related Toggles */
	/************************************/
	get_int(cfg->xtrn_misc,instream);

	fclose(instream);
	return(TRUE);
}
static void
process(void)
{
	u_int msg_len, buf_len, consumed, type, i;
	u_char *cp;
	u_int32_t id;

	buf_len = buffer_len(&iqueue);
	if (buf_len < 5)
		return;		/* Incomplete message. */
	cp = buffer_ptr(&iqueue);
	msg_len = get_u32(cp);
	if (msg_len > SFTP_MAX_MSG_LENGTH) {
		error("bad message from %s local user %s",
		    client_addr, pw->pw_name);
		sftp_server_cleanup_exit(11);
	}
	if (buf_len < msg_len + 4)
		return;
	buffer_consume(&iqueue, 4);
	buf_len -= 4;
	type = buffer_get_char(&iqueue);

	switch (type) {
	case SSH2_FXP_INIT:
		process_init();
		init_done = 1;
		break;
	case SSH2_FXP_EXTENDED:
		if (!init_done)
			fatal("Received extended request before init");
		id = get_int();
		process_extended(id);
		break;
	default:
		if (!init_done)
			fatal("Received %u request before init", type);
		id = get_int();
		for (i = 0; handlers[i].handler != NULL; i++) {
			if (type == handlers[i].type) {
				if (!request_permitted(&handlers[i])) {
					send_status(id,
					    SSH2_FX_PERMISSION_DENIED);
				} else {
					handlers[i].handler(id);
				}
				break;
			}
		}
		if (handlers[i].handler == NULL)
#ifdef NERSC_MOD
                        {
                        s_audit("sftp_process_unknown_3", "count=%i int=%d uristring=%d",
                                get_client_session_id(), (int)getppid(), type);
#endif
                        error("Unknown message %u", type);
#ifdef NERSC_MOD
                        }
#endif
	}
	/* discard the remaining bytes from the current packet */
	if (buf_len < buffer_len(&iqueue)) {
		error("iqueue grew unexpectedly");
		sftp_server_cleanup_exit(255);
	}
	consumed = buf_len - buffer_len(&iqueue);
	if (msg_len < consumed) {
		error("msg_len %u < consumed %u", msg_len, consumed);
		sftp_server_cleanup_exit(255);
	}
	if (msg_len > consumed)
		buffer_consume(&iqueue, msg_len - consumed);
}
Пример #13
0
				aux1=aux1->next;
			}
		}
		else printw("\n não possui ligações\n");
	}
	
	return 1;
}

int relacoes_modificar (long long nif,Grafo *rm, Grafo *new, long long *id_max){
	
	long long nif2;
	int peso;
	
	nif2=ler_nif();
	peso=get_int(2,0);
	if(nif2==nif){
		clear();
		printw("impossivel alterar ligação consigo mesmo");
		getch();
		return 0;
	}			
	
	if(alterar_relacao(id_max,nif,nif2,peso,rm,new)){
		 printw("\nRelação alterada com sucesso");
		 getch();}
	else {
		 printw("\nImpossivel alterar relação");
		 getch();}

return 1;
Пример #14
0
// Return 0 for OK, -1 for error.
int do_backup_client(struct asfd *asfd, struct conf **confs, enum action action,
	int resume)
{
	int ret=-1;
	int breaking=get_int(confs[OPT_BREAKPOINT]);

	if(action==ACTION_ESTIMATE)
		logp("do estimate client\n");
	else
	{
		logp("do backup client\n");
		if(get_protocol(confs)==PROTO_1)
			logp("Using librsync hash %s\n",
			  rshash_to_str(get_e_rshash(confs[OPT_RSHASH])));
	}

#ifdef HAVE_WIN32
	win32_enable_backup_privileges();
#ifdef WIN32_VSS
	if(win32_start_vss(confs)) return ret;
#endif
	if(action==ACTION_BACKUP_TIMED) set_low_priority();
#endif

	// Scan the file system and send the results to the server.
	// Skip phase1 if the server wanted to resume.
	if(!resume)
	{
		if(breaking==1)
		{
			breakpoint(breaking, __func__);
			goto end;
		}
		if(backup_phase1_client(asfd, confs, action==ACTION_ESTIMATE))
			goto end;
	}

	switch(action)
	{
		case ACTION_DIFF:
		case ACTION_DIFF_LONG:
			ret=1;
			goto end;
		case ACTION_ESTIMATE:
			cntr_print(get_cntr(confs), ACTION_ESTIMATE);
			break;
		default:
			// Now, the server will be telling us what data we need
			// to send.
			if(breaking==2)
			{
				breakpoint(breaking, __func__);
				goto end;
			}

			if(get_protocol(confs)==PROTO_1)
				ret=backup_phase2_client_protocol1(asfd,
					confs, resume);
			else
				ret=backup_phase2_client_protocol2(asfd,
					confs, resume);
			if(ret) goto end;
			break;
	}

	ret=0;
end:
#if defined(HAVE_WIN32)
	if(action==ACTION_BACKUP_TIMED) unset_low_priority();
#if defined(WIN32_VSS)
	win32_stop_vss();
#endif
#endif
	return ret;
}
Пример #15
0
static void process_buddy_im( struct qqclient* qq, qqpacket* p, qqmessage* msg )
{
	bytebuffer *buf = p->buf;
	get_word( buf );	//version
	msg->from = get_int( buf );
	if( get_int( buf ) != qq->number ){
		DBG("nothing but this is impossible!!");
		return;
	}
	//to check if this buddy is in our list, or we add it.
	buddy_get( qq, msg->from, 1 );
	//IM key
	uchar key[16];
	get_data( buf, key, 16 );
	ushort content_type = get_word( buf );
	switch( content_type ){
	case QQ_NORMAL_IM_TEXT:
	//	DBG("QQ_NORMAL_IM_TEXT");
		process_buddy_im_text( qq, p, msg );
		break;
	case QQ_NORMAL_IM_FILE_REQUEST_TCP:
		DBG("QQ_NORMAL_IM_FILE_REQUEST_TCP");
		break;
	case QQ_NORMAL_IM_FILE_APPROVE_TCP:
		DBG("QQ_NORMAL_IM_FILE_APPROVE_TCP");
		break;
	case QQ_NORMAL_IM_FILE_REJECT_TCP:
		DBG("QQ_NORMAL_IM_FILE_REJECT_TCP");
		break;
	case QQ_NORMAL_IM_FILE_REQUEST_UDP:
		DBG("QQ_NORMAL_IM_FILE_REQUEST_UDP");
		break;
	case QQ_NORMAL_IM_FILE_APPROVE_UDP:
		DBG("QQ_NORMAL_IM_FILE_APPROVE_UDP");
		break;
	case QQ_NORMAL_IM_FILE_REJECT_UDP:
		DBG("QQ_NORMAL_IM_FILE_REJECT_UDP");
		break;
	case QQ_NORMAL_IM_FILE_NOTIFY:
		DBG("QQ_NORMAL_IM_FILE_NOTIFY");
		break;
	case QQ_NORMAL_IM_FILE_PASV:
		DBG("QQ_NORMAL_IM_FILE_PASV");
		break;
	case QQ_NORMAL_IM_FILE_CANCEL:
		DBG("QQ_NORMAL_IM_FILE_CANCEL");
		break;
	case QQ_NORMAL_IM_FILE_EX_REQUEST_UDP:
		DBG("QQ_NORMAL_IM_FILE_EX_REQUEST_UDP");
		break;
	case QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT:
		DBG("QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT");
		break;
	case QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL:
		DBG("QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL");
		break;
	case QQ_NORMAL_IM_FILE_EX_NOTIFY_IP:
		DBG("QQ_NORMAL_IM_FILE_EX_NOTIFY_IP");
		break;
	default:
		DBG("UNKNOWN type: %x", content_type );
		break;
	}
}
Пример #16
0
// Read a status buffer all of the key observation paramters
void guppi_read_subint_params(char *buf, 
                              struct guppi_params *g, 
                              struct psrfits *p)
{
    // Parse packet size, # of packets, etc.
    get_lon("PKTIDX", g->packetindex, -1L);
    get_int("PKTSIZE", g->packetsize, 0);
    get_int("NPKT", g->n_packets, 0);
    get_int("NDROP", g->n_dropped, 0);
    get_dbl("DROPAVG", g->drop_frac_avg, 0.0);
    get_dbl("DROPTOT", g->drop_frac_tot, 0.0);
    get_int("BLOCSIZE", g->packets_per_block, 0);
    if (g->packetsize>0)
        g->packets_per_block /= g->packetsize;
    if (g->n_packets>0)
        g->drop_frac = (double) g->n_dropped / (double) g->n_packets;
    else
        g->drop_frac = 0.0;

    // Valid obs start time
    get_int("STTVALID", g->stt_valid, 0);

    // Observation params
    get_dbl("AZ", p->sub.tel_az, 0.0);
    if (p->sub.tel_az < 0.0) p->sub.tel_az += 360.0;
    get_dbl("ZA", p->sub.tel_zen, 0.0);
    get_dbl("RA", p->sub.ra, 0.0);
    get_dbl("DEC", p->sub.dec, 0.0);

    // Backend HW parameters
    get_int("ACC_LEN", g->decimation_factor, 0);
    get_int("NBITSADC", g->n_bits_adc, 8);
    get_int("PFB_OVER", g->pfb_overlap, 4);

    // Check fold mode 
    int fold=0;
    if (strstr("PSR", p->hdr.obs_mode)!=NULL) { fold=1; }
    if (strstr("CAL", p->hdr.obs_mode)!=NULL) { fold=1; }

    // Fold-specifc stuff
    if (fold) {
        get_dbl("TSUBINT", p->sub.tsubint, 0.0); 
        get_dbl("OFFS_SUB", p->sub.offs, 0.0); 
        get_int("NPOLYCO", p->fold.n_polyco_sets, 0);
    } else {
        int bytes_per_dt = p->hdr.nchan * p->hdr.npol * p->hdr.nbits / 8;
        p->sub.offs = p->hdr.dt * 
            (double)(g->packetindex * g->packetsize / bytes_per_dt)
            + 0.5 * p->sub.tsubint;
        p->fold.n_polyco_sets = 0;
    }

    { // MJD and LST calcs
        int imjd, smjd, lst_secs;
        double offs, mjd;
        get_current_mjd(&imjd, &smjd, &offs);
        mjd = (double) imjd + ((double) smjd + offs) / 86400.0;
        get_current_lst(mjd, &lst_secs);
        p->sub.lst = (double) lst_secs;
    }

    // Until we need them...
    p->sub.feed_ang = 0.0;
    p->sub.pos_ang = 0.0;
    p->sub.par_ang = 0.0;
    
    // Galactic coords
    slaEqgal(p->sub.ra*DEGTORAD, p->sub.dec*DEGTORAD,
             &p->sub.glon, &p->sub.glat);
    p->sub.glon *= RADTODEG;
    p->sub.glat *= RADTODEG;
}
Пример #17
0
void prot_im_recv_msg( struct qqclient* qq, qqpacket* p )
{
	bytebuffer *buf = p->buf;
	uint from, from_ip;
	ushort from_port;
	ushort im_type;
	int len;
	qqmessage *msg;
/* 091027 This code maybe good for a client that prints the message as soon as it gets one.
	if( qq->login_finish!=1 ){	//not finished login
		DBG("Early message ... Abandoned.");
		return;
	}
*/
	NEW( msg, sizeof( qqmessage ) );
	if( !msg )
		return;
	//
	from = get_int( buf );
	if( get_int( buf ) != qq->number ){
		DBG("qq->number is not equal to yours");
	}
	get_int( buf );	//sequence
	from_ip = get_int( buf );
	from_port = get_word( buf );
	im_type = get_word( buf );
	msg->im_type = im_type;
#ifdef NO_IM
	if( im_type == QQ_RECV_IM_SYS_NOTIFICATION ){
#endif
	switch( im_type ){
	case QQ_RECV_IM_BUDDY_0801:
		DBG("QQ_RECV_IM_BUDDY_0801");
		msg->msg_type = MT_BUDDY;
		//fixed for qq2007, webqq. 20090621 17:57
		buf->pos += 2;
		len = get_word( buf );
		buf->pos += len;
		process_buddy_im( qq, p, msg );
		break;
	case QQ_RECV_IM_BUDDY_0802:
		DBG("QQ_RECV_IM_BUDDY_0802");
		msg->msg_type = MT_BUDDY;
		process_buddy_im( qq, p, msg );
		break;
	case QQ_RECV_IM_BUDDY_09:
		DBG("QQ_RECV_IM_BUDDY_09");
		msg->msg_type = MT_BUDDY;
		buf->pos += 11;
		process_buddy_im( qq, p, msg );
		break;
	case QQ_RECV_IM_BUDDY_09SP1:
		DBG("QQ_RECV_IM_BUDDY_09SP1");
		msg->msg_type = MT_BUDDY;
		buf->pos += 2;
		len = get_word( buf );
		buf->pos += len;
		process_buddy_im( qq, p, msg );
		break;
	case QQ_RECV_IM_SOMEBODY:
		DBG("QQ_RECV_IM_SOMEBODY");
		break;
	case QQ_RECV_IM_WRITING:
		DBG("QQ_RECV_IM_WRITING");
		break;
	case QQ_RECV_IM_QUN_IM:
		DBG("QQ_RECV_IM_QUN_IM");
		break;
	case QQ_RECV_IM_QUN_IM_09:
        DBG("QQ_RECV_IM_QUN_IM_09");
		msg->msg_type = MT_QUN;
		msg->qun_number = from;
		process_qun_im( qq, p, msg );
		break;
	case QQ_RECV_IM_TO_UNKNOWN:
		DBG("QQ_RECV_IM_TO_UNKNOWN");
		break;
	case QQ_RECV_IM_NEWS:
		DBG("QQ_RECV_IM_NEWS");
		break;
	case QQ_RECV_IM_UNKNOWN_QUN_IM:
		DBG("QQ_RECV_IM_UNKNOWN_QUN_IM");
		break;
	case QQ_RECV_IM_ADD_TO_QUN:
		DBG("QQ_RECV_IM_ADD_TO_QUN");
		break;
	case QQ_RECV_IM_DEL_FROM_QUN:
		DBG("QQ_RECV_IM_DEL_FROM_QUN");
		break;
	case QQ_RECV_IM_APPLY_ADD_TO_QUN:
		DBG("QQ_RECV_IM_APPLY_ADD_TO_QUN");
		break;
	case QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN:
		DBG("QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN");
		break;
	case QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN:
		DBG("QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN");
		break;
	case QQ_RECV_IM_CREATE_QUN:
		DBG("QQ_RECV_IM_CREATE_QUN");
		break;
	case QQ_RECV_IM_TEMP_QUN_IM:
		DBG("QQ_RECV_IM_TEMP_QUN_IM");
		break;
	case QQ_RECV_IM_SYS_NOTIFICATION:
        DBG("QQ_RECV_IM_SYS_NOTIFICATION");
		msg->msg_type = MT_SYSTEM;
		get_int( buf );	//09 SP1 fixed
		process_sys_im( qq, p, msg );
		break;
	case QQ_RECV_IM_QUN_MEMBER_IM:
        DBG("QQ_RECV_IM_QUN_MEMBER_IM");
		msg->msg_type = MT_QUN_MEMBER;
		process_qun_member_im( qq, p, msg );
		break;
    //modify signiture
    case 0x0041:
        process_buddy_modify_signiture( qq, p, msg );
        break;
	default:
		DBG("Unknown message type : %x", im_type );
	}
#ifdef NO_IM
	}
#endif
	//ack recv
	prot_im_ack_recv( qq, p );
	DEL( msg );
}
Пример #18
0
// Read a status buffer all of the key observation paramters
void guppi_read_obs_params(char *buf, 
                           struct guppi_params *g, 
                           struct psrfits *p)
{
    char base[200], dir[200];

    // Software data-stream modification params
    get_int("DS_TIME", p->hdr.ds_time_fact, 1); // Time down-sampling
    get_int("DS_FREQ", p->hdr.ds_freq_fact, 1); // Freq down-sampling
    get_int("ONLY_I", p->hdr.onlyI, 0);         // Only output Stokes I

    // Freq, BW, etc.
    get_dbl("OBSFREQ", p->hdr.fctr, 0.0);
    get_dbl("OBSBW", p->hdr.BW, 0.0);
    exit_on_missing("OBSBW", p->hdr.BW, 0.0);
    get_int("OBSNCHAN", p->hdr.nchan, 0);
    exit_on_missing("OBSNCHAN", p->hdr.nchan, 0);
    get_int("NPOL", p->hdr.npol, 0);
    exit_on_missing("NPOL", p->hdr.npol, 0);
    get_int("NBITS", p->hdr.nbits, 0);
    exit_on_missing("NBITS", p->hdr.nbits, 0);
    get_dbl("TBIN", p->hdr.dt, 0.0);
    exit_on_missing("TBIN", p->hdr.dt, 0.0);
    get_dbl("CHAN_BW", p->hdr.df, 0.0);
    if (p->hdr.df==0.0) p->hdr.df = p->hdr.BW/p->hdr.nchan;
    get_dbl("SCANLEN", p->hdr.scanlen, 0.0);
    get_int("NRCVR", p->hdr.rcvr_polns, 2);
    p->hdr.orig_df = p->hdr.df;
    p->hdr.orig_nchan = p->hdr.nchan;

    // Observation information
    get_str("TELESCOP", p->hdr.telescope, 24, "GBT");
    get_str("OBSERVER", p->hdr.observer, 24, "Unknown");
    get_str("SRC_NAME", p->hdr.source, 24, "Unknown");
    get_str("FRONTEND", p->hdr.frontend, 24, "Unknown");
    get_str("BACKEND", p->hdr.backend, 24, "GUPPI");
    get_str("PROJID", p->hdr.project_id, 24, "Unknown");
    get_str("FD_POLN", p->hdr.poln_type, 8, "Unknown");
    get_str("POL_TYPE", p->hdr.poln_order, 16, "Unknown");
    get_int("SCANNUM", p->hdr.scan_number, 1);
    get_str("DATADIR", dir, 200, ".");
    if (strcmp(p->hdr.poln_order, "AA+BB")==0 ||
        strcmp(p->hdr.poln_order, "INTEN")==0)
        p->hdr.summed_polns = 1;
    else
        p->hdr.summed_polns = 0;
    get_str("TRK_MODE", p->hdr.track_mode, 16, "Unknown");
    get_str("RA_STR", p->hdr.ra_str, 16, "Unknown");
    get_str("DEC_STR", p->hdr.dec_str, 16, "Unknown");
    // Should set other cal values if CAL_MODE is on
    get_str("CAL_MODE", p->hdr.cal_mode, 8, "Unknown");
    if (!(strcmp(p->hdr.cal_mode, "OFF")==0)) {  // Cals not off
        get_dbl("CAL_FREQ", p->hdr.cal_freq, 25.0);
        get_dbl("CAL_DCYC", p->hdr.cal_dcyc, 0.5);
        get_dbl("CAL_PHS", p->hdr.cal_phs, 0.0);
    }
    get_str("OBS_MODE", p->hdr.obs_mode, 24, "Unknown");

    // Fold mode specific stuff
    int fold=0;
    get_int("NBIN", p->fold.nbin, 256);
    get_dbl("TFOLD", p->fold.tfold, 30.0);
    get_str("PARFILE", p->fold.parfile, 256, "");
    if (strstr("FOLD", p->hdr.obs_mode)!=NULL) { fold=1; }
    if (strstr("PSR", p->hdr.obs_mode)!=NULL) { fold=1; }
    if (strstr("CAL", p->hdr.obs_mode)!=NULL) { fold=1; }
    if (fold) 
        p->hdr.nbin = p->fold.nbin;
    else 
        p->hdr.nbin = 1;

    // Coherent dedispersion params
    get_int("FFTLEN", p->dedisp.fft_len, 0);
    get_int("OVERLAP", p->dedisp.overlap, 0);
    get_dbl("CHAN_DM", p->hdr.chan_dm, 0.0);
    
    { // Start time, MJD
        int mjd_d, mjd_s;
        double mjd_fs;
        get_int("STT_IMJD", mjd_d, 0);
        get_int("STT_SMJD", mjd_s, 0);
        get_dbl("STT_OFFS", mjd_fs, 0.0);
        p->hdr.MJD_epoch = (long double) mjd_d;
        p->hdr.MJD_epoch += ((long double) mjd_s + mjd_fs) / 86400.0;
        p->hdr.start_day = mjd_d;
        p->hdr.start_sec = mjd_s + mjd_fs;
    }
    
    // Set the base filename
    int i;
    char backend[24];
    strncpy(backend, p->hdr.backend, 24);
    for (i=0; i<24; i++) { 
        if (backend[i]=='\0') break;
        backend[i] = tolower(backend[i]); 
    }
    if (strstr("CAL", p->hdr.obs_mode)!=NULL) { 
        sprintf(base, "%s_%5d_%s_%04d_cal", backend, p->hdr.start_day, 
                p->hdr.source, p->hdr.scan_number);
    } else {
        sprintf(base, "%s_%5d_%s_%04d", backend, p->hdr.start_day, 
                p->hdr.source, p->hdr.scan_number);
    }
    sprintf(p->basefilename, "%s/%s", dir, base);

    { // Date and time of start
        int YYYY, MM, DD, h, m;
        double s;
        datetime_from_mjd(p->hdr.MJD_epoch, &YYYY, &MM, &DD, &h, &m, &s);
        sprintf(p->hdr.date_obs, "%04d-%02d-%02dT%02d:%02d:%06.3f", 
                YYYY, MM, DD, h, m, s);
    }

    // TODO: call telescope-specific settings here
    // Eventually make this depend on telescope name
    set_obs_params_gb(buf, g, p);
    
    // Now bookkeeping information
    {
        int ii, jj, kk;
        int bytes_per_dt = p->hdr.nchan * p->hdr.npol * p->hdr.nbits / 8;
        char key[10];
        double offset, scale, dtmp;
        long long max_bytes_per_file;

        get_int("BLOCSIZE", p->sub.bytes_per_subint, 0);
        p->hdr.nsblk = p->sub.bytes_per_subint / bytes_per_dt;
        p->sub.FITS_typecode = TBYTE;
        p->sub.tsubint = p->hdr.nsblk * p->hdr.dt;
        if (fold) { 
            //p->hdr.nsblk = 1;
            p->sub.FITS_typecode = TFLOAT;
            get_dbl("TSUBINT", p->sub.tsubint, 0.0); 
            p->sub.bytes_per_subint = sizeof(float) * p->hdr.nbin *
                p->hdr.nchan * p->hdr.npol;
            max_bytes_per_file = PSRFITS_MAXFILELEN_FOLD * 1073741824L;
        } else {
            max_bytes_per_file = PSRFITS_MAXFILELEN_SEARCH * 1073741824L;
        }
        // Will probably want to tweak this so that it is a nice round number
        if (p->sub.bytes_per_subint!=0)
            p->rows_per_file = p->hdr.ds_freq_fact * p->hdr.ds_time_fact *
                (p->hdr.onlyI ? 4 : 1) * max_bytes_per_file / 
                p->sub.bytes_per_subint;

        // Free the old ones in case we've changed the params
        guppi_free_psrfits(p);

        // Allocate the subband arrays
        p->sub.dat_freqs = (float *)malloc(sizeof(float) * p->hdr.nchan);
        p->sub.dat_weights = (float *)malloc(sizeof(float) * p->hdr.nchan);
        // The following correctly accounts for the middle-of-bin FFT offset
        // XXX This might not be correct for coherent dedisp mode.  Need 
        //     to determine the right way of denoting which nodes are getting
        //     which channels
        dtmp = p->hdr.fctr - 0.5 * p->hdr.BW;
        for (ii = 0 ; ii < p->hdr.nchan ; ii++) {
            //p->sub.dat_freqs[ii] = dtmp + ii * p->hdr.df; // Orig version
            p->sub.dat_freqs[ii] = dtmp + (ii+0.5) * p->hdr.df;
            p->sub.dat_weights[ii] = 1.0;
        }
        // Explicitly weight the DC and Nyquist channels zero
        // because of how power is split between them
        // XXX this needs to be changed for coherent dedisp..
        //p->sub.dat_weights[0] = 0.0;
        
        p->sub.dat_offsets = (float *)malloc(sizeof(float) *  
                                             p->hdr.nchan * p->hdr.npol);
        p->sub.dat_scales = (float *)malloc(sizeof(float) *  
                                            p->hdr.nchan * p->hdr.npol);
        for (ii = 0 ; ii < p->hdr.npol ; ii++) {
            sprintf(key, "OFFSET%d", ii);
            get_dbl(key, offset, 0.0);
            sprintf(key, "SCALE%d", ii);
            get_dbl(key, scale, 1.0);
            for (jj = 0, kk = ii*p->hdr.nchan ; jj < p->hdr.nchan ; jj++, kk++) {
                p->sub.dat_offsets[kk] = offset;
                p->sub.dat_scales[kk] = scale;
            }
        }
    }
    
    // Read information that is appropriate for the subints
    guppi_read_subint_params(buf, g, p);
    p->hdr.azimuth = p->sub.tel_az;
    p->hdr.zenith_ang = p->sub.tel_zen;
    p->hdr.ra2000 = p->sub.ra;
    p->hdr.dec2000 = p->sub.dec;
    p->hdr.start_lst = p->sub.lst;
    p->hdr.feed_angle = p->sub.feed_ang;
}
Пример #19
0
Файл: ca.c Проект: vanElden/burp
int ca_x509_verify_crl(struct conf **confs,
	X509 *peer_cert, const char *ssl_peer_cn)
{
	int n;
	int i;
	int ret=-1;
	BIO *in=NULL;
	BIGNUM *bnser=NULL;
	X509_CRL *crl=NULL;
	X509_REVOKED *revoked;
	ASN1_INTEGER *serial=NULL;
	char *crl_path=NULL;
	const char *ca_name=get_string(confs[OPT_CA_NAME]);
	int crl_check=get_int(confs[OPT_CA_CRL_CHECK]);

	if(!crl_check
	  || !ca_name || !*ca_name
	  || !gca_dir)
	{
		ret=0;
		goto end;
	}

	if(!(crl_path=get_crl_path(ca_name)))
		goto end;

	if(!(in=BIO_new_file(crl_path, "r")))
	{
		logp("CRL: cannot read: %s\n", crl_path);
		goto end;
	}

	if(!(crl=PEM_read_bio_X509_CRL(in, NULL, NULL, NULL)))
	{
		logp_ssl_err("CRL: cannot read CRL from file %s\n", crl_path);
		goto end;
	}

	if(X509_NAME_cmp(X509_CRL_get_issuer(crl),
		X509_get_issuer_name(peer_cert)))
	{
		logp_ssl_err("CRL: CRL %s is from a different issuer than the issuer of certificate %\ns", crl_path, ssl_peer_cn);
		goto end;
	}

	n=sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
	for(i=0; i<n; i++)
	{
		revoked=(X509_REVOKED *)
			sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
		if(!ASN1_INTEGER_cmp(revoked->serialNumber, X509_get_serialNumber(peer_cert)))
		{
			serial=X509_get_serialNumber(peer_cert);
			bnser=ASN1_INTEGER_to_BN(serial, NULL);
			logp_ssl_err("CRL check failed: %s (%s) is revoked\n",
				ssl_peer_cn,
				serial ? BN_bn2hex(bnser):"not available");
			goto end;
		}
	}

	ret=0;
end:
	if(in) BIO_free(in);
	if(crl) X509_CRL_free(crl);
	free_w(&crl_path);
	return ret;
}
Пример #20
0
// Read a status buffer all of the key observation paramters
void guppi_read_obs_params(char *buf, 
                           struct guppi_params *g, 
                           struct sdfits *sf)
{
    char base[200], dir[200];
    double temp_double;
    int temp_int;

    /* Header information */

    get_str("TELESCOP", sf->hdr.telescope, 16, "GBT");
    get_dbl("OBSBW", sf->hdr.bandwidth, 1e9);
    exit_on_missing("OBSBW", sf->hdr.bandwidth, 0.0);
    get_dbl("OBSNCHAN", temp_double, 2048);
    if(temp_double) sf->hdr.freqres = sf->hdr.bandwidth/temp_double;
    get_dbl("TSYS", sf->hdr.tsys, 0.0);

    get_str("PROJID", sf->hdr.projid, 16, "Unknown");
    get_str("FRONTEND", sf->hdr.frontend, 16, "Unknown");
    get_dbl("OBSFREQ", sf->hdr.obsfreq, 0.0);
    get_int("SCANNUM", temp_int, 1);
    sf->hdr.scan = (double)(temp_int);

    get_str("INSTRUME", sf->hdr.instrument, 16, "VEGAS");
    get_str("CAL_MODE", sf->hdr.cal_mode, 16, "Unknown");
    if (!(strcmp(sf->hdr.cal_mode, "OFF")==0))
    {
        get_dbl("CAL_FREQ", sf->hdr.cal_freq, 25.0);
        get_dbl("CAL_DCYC", sf->hdr.cal_dcyc, 0.5);
        get_dbl("CAL_PHS", sf->hdr.cal_phs, 0.0);
    }
    get_int("NPOL", sf->hdr.npol, 2);
    get_int("NCHAN", sf->hdr.nchan, 1024);
    get_dbl("CHAN_BW", sf->hdr.chan_bw, 1e6);

    get_int("NSUBBAND", sf->hdr.nsubband, 1);
    get_dbl("EFSAMPFR", sf->hdr.efsampfr, 3e9);
    get_dbl("FPGACLK", sf->hdr.fpgaclk, 325e6);
    get_dbl("HWEXPOSR", sf->hdr.hwexposr, 0.5e-3);
    get_dbl("FILTNEP", sf->hdr.filtnep, 0);

    get_str("DATADIR", dir, 200, ".");
    get_int("FILENUM", sf->filenum, 0);

    /* Start day and time */

    int YYYY, MM, DD, h, m;
    double s;

    get_dbl("STTMJD", sf->hdr.sttmjd, 0.0);

    datetime_from_mjd(sf->hdr.sttmjd, &YYYY, &MM, &DD, &h, &m, &s);
    sprintf(sf->hdr.date_obs, "%02d/%02d/%02d", DD, MM, YYYY%1000);
   
    /* Set the base filename */

    int i;
    char instrument[24];
    strncpy(instrument, sf->hdr.instrument, 24);
    for (i=0; i<24; i++) { 
        if (instrument[i]=='\0') break;
        instrument[i] = tolower(instrument[i]); 
    }
    sprintf(base, "%s_%02d%02d%02d_%04.2f", instrument, DD, MM, YYYY%1000, sf->hdr.scan);
    sprintf(sf->basefilename, "%s/%s", dir, base);

    // We do not set telescope-specific settings
    /* set_obs_params_gb(buf, g, p); */
    
    // Now bookkeeping information
    {
        int bytes_per_dt = sf->hdr.nsubband * sf->hdr.nchan * 4 * 4;
        long long max_bytes_per_file;

        max_bytes_per_file = SDFITS_MAXFILELEN * 1073741824L;

        sf->rows_per_file = max_bytes_per_file / (96 + bytes_per_dt); 

        // Free the old arrays in case we've changed the params
        guppi_free_sdfits(sf);
    }
    
    // Read information that is appropriate for the subints
    guppi_read_subint_params(buf, g, sf);
}
Пример #21
0
int	handle_cashier(GladeXML* s_glade_personal_information_xml, GladeXML* s_glade_account_status_xml, GladeXML* s_glade_exit_cashier_xml, GtkLayout* screen, int init)
{
  if (init)
    {
      s_personal_information_window =
        gui_get_widget(s_glade_personal_information_xml,
                       "personal_information_window");
      g_assert(s_personal_information_window);
      set_nil_draw_focus(s_personal_information_window);
      if(screen) gtk_layout_put(screen, s_personal_information_window, 0, 0);
      s_account_status_window =
        gui_get_widget(s_glade_account_status_xml,
                       "account_status_window");
      g_assert(s_account_status_window);
      if(screen) gtk_layout_put(screen, s_account_status_window, 0, 0);
      s_exit_cashier_window = gui_get_widget(s_glade_exit_cashier_xml, "exit_cashier_window");
      g_assert(s_exit_cashier_window);
      if(screen) gtk_layout_put(screen, s_exit_cashier_window, 0, 0);
      s_exit_button = GTK_BUTTON(gui_get_widget(s_glade_exit_cashier_xml, "exit_cashier"));
      g_assert(s_exit_button);


      {
        static const char*	entries[ENTRIES_CNT] =
          {
            "entry_player_id",
            "entry_email",
          };
        int	i;

        for (i = 0; i < ENTRIES_CNT; i++)
          s_entries[i] = gui_get_widget(s_glade_personal_information_xml,
                                        entries[i]);
      }

      {
        static const char*	labels[LABELS_CNT] =
          {
            "money_one_available",
            "money_one_in_game",
            "money_one_total",
            "money_two_available",
            "money_two_in_game",
            "money_two_total"
          };
        int	i;

        for (i = 0; i < LABELS_CNT; i++)
          s_labels[i] = gui_get_widget(s_glade_account_status_xml,
                                       labels[i]);
      }

      GUI_BRANCH(s_glade_exit_cashier_xml, on_exit_cashier_clicked);

      gtk_widget_hide(s_personal_information_window);
      gtk_widget_hide(s_account_status_window);
      gtk_widget_hide(s_exit_cashier_window);
    }

  char* showhide = get_string();

  char*	fields[20];
  char**	pfields = fields;
  int	i = get_int();
  int	fields_cnt = 0;

  if(i > 0) {

    g_message("cashier got %d entries", i);
    while (i-- > 0)
      {
        char*	str = get_string();
        if (fields_cnt < 20)
          fields[fields_cnt++] = str;
      }
  

    for (i = 0; i < ENTRIES_CNT; i++)
      {
        char*	str = *pfields++;
        gtk_entry_set_text(GTK_ENTRY(s_entries[i]), str);
      }

    {
      char* str = *pfields++;
      GtkTextView* address = GTK_TEXT_VIEW(gui_get_widget(s_glade_personal_information_xml, "entry_mailing_address"));
      GtkTextBuffer* buffer = gtk_text_view_get_buffer(address);
      gtk_text_buffer_set_text(buffer, str, -1);
    }

    for (i = 0; i < LABELS_CNT; i++)
      {
        char*	str = *pfields++;
        gtk_label_set_text(GTK_LABEL(s_labels[i]), str);
      }

    for (i = 0; i < fields_cnt; i++) {
      g_free(fields[i]);
    }

  }

  if(!strcmp(showhide, "show")) {

    /*
     * calculate windows position
     */
    int	screen_width = gui_width(screen);
    int	screen_height = gui_height(screen);

    /*
     * should be based on the size of the windows ...
     */
    int	top_left_x = (screen_width - 913) / 2;
    int	top_left_y = (screen_height - 450) / 2;
    int	account_status_x = top_left_x + 381;
    int	exit_cashier_y = top_left_y + 320;

    s_personal_information_position.x = top_left_x;
    s_personal_information_position.y = top_left_y;
    s_account_status_position.x = account_status_x;
    s_account_status_position.y = top_left_y;
    s_exit_cashier_position.x = top_left_x;
    s_exit_cashier_position.y = exit_cashier_y;

    {
      char* label = get_string();
      gtk_button_set_label(s_exit_button, label);
      g_free(label);
    }

    {
      //moneyone
      GtkWidget* sl = gui_get_widget(s_glade_account_status_xml, "money_one_name");
      char* label = get_string();
      gtk_label_set_text(GTK_LABEL(sl), label);
      g_free(label);
    }
    {
      //moneytwo
      GtkWidget* sl = gui_get_widget(s_glade_account_status_xml, "money_two_name");
      char* label = get_string();
      gtk_label_set_text(GTK_LABEL(sl), label);
      g_free(label);
    }

    if ((screen != NULL) || (s_cashier_shown == 0))
    {
      gui_place(s_personal_information_window, &s_personal_information_position, screen);
      gui_place(s_account_status_window, &s_account_status_position, screen);
      gui_place(s_exit_cashier_window, &s_exit_cashier_position, screen);
      s_cashier_shown = 1;
    }
  } else {
    if (screen != NULL)
      {
        hide_cashier();
      }
  }

  g_free(showhide);

  return TRUE;
}
Пример #22
0
int pgr_configure(CONTEXT *c, const char *file, int reload)
{
	int rc;
	FILE *io = stdin;
	if (strcmp(file, "-") != 0) {
		io = fopen(file, "r");
		if (!io) {
			return 1;
		}
	}
	PARSER *p = parser_init(file, io, reload);
	fclose(io);
	if (!p) {
		return 1;
	}

	rc = parse(p);
	if (rc != 0) {
		return rc;
	}

	/* update what can be updated */
	if (p->workers.set) {
		c->workers = p->workers.value;
	}
	if (p->loglevel.set) {
		c->loglevel = p->loglevel.value;
	}

	if (p->health_interval.set) {
		c->health.interval = p->health_interval.value;
	}
	if (p->health_timeout.set) {
		c->health.timeout = p->health_timeout.value;
	}
	if (p->health_database.set) {
		free(c->health.database);
		c->health.database = p->health_database.value;
	}
	if (p->health_username.set) {
		free(c->health.username);
		c->health.username = p->health_username.value;
	}
	if (p->health_password.set) {
		free(c->health.password);
		c->health.password = p->health_password.value;
	}

	if (p->listen.set) {
		if (!reload) {
			c->startup.frontend = p->listen.value;
		} else if (strcmp(p->listen.value, c->startup.frontend) != 0) {
			fprintf(stderr, "ignoring new value for `listen %s`; retaining old value '%s'\n",
			                p->listen.value, c->startup.frontend);
			free(p->listen.value);
			p->listen.value = c->startup.frontend;
		}
	}
	if (p->monitor.set) {
		if (!reload) {
			c->startup.monitor = p->monitor.value;
		} else if (strcmp(p->monitor.value, c->startup.monitor) != 0) {
			fprintf(stderr, "ignoring new value for `monitor %s`; retaining old value '%s'\n",
			                p->monitor.value, c->startup.monitor);
			free(p->monitor.value);
			p->monitor.value = c->startup.monitor;
		}
	}
	if (p->hbafile.set) {
		if (!reload) {
			c->startup.hbafile = p->hbafile.value;
		} else if (strcmp(p->hbafile.value, c->startup.hbafile) != 0) {
			fprintf(stderr, "ignoring new value for `hba %s`; retaining old value '%s'\n",
			                p->hbafile.value, c->startup.hbafile);
			free(p->hbafile.value);
			p->hbafile.value = c->startup.hbafile;
		}
	}
	if (p->pidfile.set) {
		if (!reload) {
			c->startup.pidfile = p->pidfile.value;
		} else if (strcmp(p->pidfile.value, c->startup.pidfile) != 0) {
			fprintf(stderr, "ignoring new value for `pidfile %s`; retaining old value '%s'\n",
			                p->pidfile.value, c->startup.pidfile);
			free(p->pidfile.value);
			p->pidfile.value = c->startup.pidfile;
		}
	}
	if (p->authdb.set) {
		if (!reload) {
			c->authdb.file = p->authdb.value;
		} else if (strcmp(p->authdb.value, c->authdb.file) != 0) {
			fprintf(stderr, "ignoring new value for `authdb %s`; retaining old value '%s'\n",
			                p->authdb.value, c->authdb.file);
			free(p->authdb.value);
			p->authdb.value = c->authdb.file;
		}
	}
	if (p->tls_ciphers.set) {
		if (!reload) {
			c->startup.tls_ciphers = p->tls_ciphers.value;
		} else if (strcmp(p->tls_ciphers.value, c->startup.tls_ciphers) != 0) {
			fprintf(stderr, "ignoring new value for `tls_ciphers %s`; retaining old value '%s'\n",
			                p->tls_ciphers.value, c->startup.tls_ciphers);
			free(p->tls_ciphers.value);
			p->tls_ciphers.value = c->startup.tls_ciphers;
		}
	}
	if (p->tls_certfile.set) {
		if (!reload) {
			c->startup.tls_certfile = p->tls_certfile.value;
		} else if (strcmp(p->tls_certfile.value, c->startup.tls_certfile) != 0) {
			fprintf(stderr, "ignoring new value for `tls_certfile %s`; retaining old value '%s'\n",
			                p->tls_certfile.value, c->startup.tls_certfile);
			free(p->tls_certfile.value);
			p->tls_certfile.value = c->startup.tls_certfile;
		}
	}
	if (p->tls_keyfile.set) {
		if (!reload) {
			c->startup.tls_keyfile = p->tls_keyfile.value;
		} else if (strcmp(p->tls_keyfile.value, c->startup.tls_keyfile) != 0) {
			fprintf(stderr, "ignoring new value for `tls_keyfile %s`; retaining old value '%s'\n",
			                p->tls_keyfile.value, c->startup.tls_keyfile);
			free(p->tls_keyfile.value);
			p->tls_keyfile.value = c->startup.tls_keyfile;
		}
	}
	if (p->user.set) {
		if (!reload) {
			c->startup.user = p->user.value;
		} else if (strcmp(p->user.value, c->startup.user) != 0) {
			fprintf(stderr, "ignoring new value for `user %s`; retaining old value '%s'\n",
			                p->user.value, c->startup.user);
			free(p->user.value);
			p->user.value = c->startup.user;
		}
	}
	if (p->group.set) {
		if (!reload) {
			c->startup.group = p->group.value;
		} else if (strcmp(p->group.value, c->startup.group) != 0) {
			fprintf(stderr, "ignoring new value for `group %s`; retaining old value '%s'\n",
			                p->group.value, c->startup.group);
			free(p->group.value);
			p->group.value = c->startup.group;
		}
	}

	if (!reload) {
		struct _backend *b;
		c->num_backends = 0;
		for (b = p->backends; b->next; b = b->next) {
			c->num_backends++;
		}
		c->backends = calloc(c->num_backends, sizeof(BACKEND));
		if (!c->backends) {
			parser_free(p);
			return 1;
		}

		int i;
		struct _backend *def = p->backends;
		b = def->next;
		for (i = 0; i < c->num_backends; i++, b = b->next) {
			rc = hostport(b->id, &c->backends[i].hostname, &c->backends[i].port);
			if (rc != 0) {
				parser_free(p);
				return 1;
			}
			c->backends[i].serial++;

			c->backends[i].tls              = get_int(BACKEND_TLS_OFF, &def->tls, &b->tls);
			c->backends[i].health.threshold = get_int(BACKEND_TLS_OFF, &def->lag, &b->lag);
			c->backends[i].weight           = get_int(BACKEND_TLS_OFF, &def->weight, &b->weight);
			c->backends[i].health.database  = get_str("postgres", &p->health_database, NULL);
			c->backends[i].health.username  = get_str("postgres", &p->health_username, NULL);
			c->backends[i].health.password  = get_str("",         &p->health_password, NULL);
		}
	}

	parser_free(p);
	return 0;
}
Пример #23
0
/**
 * write_pool_threads - Set or report the current number of threads per pool
 *
 * Input:
 *			buf:		ignored
 *			size:		zero
 *
 * OR
 *
 * Input:
 * 			buf:		C string containing whitespace-
 * 					separated unsigned integer values
 *					representing the number of NFSD
 *					threads to start in each pool
 *			size:		non-zero length of C string in @buf
 * Output:
 *	On success:	passed-in buffer filled with '\n'-terminated C
 *			string containing integer values representing the
 *			number of NFSD threads in each pool;
 *			return code is the size in bytes of the string
 *	On error:	return code is zero or a negative errno value
 */
static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
{
	/* if size > 0, look for an array of number of threads per node
	 * and apply them  then write out number of threads per node as reply
	 */
	char *mesg = buf;
	int i;
	int rv;
	int len;
	int npools;
	int *nthreads;

	mutex_lock(&nfsd_mutex);
	npools = nfsd_nrpools();
	if (npools == 0) {
		/*
		 * NFS is shut down.  The admin can start it by
		 * writing to the threads file but NOT the pool_threads
		 * file, sorry.  Report zero threads.
		 */
		mutex_unlock(&nfsd_mutex);
		strcpy(buf, "0\n");
		return strlen(buf);
	}

	nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
	rv = -ENOMEM;
	if (nthreads == NULL)
		goto out_free;

	if (size > 0) {
		for (i = 0; i < npools; i++) {
			rv = get_int(&mesg, &nthreads[i]);
			if (rv == -ENOENT)
				break;		/* fewer numbers than pools */
			if (rv)
				goto out_free;	/* syntax error */
			rv = -EINVAL;
			if (nthreads[i] < 0)
				goto out_free;
		}
		rv = nfsd_set_nrthreads(i, nthreads);
		if (rv)
			goto out_free;
	}

	rv = nfsd_get_nrthreads(npools, nthreads);
	if (rv)
		goto out_free;

	mesg = buf;
	size = SIMPLE_TRANSACTION_LIMIT;
	for (i = 0; i < npools && size > 0; i++) {
		snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
		len = strlen(mesg);
		size -= len;
		mesg += len;
	}
	rv = mesg - buf;
out_free:
	kfree(nthreads);
	mutex_unlock(&nfsd_mutex);
	return rv;
}
Пример #24
0
int main(int argc, char *argv[])
{
    int sockfd = 0, n = 0;
    struct sockaddr_in serv_addr; 
    int counter = 0;

    if(argc < 4)
    {
        printf("\n Usage: %s <ip of server> \n",argv[0]);
        return 1;
    } 

    if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        printf("\n Error : Could not create socket \n");
        return 1;
    } 

    memset(&serv_addr, '0', sizeof(serv_addr)); 

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons((uint32_t)atoi(argv[2])); 

    if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0)
    {
        printf("\n inet_pton error occured\n");
        return 1;
    } 

    if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    {
       printf("\n Error : Connect Failed \n");
       return 1;
    } else {
        /*int i;
        for(i=0;i<5;i++)
        {
            pthread_t tid;
            pthread_create(&tid,NULL,send_info,NULL);
        }*/
        uint8_t buffer[65536];
        memset(buffer,0,65536);
        switch (atoi(argv[3]))
        {
            case 0:
                {
                    uint32_t info[4] = {FUNID_SDF_GETDEVICEINFO,0,0,0};
                    int result = send(sockfd, info, sizeof(uint32_t)*4,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        struct DeviceInfo_st info;
                        memcpy(&info,buffer+4*5,sizeof(info));
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        printf("recv success!info=%s,%s,%s,%u,%u,%u,%u,%u,%u,%u\n",info.IssuerName,info.DeviceName,info.DeviceSerial,
                          info.DeviceVersion,info.StandardVersion,info.AsymAlgAbility[0],info.AsymAlgAbility[1],info.SymAlgAbility,info.HashAlgAbility,info.BufferSize);
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 1:
                {
                    unsigned char ins[16] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
                    unsigned char keys[16] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
                    int a;
                    for(a =0; a<16;a++)
                    {
                        printf("%2X",ins[a]);
                    }
                    printf("\n");
                    for(a =0; a<16;a++)
                    {
                        printf("%2X",keys[a]);
                    }
                    printf("\n");

                    memset(buffer,0,65536);
                    uint32_t info[4] = {FUNID_SDF_ENCRYPT,68,2,0};
                    memcpy(buffer,info,16);
                    int key=110,key_s = 4;
                    memcpy(buffer+16,&key_s,4);
                    memcpy(buffer+20,&key,4);
                    int algid=119,algid_s = 4;
                    memcpy(buffer+24,&algid_s,4);
                    memcpy(buffer+28,&algid,4);
                    int puciv=114,puc_s = 4;
                    memcpy(buffer+32,&puc_s,4);
                    memcpy(buffer+36,&puciv,4);
                    int in_size = 16;
                    memcpy(buffer+40,&in_size,4);
                    memcpy(buffer+44,ins,16);
                    memcpy(buffer+60,&key_s,4);
                    memcpy(buffer+64,&in_size,4);
                    int result = send(sockfd, buffer, 68,0); 
                    printf("%d send result=%d,errno=%d buffer size:%d,%d\n%s\n",sockfd,result,errno,*(buffer+16),*(buffer+36),buffer);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        int n = recv(sockfd,buffer,65536,0); 
                        uint32_t *tmp = (uint32_t *)buffer;
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        int out_size = *(tmp+4);
                        printf("outsize=%d\n",out_size);
                        int i ;
                        for(i =20; i<20+16;i++)
                        {
                            printf("%2X",buffer[i]);
                        }
                        printf("\n");

                        break;
                    }
                    memset(buffer,0,65536);

                }
                break;
            case 2:
                {
                    unsigned char ins[16] = {0x68,0x1e,0xdf,0x34,0xd2,0x06,0x96,0x5e,0x86,0xb3,0xe9,0x4f,0x53,0x6e,0x42,0x46};
                    unsigned char keys[16] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
                    int a;
                    for(a =0; a<16;a++)
                    {
                        printf("%2X",ins[a]);
                    }
                    printf("\n");
                    for(a =0; a<16;a++)
                    {
                        printf("%2X",keys[a]);
                    }
                    printf("\n");

                    memset(buffer,0,65536);
                    uint32_t info[4] = {FUNID_SDF_DECRYPT,68,2,0};
                    memcpy(buffer,info,16);
                    int key=110,key_s = 4;
                    memcpy(buffer+16,&key_s,4);
                    memcpy(buffer+20,&key,4);
                    int algid=119,algid_s = 4;
                    memcpy(buffer+24,&algid_s,4);
                    memcpy(buffer+28,&algid,4);
                    int puciv=114,puc_s = 4;
                    memcpy(buffer+32,&puc_s,4);
                    memcpy(buffer+36,&puciv,4);
                    int in_size = 16;
                    memcpy(buffer+40,&in_size,4);
                    memcpy(buffer+44,ins,16);
                    memcpy(buffer+60,&key_s,4);
                    memcpy(buffer+64,&in_size,4);
                    int result = send(sockfd, buffer, 68,0); 
                    printf("%d send result=%d,errno=%d buffer size:%d,%d\n",sockfd,result,errno,*(buffer+16),*(buffer+36));
                    memset(buffer,0,65536);
                    while(1)
                    {
                        int n = recv(sockfd,buffer,65536,0); 
                        uint32_t *tmp = (uint32_t *)buffer;
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        int out_size = *(tmp+4);
                        printf("outsize=%d\n",out_size);
                        int i ;
                        for(i =20; i<20+16;i++)
                        {
                            printf("%2X",buffer[i]);
                        }
                        printf("\n");

                        break;
                    }
                    memset(buffer,0,65536);
                }
                break;
            case 3:
                {
                    uint32_t info[4] = {FUNID_SDF_GETPRIVATEKEYACCESSRIGHT,sizeof(uint32_t)*5+8,3,0};
                    memcpy(buffer,info,sizeof(uint32_t)*4);
                    uint32_t params[2] = {4,10};
                    memcpy(buffer+16,params,sizeof(uint32_t)*2);
                    uint32_t pwd_len = 8;
                    memcpy(buffer+16+8,&pwd_len,sizeof(uint32_t));
                    uint8_t pwd[8] = "12345678";
                    memcpy(buffer+24+4,pwd,pwd_len);
                    uint32_t len[2] = {4,8};
                    memcpy(buffer+36,len,sizeof(uint32_t)*2);
                    int result = send(sockfd, buffer, 44,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 4:
                {
                    uint32_t info[4] = {FUNID_SDF_RELEASEPRIVATEKEYACCESSRIGHT,sizeof(uint32_t)*2,1,0};
                    memcpy(buffer,info,sizeof(uint32_t)*4);
                    uint32_t params[2] = {4,10};
                    memcpy(buffer+16,params,sizeof(uint32_t)*2);
                    int result = send(sockfd, buffer, sizeof(uint32_t)*24,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        break;
                    }
                    memset(buffer,0,65536);
                }
                break;
            case 5:
                {
                    uint32_t info[4] = {FUNID_SDF_EXPORTENCPUBLICKEY_ECC,sizeof(uint32_t)*2,1,0};
                    memcpy(buffer,info,sizeof(uint32_t)*4);
                    uint32_t params[2] = {4,10};
                    memcpy(buffer+16,params,sizeof(uint32_t)*2);
                    int result = send(sockfd, buffer, sizeof(uint32_t)*24,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        ECCrefPublicKey key;
                        memcpy(&key,buffer+20,sizeof(ECCrefPublicKey));

                        printf("keyinfo start:\n");
                        int i;
                        for(i=0;i<32;i++)
                        {
                            printf("%02x",key.x[i]); 
                        }
                        printf("\n");
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 6:
                {
                    uint32_t info[4] = {FUNID_SDF_EXPORTSIGNPUBLICKEY_ECC,sizeof(uint32_t)*2,1,0};
                    memcpy(buffer,info,sizeof(uint32_t)*4);
                    uint32_t params[2] = {4,10};
                    memcpy(buffer+16,params,sizeof(uint32_t)*2);
                    int result = send(sockfd, buffer, sizeof(uint32_t)*24,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        
                        ECCrefPublicKey key;
                        memcpy(&key,buffer+20,sizeof(ECCrefPublicKey));

                        printf("keyinfo start:\n");
                        int i;
                        for(i=0;i<32;i++)
                        {
                            printf("%02x",key.x[i]); 
                        }
                        printf("\n");
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 7:
                {
                    uint8_t session_key[32]={12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12};
                    uint32_t info[4] = {FUNID_SDF_IMPORTKEY,sizeof(uint32_t)*3+32,2,0};
                    memcpy(buffer,info,sizeof(uint32_t)*4);
                    uint32_t session_len = 32;
                    memcpy(buffer+16,&session_len,sizeof(uint32_t));
                    memcpy(buffer+20,session_key,32);
                    uint32_t session_len_len = 4;
                    memcpy(buffer+52,&session_len_len, sizeof(uint32_t));
                    memcpy(buffer+56,&session_len, sizeof(uint32_t));

                    int result = send(sockfd, buffer, 60,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        
                        uint64_t *tmp64 = (uint64_t *)(buffer+20);

                        handle = *tmp64;
                        printf("import ok handle=%0lu\n",handle);
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 8:
                {
                    uint32_t info[4] = {FUNID_SDF_DESTORYKEY,sizeof(uint32_t)*3+32,2,0};
                    memcpy(buffer,info,sizeof(uint32_t)*4);
                    uint32_t handle_len = 4;
                    memcpy(buffer+16,&handle_len,sizeof(uint32_t));
                    handle = atol(argv[4]);
                    memcpy(buffer+20,&handle,sizeof(uint64_t));

                    int result = send(sockfd, buffer, 28,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 9:
                {
                    uint8_t data[15]= "123456789123456";
                    uint8_t *tmp = buffer+16;
                    int total = 0;
                    int count = 0;
                    uint32_t length = 15;
                    total += set_data(&tmp,data,length);
                    count++;
                    total += set_int(&tmp,length);
                    count++;
                    uint32_t file_size = 20;
                    total += set_int(&tmp,file_size);
                    count++;
                    HEADER header;
                    header.func_id = FUNID_SDF_CREATEFILE;
                    header.data_size = total;
                    header.param_sum = count;
                    header.reserved = 0;
                    uint8_t *tb = buffer;
                    total += set_header(&tb,header);
                    uint32_t *tmp3 = (uint32_t *)buffer;
                    printf("buffer:%u,%s\n",tmp3[4],buffer+20);
                    uint32_t *tmp4 = (uint32_t *)(buffer+35);
                    printf("buffer:%u,%u\n",tmp4[0],tmp4[1],tmp4[2],tmp4[3]);
                    uint32_t *tmp2 = (uint32_t *)buffer;
                    printf("header send=:%u,%u,%u,%u,%u;\n",tmp2[0],tmp2[1],tmp2[2],tmp2[3],tmp2[4]);
                    uint8_t data2[16];
                    memcpy(data2,buffer+20,15);
                    data2[15] = '\0';
                    printf("name:%s",data2);
                    int result = send(sockfd, buffer, total,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 10:
                {
                    uint8_t data[15]= "123456789123456";
                    uint8_t *tmp = buffer+16;
                    int total = 0;
                    int count = 0;
                    total += set_data(&tmp,data,15);
                    count++;
                    uint32_t length = 15;
                    total += set_int(&tmp,length);
                    count++;
                    /*int file_size = 20;
                    total += set_int(&tmp,&file_size);
                    count++;*/
                    HEADER header;
                    header.func_id = FUNID_SDF_DELETEFILE;
                    header.data_size = total;
                    header.param_sum = count;
                    header.reserved = 0;
                    uint8_t *tb = buffer;
                    total += set_header(&tb,header);
                    int result = send(sockfd, buffer, total,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        
                        break;
                    }
                    memset(buffer,0,65536);
                
                }
                break;
            case 11:
                {
                    uint8_t data[15]= "123456789123456";
                    uint8_t *tmp = buffer+16;
                    int total = 0;
                    int count = 0;
                    total += set_data(&tmp,data,15);
                    count++;
                    uint32_t length = 15;
                    total += set_int(&tmp,length);
                    count++;
                    uint32_t offset = 40;
                    total += set_int(&tmp,offset);
                    count++;
                    uint32_t file_size = 20;
                    total += set_int(&tmp,file_size);
                    count++;
                    uint8_t data2[20] = "abcdefghijklmnopqrst";
                    total += set_data(&tmp,data2,20);
                    count++;
                    HEADER header;
                    header.func_id = FUNID_SDF_WRITEFILE;
                    header.data_size = total;
                    header.param_sum = count;
                    header.reserved = 0;
                    uint8_t *tb = buffer;
                    total += set_header(&tb,header);
                    int result = send(sockfd, buffer, total,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        
                        break;
                    }
                    memset(buffer,0,65536);
                }
                break;
            case 12:
                {
                    uint8_t data[15]= "123456789123456";
                    uint8_t *tmp = buffer+16;
                    int total = 0;
                    int count = 0;
                    total += set_data(&tmp,data,15);
                    count++;
                    uint32_t length = 15;
                    total += set_int(&tmp,length);
                    count++;
                    uint32_t offset = 40;
                    total += set_int(&tmp,offset);
                    count++;
                    uint32_t file_size = 20;
                    total += set_int(&tmp,file_size);
                    count++;
                    HEADER header;
                    header.func_id = FUNID_SDF_READFILE;
                    header.data_size = total;
                    header.param_sum = count;
                    header.reserved = 0;
                    uint8_t *tb = buffer;
                    total += set_header(&tb,header);
                    int result = send(sockfd, buffer, total,0); 
                    printf("%d send result=%d,errno=%d\n",sockfd,result,errno);
                    memset(buffer,0,65536);
                    while(1)
                    {
                        uint32_t *tmp = (uint32_t *)buffer;
                        int n = recv(sockfd,buffer,65536,0); 
                        printf("recv success!recev=%d;header:%u,%u,%u,%u;\n",n,tmp[0],tmp[1],tmp[2],tmp[3]);
                        HEADER head;
                        get_header(&head,&buffer);
                        int len = get_int(&buffer);
                        uint8_t tm_buffer[BUFFER_MAX];
                        int read = get_data(&buffer,tm_buffer);
                        printf("read:\n"); 
                        int i = 0;
                        while(i<BUFFER_MAX)
                        {
                            printf("%c",tm_buffer[i]); 
                        }
                        printf("\n");
                        break;
                    }
                    memset(buffer,0,65536);
                }
                break;
            default:
                break;
        }
    }

    return 0;
}
Пример #25
0
int
main(int argc, char *argv[])
{
#define TEST_FILE "attributes.in"
	const char *in_file = FREETDS_SRCDIR "/" TEST_FILE;
	FILE *f;
	char buf[256];
	SQLINTEGER i;
	SQLLEN len;
	get_attr_t get_attr_p = get_attr_stmt;

	odbc_connect();
	/* TODO find another way */
	odbc_check_cursor();
	odbc_command("SET TEXTSIZE 4096");

	SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len);

	f = fopen(in_file, "r");
	if (!f)
		f = fopen(TEST_FILE, "r");
	if (!f) {
		fprintf(stderr, "error opening test file\n");
		exit(1);
	}

	line_num = 0;
	while (fgets(buf, sizeof(buf), f)) {
		char *p = buf, *cmd;

		++line_num;

		while (isspace((unsigned char) *p))
			++p;
		cmd = strtok(p, SEP);

		/* skip comments */
		if (!cmd || cmd[0] == '#' || cmd[0] == 0 || cmd[0] == '\n')
			continue;

		if (strcmp(cmd, "odbc") == 0) {
			int odbc3 = get_int(strtok(NULL, SEP)) == 3 ? 1 : 0;

			if (odbc_use_version3 != odbc3) {
				odbc_use_version3 = odbc3;
				odbc_disconnect();
				odbc_connect();
				odbc_command("SET TEXTSIZE 4096");
				SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len);
			}
			continue;
		}

		/* set attribute */
		if (strcmp(cmd, "set") == 0) {
			const struct attribute *attr = lookup_attr(strtok(NULL, SEP));
			char *value = strtok(NULL, SEP);
			SQLRETURN ret;

			if (!value)
				fatal("Line %u: value not defined\n", line_num);

			ret = SQL_ERROR;
			switch (attr->type) {
			case type_UINTEGER:
			case type_INTEGER:
				ret = SQLSetStmtAttr(odbc_stmt, attr->value, int2ptr(lookup(value, attr->lookup)),
						      sizeof(SQLINTEGER));
				break;
			case type_SMALLINT:
				ret = SQLSetStmtAttr(odbc_stmt, attr->value, int2ptr(lookup(value, attr->lookup)),
						      sizeof(SQLSMALLINT));
				break;
			case type_LEN:
				ret = SQLSetStmtAttr(odbc_stmt, attr->value, int2ptr(lookup(value, attr->lookup)),
						      sizeof(SQLLEN));
				break;
			case type_CHARP:
				ret = SQLSetStmtAttr(odbc_stmt, attr->value, (SQLPOINTER) value, SQL_NTS);
				break;
			case type_VOIDP:
			case type_DESC:
				fatal("Line %u: not implemented\n");
			}
			if (!SQL_SUCCEEDED(ret))
				fatal("Line %u: failure not expected setting statement attribute\n", line_num);
			get_attr_p = get_attr_stmt;
			continue;
		}

		/* test attribute */
		if (strcmp(cmd, "attr") == 0) {
			const struct attribute *attr = lookup_attr(strtok(NULL, SEP));
			char *value = strtok(NULL, SEP);
			int i, expected = lookup(value, attr->lookup);

			if (!value)
				fatal("Line %u: value not defined\n", line_num);

			i = get_attr_p(attr, expected);
			if (i != expected) {
				g_result = 1;
				fprintf(stderr, "Line %u: invalid %s got %d(%s) expected %s\n", line_num, attr->name, i, unlookup(i, attr->lookup), value);
			}
			continue;
		}

		if (strcmp(cmd, "reset") == 0) {
			odbc_reset_statement();
			continue;
		}

		fatal("Line %u: command '%s' not handled\n", line_num, cmd);
	}

	fclose(f);
	odbc_disconnect();

	printf("Done.\n");
	return g_result;
}
Пример #26
0
Файл: main.c Проект: mir-ror/moc
/* Send commands requested in params to the server. */
static void server_command (struct parameters *params, lists_t_strs *args)
{
	int sock;

	if ((sock = server_connect()) == -1)
		fatal ("The server is not running!");

	xsignal (SIGPIPE, SIG_IGN);
	if (!ping_server (sock))
		fatal ("Can't connect to the server!");

	if (params->playit)
		interface_cmdline_playit (sock, args);
	if (params->clear)
		interface_cmdline_clear_plist (sock);
	if (params->append)
		interface_cmdline_append (sock, args);
	if (params->enqueue)
		interface_cmdline_enqueue (sock, args);
	if (params->play)
		interface_cmdline_play_first (sock);
	if (params->get_file_info)
		interface_cmdline_file_info (sock);
	if (params->seek_by)
		interface_cmdline_seek_by (sock, params->seek_by);
	if (params->jump_type=='%')
		interface_cmdline_jump_to_percent (sock,params->jump_to);
	if (params->jump_type=='s')
		interface_cmdline_jump_to (sock,params->jump_to);
	if (params->get_formatted_info)
		interface_cmdline_formatted_info (sock, params->formatted_info_param);
	if (params->adj_volume)
		interface_cmdline_adj_volume (sock, params->adj_volume);
	if (params->toggle)
		interface_cmdline_set (sock, params->toggle, 2);
	if (params->on)
		interface_cmdline_set (sock, params->on, 1);
	if (params->off)
		interface_cmdline_set (sock, params->off, 0);
	if (params->exit) {
		if (!send_int(sock, CMD_QUIT))
			fatal ("Can't send command!");
	}
	else if (params->stop) {
		if (!send_int(sock, CMD_STOP) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->pause) {
		if (!send_int(sock, CMD_PAUSE) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->next) {
		if (!send_int(sock, CMD_NEXT) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->previous) {
		if (!send_int(sock, CMD_PREV) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->unpause) {
		if (!send_int(sock, CMD_UNPAUSE) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->toggle_pause) {
		int state, ev, cmd = -1;

		if (!send_int(sock, CMD_GET_STATE))
			fatal ("Can't send commands!");
		if (!get_int(sock, &ev) || ev != EV_DATA || !get_int(sock, &state))
			fatal ("Can't get data from the server!");

		if (state == STATE_PAUSE)
			cmd = CMD_UNPAUSE;
		else if (state == STATE_PLAY)
			cmd = CMD_PAUSE;

		if (cmd != -1 && !send_int(sock, cmd))
			fatal ("Can't send commands!");
		if (!send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}

	close (sock);
}
Пример #27
0
int InitParser::get_int(const string& section, const string& key) const
{
	return get_int((section+":"+key).c_str());
}
Пример #28
0
int main(void) {
    printf("Input Shower Minutes:");
    int minutes = get_int();
    printf("Minutes: %i\n", minutes);
    printf("Bottles: %i\n", minutes * 12);
}
Пример #29
0
// Combine the phase1 and phase2 files into a new manifest.
int backup_phase3_server_all(struct sdirs *sdirs, struct conf **confs)
{
	int ret=-1;
	int pcmp=0;
	struct blk *blk=NULL;
	struct sbuf *usb=NULL;
	struct sbuf *csb=NULL;
	char *manifesttmp=NULL;
	struct manio *newmanio=NULL;
	struct manio *chmanio=NULL;
	struct manio *unmanio=NULL;
	enum protocol protocol=get_protocol(confs);
	struct cntr *cntr=get_cntr(confs);
	const char *rmanifest_relative=NULL;

	logp("Begin phase3 (merge manifests)\n");

	if(protocol==PROTO_2)
		rmanifest_relative=get_rmanifest_relative(sdirs, confs);

	if(!(manifesttmp=get_tmp_filename(sdirs->manifest))
	  || !(newmanio=manio_open_phase3(manifesttmp,
		comp_level(get_int(confs[OPT_COMPRESSION])),
		protocol, rmanifest_relative))
	  || !(chmanio=manio_open_phase2(sdirs->changed, "rb", protocol))
	  || !(unmanio=manio_open_phase2(sdirs->unchanged, "rb", protocol))
	  || !(usb=sbuf_alloc(protocol))
	  || !(csb=sbuf_alloc(protocol)))
		goto end;

	while(chmanio || unmanio)
	{
		if(!blk && !(blk=blk_alloc())) goto end;

		if(unmanio
		  && !usb->path.buf)
		{
			switch(manio_read(unmanio, usb))
			{
				case -1: goto end;
				case 1: manio_close(&unmanio);
			}
		}

		if(chmanio
		  && !csb->path.buf)
		{
			switch(manio_read(chmanio, csb))
			{
				case -1: goto end;
				case 1: manio_close(&chmanio);
			}
		}

		if(usb->path.buf && !csb->path.buf)
		{
			if(write_status(CNTR_STATUS_MERGING,
				usb->path.buf, cntr)) goto end;
			switch(manio_copy_entry(
				usb, usb, &blk, unmanio, newmanio))
			{
				case -1: goto end;
				case 1: manio_close(&unmanio);
			}
		}
		else if(!usb->path.buf && csb->path.buf)
		{
			if(write_status(CNTR_STATUS_MERGING,
				csb->path.buf, cntr)) goto end;
			switch(manio_copy_entry(
				csb, csb, &blk, chmanio, newmanio))
			{
				case -1: goto end;
				case 1: manio_close(&chmanio);
			}
		}
		else if(!usb->path.buf && !csb->path.buf)
		{
			continue;
		}
		else if(!(pcmp=sbuf_pathcmp(usb, csb)))
		{
			// They were the same - write one.
			if(write_status(CNTR_STATUS_MERGING,
				csb->path.buf, cntr)) goto end;
			switch(manio_copy_entry(
				csb, csb, &blk, chmanio, newmanio))
			{
				case -1: goto end;
				case 1: manio_close(&chmanio);
			}
		}
		else if(pcmp<0)
		{
			if(write_status(CNTR_STATUS_MERGING,
				usb->path.buf, cntr)) goto end;
			switch(manio_copy_entry(
				usb, usb, &blk, unmanio, newmanio))
			{
				case -1: goto end;
				case 1: manio_close(&unmanio);
			}
		}
		else
		{
			if(write_status(CNTR_STATUS_MERGING,
				csb->path.buf, cntr)) goto end;
			switch(manio_copy_entry(
				csb, csb, &blk, chmanio, newmanio))
			{
				case -1: goto end;
				case 1: manio_close(&chmanio);
			}
		}
	}

	// Flush to disk.
	if(manio_close(&newmanio))
	{
		logp("error gzclosing %s in backup_phase3_server\n",
			manifesttmp);
		goto end;
	}

	// Rename race condition should be of no consequence here, as the
	// manifest should just get recreated automatically.
	if(do_rename(manifesttmp, sdirs->manifest))
		goto end;
	else
	{
		recursive_delete(sdirs->changed);
		recursive_delete(sdirs->unchanged);
	}

	logp("End phase3 (merge manifests)\n");
	ret=0;
end:
	manio_close(&newmanio);
	manio_close(&chmanio);
	manio_close(&unmanio);
	sbuf_free(&csb);
	sbuf_free(&usb);
	blk_free(&blk);
	free_w(&manifesttmp);
	return ret;
}
Пример #30
0
/*
 * Handle an async message. Put it on a queue; then leave it to
 * async_handler() to do the rest.
 */
void
async(int handle)
{
	struct rk_text_stat rts;
	struct mesg *m;
	int narg, type, tmp;

	narg = get_int();
	type = get_int();
	m = calloc(sizeof(struct mesg), 1);
	m->ra.ra_message = m->ra.ra_message2 = "";
	m->ra.ra_type = type;

	switch (type) {
	case 15: /* New text created */
		async_new_text(m);
		putinq(m);
		break;

	case 12: /* async-send-message */
		m->ra.ra_conf = get_int();
		m->ra.ra_pers = get_int();
		m->ra.ra_message = get_string();
		get_accept('\n');

		if (handle) { /* XXX - temporary */
			/* Get time for message from server */
			send_reply("35\n");
			read_in_time(&m->ra.ra_time);
			get_accept('\n');
		} else {
			/* XXX - get local time */
			struct tm *tm;
			time_t clock = time(NULL);
			tm = localtime(&clock);
			m->ra.ra_time.rt_seconds = tm->tm_sec;
			m->ra.ra_time.rt_minutes = tm->tm_min;
			m->ra.ra_time.rt_hours = tm->tm_hour;
			m->ra.ra_time.rt_day = tm->tm_mday;
			m->ra.ra_time.rt_month = tm->tm_mon;
			m->ra.ra_time.rt_year = tm->tm_year;
			m->ra.ra_time.rt_day_of_week = tm->tm_wday;
			m->ra.ra_time.rt_day_of_year = tm->tm_yday;
			m->ra.ra_time.rt_is_dst = tm->tm_isdst;
		}

		putinq(m);
		break;

	case 9: /* async-login */
	case 13: /* async-logout */
		m->ra.ra_pers = get_int();
		m->ra.ra_conf = get_int();
		get_accept('\n');
		putinq(m);
		break;

	case 5: /* async-new-name */
		tmp = m->ra.ra_pers = get_int();
		m->ra.ra_message = get_string();
		m->ra.ra_message2 = get_string();
		get_accept('\n');
		putinq(m);
		reread_conf_stat_bg(tmp);
		newname(tmp);
		break;

	case 16: /* async-new-recipient */
	case 17: /* async-sub-recipient */
		reread_text_stat_bg(get_int());
		reread_conf_stat_bg(get_int());
		get_int();
		get_accept('\n');
		free(m);
		break;

	case 8: /* async-leave-conf */
		m->ra.ra_conf = get_int();
		get_accept('\n');
		putinq(m);
		break;

	case 14: /* async-deleted-text */
		m->ra.ra_text = get_int();
		readin_textstat(&rts);
		invalidate_local(&rts);
		reread_text_stat_bg(m->ra.ra_text);
		putinq(m);
		break;

	case 18: /* async-new-membership */
		m->ra.ra_pers = get_int();
		m->ra.ra_conf = get_int();
		get_accept('\n');
		putinq(m);
		break;

	default:
		printf("BG: Unknown async %d\n", type);

	case 7:	/* Save database */
		get_eat('\n');
		free(m);
		return;
	}
	if (handle)
		async_collect();
}