Beispiel #1
0
static int parse_supertcp(struct ftpparse *f, char *p[], int l[], 
  unsigned int count)
{
  unsigned long mon;
  unsigned long day;
  unsigned long year;
  unsigned long hour;
  unsigned long min;
  unsigned long sec;
  int mtimetype;
  uint64 size=0; /* optional, dirs */
  int x;
  int dir=0;

/* CMT             <DIR>           11-21-94        10:17 */
/* DESIGN1.DOC          11264      05-11-95        14:20 */

  if (count<4) return 0;
  x=scan_time(p[3],l[3],&hour,&min,&sec,&mtimetype);
  if (x!=l[3]) return 0;


  x=get_ulong(p[2],l[2],&mon); 
  if (x!=2 || p[2][x]!='-') return 0;
  x++;
  x+=get_ulong(p[2]+x,l[2]-x,&day); 
  if (x!=5 || p[2][x]!='-') return 0;
  x++;
  x+=get_ulong(p[2]+x,l[2]-x,&year); 
  if ((x!=8  && x!=10) || p[2][x]!=' ') return 0;
  if (!fix_year(&year)) return 0;
  if (my_byte_equal(p[1],5,"<DIR>")) 
    dir=1;
  else {
    x=get_uint64(p[1],l[1],&size);
    if (!x || p[1][x]!=' ') return 0;
  }

  f->name=p[0];
  f->namelen=l[0];
  f->size=size;
  if (!dir)
    f->sizetype=FTPPARSE_SIZE_BINARY;
  utcdate2tai (&f->mtime,year,mon,day,hour,min,sec);
  f->mtimetype=mtimetype;
  if (dir) f->flagtrycwd=1;
  else     f->flagtryretr=1;
  return 1;
}
Beispiel #2
0
static int scan_time(const char *buf, const unsigned int len,
  unsigned long *h, unsigned long *m, unsigned long *s, int *type)
{
/* 11:48:54 */
/* 01:48:54 */
/*  1:48:54 */
/* 11:48 */
/* 11:48PM */
/* 11:48AM */
/* 11:48:54PM */
/* 11:48:54AM */
  unsigned int x;
  unsigned int y;
  *h=*m=*s=0;

  x=get_ulong(buf,len,h);
  if (len==x) return 0;
  if (!x || x>2) return 0;

  if (':' != buf[x]) return 0;
  if (len==++x) return 0;

  y=get_ulong(buf+x,len-x,m);
  if (y!=2) return 0;
  x+=y;

  if (x!=len && ':' == buf[x]) {
    if (len==++x) return 0;

    y=get_ulong(buf+x,len-x,s);
    if (y!=2) return 0;
    x+=y;
    *type=FTPPARSE_MTIME_REMOTESECOND;
  } else
    *type=FTPPARSE_MTIME_REMOTEMINUTE;

  if (x!=len && ('A' == buf[x] || 'P' == buf[x])) {
    if ('P' == buf [x])
      *h+=12;
    x++;
    if (len==x) return 0;
    if ('M' != buf[x]) return 0;
    x++;
    if (len==x) return 0;
  }
  if (len==x || buf[x]==' ') return x;
  return 0;
}
Beispiel #3
0
static void
store_array(void)
{
	struct number *inumber;
	struct value *value;
	struct stack *stack;
	u_long idx;
	int reg;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		value = pop();
		if (value == NULL) {
			free_number(inumber);
			return;
		}
		idx = get_ulong(inumber);
		if (BN_is_negative(inumber->number)) {
			warnx("negative idx");
			stack_free_value(value);
		} else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX) {
			warnx("idx too big");
			stack_free_value(value);
		} else {
			stack = &bmachine.reg[reg];
			frame_assign(stack, idx, value);
		}
		free_number(inumber);
	}
}
Beispiel #4
0
static void
load_array(void)
{
	struct number *inumber, *n;
	struct stack *stack;
	struct value *v;
	struct value copy;
	u_long idx;
	int reg;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		idx = get_ulong(inumber);
		if (BN_is_negative(inumber->number))
			warnx("negative idx");
		else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX)
			warnx("idx too big");
		else {
			stack = &bmachine.reg[reg];
			v = frame_retrieve(stack, idx);
			if (v == NULL || v->type == BCODE_NONE) {
				n = new_number();
				bn_check(BN_zero(n->number));
				push_number(n);
			}
			else
				push(stack_dup_value(v, &copy));
		}
		free_number(inumber);
	}
}
Beispiel #5
0
static void
store_array(void)
{
	int			reg;
	struct number		*inumber;
	u_long			index;
	struct value		*value;
	struct stack		*stack;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		value = pop();
		if (value == NULL) {
			free_number(inumber);
			return;
		}
		index = get_ulong(inumber);
		if (BN_cmp(inumber->number, &zero) < 0) {
			warnx("negative index");
			stack_free_value(value);
		} else if (index == BN_MASK2 || index > MAX_ARRAY_INDEX) {
			warnx("index too big");
			stack_free_value(value);
		} else {
			stack = &bmachine.reg[reg];
			frame_assign(stack, index, value);
		}
		free_number(inumber);
	}
}
Beispiel #6
0
static void
load_array(void)
{
	int			reg;
	struct number		*inumber, *n;
	u_long			index;
	struct stack		*stack;
	struct value		*v, copy;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		index = get_ulong(inumber);
		if (BN_cmp(inumber->number, &zero) < 0)
			warnx("negative index");
		else if (index == BN_MASK2 || index > MAX_ARRAY_INDEX)
			warnx("index too big");
		else {
			stack = &bmachine.reg[reg];
			v = frame_retrieve(stack, index);
			if (v == NULL) {
				n = new_number();
				bn_check(BN_zero(n->number));
				push_number(n);
			}
			else
				push(stack_dup_value(v, &copy));
		}
		free_number(inumber);
	}
}
static int
np_ulong(char *p, PyObject *v, const formatdef *f)
{
	unsigned long x;
	if (get_ulong(v, &x) < 0)
		return -1;
	memcpy(p, (char *)&x, sizeof x);
	return 0;
}
Beispiel #8
0
static PyObject *
B_set(void *ptr, PyObject *value, Py_ssize_t size)
{
    unsigned long val;
    if (get_ulong(value, &val) < 0)
        return NULL;
    *(unsigned char *)ptr = SET(unsigned char, *(unsigned char*)ptr, val, size);
    _RET(value);
}
static int
np_uint(char *p, PyObject *v, const formatdef *f)
{
	unsigned long x;
	unsigned int y;
	if (get_ulong(v, &x) < 0)
		return -1;
	y = (unsigned int)x;
	memcpy(p, (char *)&y, sizeof y);
	return 0;
}
Beispiel #10
0
Boolean
CDR::skip_string ()			// ISO/1 or octet string
{
  ULong	len = get_ulong ();

  if ( len > remaining)
    return CDR_FALSE;		// buffer's changed

  next += (unsigned) len;
  remaining -= (unsigned) len;
  return CDR_TRUE;
}
Beispiel #11
0
static PyObject *
L_set(void *ptr, PyObject *value, Py_ssize_t size)
{
    unsigned long val;
    unsigned long x;
    if (get_ulong(value, &val) < 0)
        return  NULL;
    memcpy(&x, ptr, sizeof(x));
    x = SET(x, val, size);
    memcpy(ptr, &x, sizeof(x));
    _RET(value);
}
Beispiel #12
0
static PyObject *
I_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{
    unsigned long val;
    unsigned int field;
    if (get_ulong(value, &val) < 0)
        return  NULL;
    memcpy(&field, ptr, sizeof(field));
    field = (unsigned int)SET(field, (unsigned int)val, size);
    field = SWAP_INT(field);
    memcpy(ptr, &field, sizeof(field));
    _RET(value);
}
static int
lp_uint(char *p, PyObject *v, const formatdef *f)
{
	unsigned long x;
	int i;
	if (get_ulong(v, &x) < 0)
		return -1;
	i = f->size;
	do {
		*p++ = (char)x;
		x >>= 8;
	} while (--i > 0);
	return 0;
}
Beispiel #14
0
static PyObject *
L_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{
    unsigned long val;
    unsigned long field;
    if (get_ulong(value, &val) < 0)
        return  NULL;
    memcpy(&field, ptr, sizeof(field));
    field = SWAP_LONG(field);
    field = SET(unsigned long, field, val, size);
    field = SWAP_LONG(field);
    memcpy(ptr, &field, sizeof(field));
    _RET(value);
}
Beispiel #15
0
static int process_frame(unsigned char *pwork, int nchunks, int verbose)
{
  unsigned char *pmchunk;
  unsigned long chunk_size;
  int i, chunk_type;

  for (i=0; i< nchunks; i++)
    {
      chunk_size = get_ulong(&pwork[0]);
      chunk_type = get_ushort(&pwork[4]);

      pmchunk = pwork + CHUNK_HEAD_SIZE;
      if (verbose)
	fprintf(stdout,"chunk %d of type 0x%X and size %ld\n",
		i,chunk_type,chunk_size);

      if (chunk_type == FLI_COLOR)
	{
	  table_colors(pmchunk, COLOR_FLAG_64);
	}
      else if (chunk_type == FLI_256_COLOR)
	{
	  table_colors(pmchunk, COLOR_FLAG_256);
	}
      else if (chunk_type == FLI_DELTA)
	{
	  buffer_delta_chunk(pmchunk, image_buffer, 
			     image_height, image_width);
	}
      else if (chunk_type == FLI_LC)
	{
	  buffer_lc_chunk(pmchunk, image_buffer,
			  image_height, image_width);
	}
      else if (chunk_type == FLI_BRUN)
	{
	  buffer_brun_chunk(pmchunk, image_buffer,
			    image_height, image_width);
	}
      else
	{
	  fprintf(stderr,"unknown chunk type 0x%X -- chunk ignored\n",
		  chunk_type);
	}
      pwork += chunk_size;
    }

  return(1);
}
Beispiel #16
0
static int
np_uint(char *p, PyObject *v, const formatdef *f)
{
	unsigned long x;
	unsigned int y;
	if (get_ulong(v, &x) < 0)
		return -1;
	y = (unsigned int)x;
#if (SIZEOF_LONG > SIZEOF_INT)
	if (x > ((unsigned long)UINT_MAX))
		RANGE_ERROR(y, f, 1, -1);
#endif
	memcpy(p, (char *)&y, sizeof y);
	return 0;
}
Beispiel #17
0
static void
set_obase(void)
{
	struct number	*n;
	u_long		base;

	n = pop_number();
	if (n != NULL) {
		base = get_ulong(n);
		if (base != BN_MASK2 && base > 1)
			bmachine.obase = base;
		else
			warnx("output base must be a number greater than 1");
		free_number(n);
	}
}
Beispiel #18
0
static value op_limit(value f, void op(unsigned long))
	{
	if (!f->L) return 0;
	{
	value x = arg(f->R);
	if (x->T == type_num)
		{
		op(get_ulong(x));
		f = hold(QI);
		}
	else
		f = hold(Qvoid);
	drop(x);
	return f;
	}
	}
Beispiel #19
0
static void
set_obase(void)
{
	struct number *n;
	u_long base;

	n = pop_number();
	if (n != NULL) {
		base = get_ulong(n);
		if (base != ULONG_MAX && base > 1 && base <= UINT_MAX)
			bmachine.obase = (u_int)base;
		else
			warnx("output base must be a number greater than 1");
		free_number(n);
	}
}
Beispiel #20
0
static void
set_ibase(void)
{
	struct number *n;
	u_long base;

	n = pop_number();
	if (n != NULL) {
		base = get_ulong(n);
		if (base != ULONG_MAX && 2 <= base && base <= 16)
			bmachine.ibase = (u_int)base;
		else
			warnx("input base must be a number between 2 and 16 "
			    "(inclusive)");
		free_number(n);
	}
}
Beispiel #21
0
/* see http://cr.yp.to/ftp/list/eplf.html */
static int 
parse_eplf(struct ftpparse *f, char *buf, unsigned int len)
{
  unsigned int start,pos;
  unsigned long ul;
  if (buf[0]!='+') return 0;

  start=1;
  for (pos = 1;pos < len;pos++) {
    if ('\t'==buf[pos]) {
      f->name=buf+pos+1;
      f->namelen=len-pos-1;
      if (!f->namelen) return 0; /* huh? */
      f->format=FTPPARSE_FORMAT_EPLF;
      return 1;
    }
    if (',' != buf[pos])
      continue;
    switch(buf[start]) {
    case '/': f->flagtrycwd=1; break;
    case 'r': f->flagtryretr=1; break;
    case 's': 
      if (pos-start-1==0) return 0;
      if (get_uint64(buf+start+1,pos-start-1,&f->size)
	  !=pos-start-1) return 0;
      f->sizetype=FTPPARSE_SIZE_BINARY;
      break;
    case 'm':
      if (pos-start-1==0) return 0;
      if (get_ulong(buf+start+1,pos-start-1,&ul)!=pos-start-1) return 0;
      tai_unix(&f->mtime,ul);
      f->mtimetype = FTPPARSE_MTIME_LOCAL;
      break;
    case 'i':
      /* refuse zero bytes length ids */
      if (pos-start-1==0) return 0;
      f->idtype = FTPPARSE_ID_FULL;
      f->id=buf+start+1;
      f->idlen=pos-start-1;
      break;
    }
    start=pos+1;
  }
  return 0;
}
Beispiel #22
0
static void
set_scale(void)
{
	struct number	*n;
	u_long		scale;

	n = pop_number();
	if (n != NULL) {
		if (BN_cmp(n->number, &zero) < 0)
			warnx("scale must be a nonnegative number");
		else {
			scale = get_ulong(n);
			if (scale != BN_MASK2)
				bmachine.scale = scale;
			else
				warnx("scale too large");
			}
		free_number(n);
	}
}
Beispiel #23
0
static int
lp_uint(char *p, PyObject *v, const formatdef *f)
{
	unsigned long x;
	Py_ssize_t i;
	if (get_ulong(v, &x) < 0)
		return -1;
	i = f->size;
	if (i != SIZEOF_LONG) {
		unsigned long maxint = 1;
		maxint <<= (unsigned long)(i * 8);
		if (x >= maxint)
			RANGE_ERROR(x, f, 1, maxint - 1);
	}
	do {
		*p++ = (char)x;
		x >>= 8;
	} while (--i > 0);
	return 0;
}
Beispiel #24
0
static void
set_scale(void)
{
	struct number *n;
	u_long scale;

	n = pop_number();
	if (n != NULL) {
		if (BN_is_negative(n->number))
			warnx("scale must be a nonnegative number");
		else {
			scale = get_ulong(n);
			if (scale != ULONG_MAX && scale <= UINT_MAX)
				bmachine.scale = (u_int)scale;
			else
				warnx("scale too large");
			}
		free_number(n);
	}
}
Beispiel #25
0
static void
quitN(void)
{
	struct number	*n;
	u_long		i;

	n = pop_number();
	if (n == NULL)
		return;
	i = get_ulong(n);
	if (i == BN_MASK2 || i == 0)
		warnx("Q command requires a number >= 1");
	else if (bmachine.readsp < i)
		warnx("Q command argument exceeded string execution depth");
	else {
		while (i-- > 0) {
			src_free();
			bmachine.readsp--;
		}
	}
}
Beispiel #26
0
static void
skipN(void)
{
	struct number *n;
	u_long i;

	n = pop_number();
	if (n == NULL)
		return;
	i = get_ulong(n);
	if (i == ULONG_MAX)
		warnx("J command requires a number >= 0");
	else if (i > 0 && bmachine.readsp < i)
		warnx("J command argument exceeded string execution depth");
	else {
		while (i-- > 0) {
			src_free();
			bmachine.readsp--;
		}
		skip_until_mark();
	}
}
Beispiel #27
0
/* another bright re-invention of a broken wheel from the people, who
 * made an art of it.
 */
static int 
parse_os2(struct ftpparse *f, char *p[], int l[], 
  unsigned int count)
{
/*         0           DIR   04-11-95   16:26  ADDRESS
 *       612      A          07-28-95   16:45  air_tra1.bag
 *    310992                 06-28-94   09:56  INSTALL.EXE
 */
  unsigned long mon;
  unsigned long day;
  unsigned long year;
  unsigned long hour;
  unsigned long min;
  unsigned long sec;
  int mtimetype;
  uint64 size;
  int x;
  unsigned int i;
  int dir=0;
  if (count<4) return 0;

  x=get_uint64(p[0],l[0],&size);
  if (!x || p[0][x]!=' ') return 0;
  
  for (i=1; i<count-2; i++) {
    x=get_ulong(p[i],l[i],&mon);
    if (!x) continue;
    if (x!=2 || p[i][x]!='-') return 0;
    mon-=1;
    x++;
    x+=get_ulong(p[i]+x,l[i]-x,&day);
    if (x!=5 || p[i][x]!='-') return 0;
    x++;
    x+=get_ulong(p[i]+x,l[i]-x,&year);
    if (x!=8 || p[i][x]!=' ') return 0;
    if (!fix_year(&year)) return 0;
    break;
  }
  if (i>1)
    if (my_byte_equal(p[i-1],3,"DIR")) 
      dir=1;
  i++;

  if (i==count) return 0;
  x=scan_time(p[i],l[i],&hour,&min,&sec,&mtimetype);
  if (x!=l[i]) return 0;
  i++;
  if (i==count) return 0;

  f->name=p[i];
  f->namelen=l[i];
  if (dir) {
    f->flagtrycwd=1;
  } else {
    f->flagtryretr=1;
    f->sizetype=FTPPARSE_SIZE_BINARY;
    f->size=size;
  }
  utcdate2tai (&f->mtime,year,mon,day,hour,min,sec);
  f->mtimetype=mtimetype;
  return 1;
}
int
handle_gahp_command(char ** argv, int argc) {
	// Assume it's been verified

	if (strcasecmp (argv[0], GAHP_COMMAND_JOB_REMOVE)==0) {
		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createRemoveRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_HOLD)==0) {
		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createHoldRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;

	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_RELEASE)==0) {

		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createReleaseRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;

	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_STATUS_CONSTRAINED) ==0) {

		int req_id;

		if (!(argc == 4 &&
			get_int (argv[1], &req_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		char * constraint = argv[3];


		enqueue_command (
			SchedDRequest::createStatusConstrainedRequest(
				req_id,
				constraint));

		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_UPDATE_CONSTRAINED) ==0) {
		int req_id;
		ClassAd * classad;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_class_ad (argv[4], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		char * constraint = argv[3];

		enqueue_command (
			SchedDRequest::createUpdateConstrainedRequest(
				req_id,
				constraint,
				classad));

		delete classad;
		return TRUE;

	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_UPDATE) ==0) {

		int req_id;
		ClassAd * classad;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id) &&
			get_class_ad (argv[4], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		//char * constraint = argv[3];

		enqueue_command (
			SchedDRequest::createUpdateRequest(
				req_id,
				cluster_id,
				proc_id,
				classad));

		delete classad;
		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_SUBMIT) ==0) {
		int req_id;
		ClassAd * classad;

		if (!(argc == 4 &&
			get_int (argv[1], &req_id) &&
			get_class_ad (argv[3], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createSubmitRequest(
				req_id,
				classad));

		delete classad;
		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_UPDATE_LEASE) ==0) {
		int req_id;
		int num_jobs;

		if (!(argc >= 4 &&
			get_int (argv[1], &req_id) &&
			get_int (argv[3], &num_jobs))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		job_expiration * expirations = new job_expiration[num_jobs];
		int i;
		for (i=0; i<num_jobs; i++) {
			if (!get_job_id(argv[4+i*2], 
							&(expirations[i].cluster),
							&(expirations[i].proc))) {
				delete[] expirations;
				return FALSE;
			}

			if (!get_ulong (argv[4+i*2+1], &(expirations[i].expiration))) {
				delete [] expirations;
				return FALSE;
			}
		}	

		enqueue_command (
			SchedDRequest::createUpdateLeaseRequest(
													req_id,
													num_jobs,
													expirations));

		delete [] expirations;
		return TRUE;
	}  else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_STAGE_IN) ==0) {
		int req_id;
		ClassAd * classad;

		if (!(argc == 4 &&
			get_int (argv[1], &req_id) &&
			get_class_ad (argv[3], &classad))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createJobStageInRequest(
				req_id,
				classad));

		delete classad;
		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_STAGE_OUT) ==0) {
		int req_id;
		int cluster_id, proc_id;

		if (!(argc == 4 &&
			  get_int (argv[1], &req_id) &&
			  get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createJobStageOutRequest(
				req_id,
				cluster_id,
				proc_id));

		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_JOB_REFRESH_PROXY)==0) {
		int req_id = 0;
		int cluster_id, proc_id;

		if (!(argc == 5 &&
			get_int (argv[1], &req_id) &&
			get_job_id (argv[3], &cluster_id, &proc_id))) {

			dprintf (D_ALWAYS, "Invalid args to %s\n", argv[0]);
			return FALSE;
		}

		enqueue_command (
			SchedDRequest::createRefreshProxyRequest(
				req_id,
				cluster_id,
				proc_id,
				argv[4]));
		return TRUE;
	} else if (strcasecmp (argv[0], GAHP_COMMAND_INITIALIZE_FROM_FILE)==0) {
		static bool init_done = false;

		if ( init_done == false ) {
			SetEnv( "X509_USER_PROXY", argv[1] );
			UnsetEnv( "X509_USER_CERT" );
			UnsetEnv( "X509_USER_KEY" );
			proxySubjectName = x509_proxy_identity_name( argv[1] );
			if ( !proxySubjectName ) {
				dprintf( D_ALWAYS, "Failed to query certificate identity "
						 "from %s\n",  argv[1] );
				return TRUE;
			}
			Reconfig();
			init_done = true;
		}
		return TRUE;
	}

	dprintf (D_ALWAYS, "Invalid command %s\n", argv[0]);
	return FALSE;
}
Beispiel #29
0
bool valtostr(const value_t * val, char *str, size_t n)
{
    char buf[128];
    int max_bytes = 0;
    bool print_as_unsigned = false;

#define FLAG_MACRO(bytes, string) (val->flags.u##bytes##b && val->flags.s##bytes##b) ? (string " ") : (val->flags.u##bytes##b) ? (string "u ") : (val->flags.s##bytes##b) ? (string "s ") : ""

    /* set the flags */
    snprintf(buf, sizeof(buf), "[%s%s%s%s%s%s%s]",
             FLAG_MACRO(64, "I64"),
             FLAG_MACRO(32, "I32"),
             FLAG_MACRO(16, "I16"),
             FLAG_MACRO(8,  "I8"),
             val->flags.f64b ? "F64 " : "",
             val->flags.f32b ? "F32 " : "",
             (val->flags.ineq_reverse && !val->flags.ineq_forwards) ? "(reversed inequality) " : "");

    if (val->flags.u64b) {
        max_bytes = 8;
        print_as_unsigned =  true;
    }
    else if (val->flags.s64b) {
        max_bytes = 8;
        print_as_unsigned = false;
    }
    else if (val->flags.u32b) {
        max_bytes = 4;
        print_as_unsigned =  true;
    }
    else if (val->flags.s32b) {
        max_bytes = 4;
        print_as_unsigned = false;
    }
    else if (val->flags.u16b) {
        max_bytes = 2;
        print_as_unsigned =  true;
    }
    else if (val->flags.s16b) {
        max_bytes = 2;
        print_as_unsigned = false;
    }
    else if (val->flags.u8b ) {
        max_bytes = 1;
        print_as_unsigned =  true;
    }
    else if (val->flags.s8b ) {
        max_bytes = 1;
        print_as_unsigned = false;
    }

    /* find the right format, considering different integer size implementations */
    if (max_bytes == sizeof(long long)) snprintf(str, n, print_as_unsigned ? "%llu, %s" : "%lld, %s", print_as_unsigned ? get_ulonglong(val) : get_slonglong(val), buf);
    else if (max_bytes == sizeof(long))      snprintf(str, n, print_as_unsigned ? "%lu, %s"  : "%ld, %s" , print_as_unsigned ? get_ulong(val) : get_slong(val), buf);
    else if (max_bytes == sizeof(int))       snprintf(str, n, print_as_unsigned ? "%u, %s"   : "%d, %s"  , print_as_unsigned ? get_uint(val) : get_sint(val), buf);
    else if (max_bytes == sizeof(short))     snprintf(str, n, print_as_unsigned ? "%hu, %s"  : "%hd, %s" , print_as_unsigned ? get_ushort(val) : get_sshort(val), buf);
    else if (max_bytes == sizeof(char))      snprintf(str, n, print_as_unsigned ? "%hhu, %s" : "%hhd, %s", print_as_unsigned ? get_uchar(val) : get_schar(val), buf);
    else if (val->flags.f64b) snprintf(str, n, "%lf, %s", get_f64b(val), buf);
    else if (val->flags.f32b) snprintf(str, n, "%f, %s", get_f32b(val), buf);
    else {
        snprintf(str, n, "%#llx?, %s", get_slonglong(val), buf);
        return false;
    }

    return true;
}
Beispiel #30
0
int unfli
(
FILE *input, 
char *out_name_base, 
char *out_name_ext, 
int outtype,
int begin_frame, 
int max_frames,
int verbose,
int compress_flag
)
{
  unsigned char file_header[FILE_HEAD_SIZE];
  unsigned char frame_header[FRAME_HEAD_SIZE];
  unsigned char *frame_buffer;
  int buffer_len;
  int work_len;
  int file_len, file_type, frame_len, frame_type;
  int n, nframes;
  int last_frame, digits, help;
  int nchunks;

  if (fread(file_header, 1, FILE_HEAD_SIZE, input) != FILE_HEAD_SIZE)
    return(-1);

  file_len = get_ulong(&file_header[0]);
  if (verbose) fprintf(stdout,"Size of input file: %d\n", file_len);

  file_type = get_ushort(&file_header[4]);
  if (verbose) fprintf(stdout,"Type of input file: 0x%X\n", file_type);

  if (!((file_type == FLI_FILE_MAGIC) || (file_type == FLC_FILE_MAGIC)))
    {
      fprintf(stdout,"Unknown file type!\n");
      return(0);
    }

  nframes = get_ushort(&file_header[6]);
  image_width = get_ushort(&file_header[8]);
  image_height = get_ushort(&file_header[10]);
  if (verbose)
    {
      fprintf(stdout,"Number of frames: %d\n", nframes);
      fprintf(stdout,"Width:  %d\n", image_width);
      fprintf(stdout,"Height: %d\n", image_height);
    }

  buffer_len = image_width * image_height;

  frame_buffer = malloc(buffer_len);
  image_buffer = malloc(buffer_len);

  if ((frame_buffer == NULL) || (image_buffer == NULL))
    return(-2);

  memset(image_buffer, 0, buffer_len);
  memset(palette, 0, MAXCOLORS * 3);

  if (max_frames <= 0) max_frames = nframes;
  nframes++;

  if ((begin_frame < 1) || (begin_frame > nframes))
    {
      fprintf(stderr,"Begin frame-number %d out of range (1 .... %d)\n",
	      begin_frame, nframes);
      return(0);
    }

  last_frame = begin_frame + max_frames - 1;

  if (last_frame > nframes) last_frame = nframes;

  help = nframes;
  digits=0;
  while (help > 0)
    {
      help = (help - (help % 10))/10;
      digits++;
    }
  if (digits < 3) digits = 3;

  if (last_frame == begin_frame)
    fprintf(stdout,"Extracting frame %d\n",begin_frame);
  else
    fprintf(stdout,"Extracting frames from %d to %d\n",
	    begin_frame, last_frame);

  for (n = 1; n <= nframes; n++)
    {
      if (n > last_frame) break;

      if (fread(frame_header, 1, FRAME_HEAD_SIZE, input) != FRAME_HEAD_SIZE)
	return(-1);
      frame_len = get_ulong(&frame_header[0]);
      if (verbose)
	fprintf(stdout,"Frame %d  --  size: %d\n", n, frame_len);

      frame_type = get_ushort(&frame_header[4]);
      if (frame_type != FLI_FRAME_MAGIC)
	{
	  fprintf(stderr,"Invalid frame type: 0x%X\n", frame_type);
	  return(0);
	}

      work_len = frame_len - FRAME_HEAD_SIZE;
      if (work_len > 0)
	{
	  if (buffer_len < work_len)
	    {
	      free(frame_buffer);
	      buffer_len = work_len;
	      frame_buffer = malloc(buffer_len);
	      if (frame_buffer == NULL) return(-2);
	    }
      
	  if (fread(frame_buffer, 1, work_len, input) != work_len) return(-1);
	  nchunks = get_ushort(&frame_header[6]);
	  process_frame(frame_buffer, nchunks, verbose);
	}

      if (n >= begin_frame)
	{
	  if (!out_image(image_buffer,palette,image_width,image_height,
		       outtype,out_name_base,out_name_ext,digits,n,
		       compress_flag))
	    return(0);
	}
    }

  return(1);
}