Beispiel #1
0
char *disrst(

  struct tcp_chan *chan,
  int *retval)

  {
  int        locret;
  int        negate;
  unsigned int count;

  char *value = NULL;

  assert(retval != NULL);

  locret = disrsi_(chan, &negate, &count, 1);

  if (locret == DIS_SUCCESS)
    {
    if (negate)
      {
      locret = DIS_BADSIGN;
      }
    else
      {
      value = (char *)calloc(1, (size_t)count + 1);

      if (value == NULL)
        {
        locret = DIS_NOMALLOC;
        }
      else
        {
        if (tcp_gets(chan, value, (size_t)count) != (int)count)
          locret = DIS_PROTO;

#ifndef NDEBUG
        else if (memchr(value, 0, (size_t)count))
          locret = DIS_NULLSTR;

#endif
        else
          value[count] = '\0';
        }
      }
    locret = (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0) ?  DIS_NOCOMMIT : locret;
    }

  *retval = locret;

  if ((locret != DIS_SUCCESS) && (value != NULL))
    {
    free(value);

    value = NULL;
    }

  return(value);
  }  /* END disrst() */
Beispiel #2
0
int tcp_getc(

  struct tcp_chan *chan)

  {
  int rc = DIS_SUCCESS;
  char ret_val;
  if ((rc = tcp_gets(chan, &ret_val, 1)) < 0)
    return rc;
  return (int)ret_val;
  }  /* END tcp_getc() */
Beispiel #3
0
int tcp_getc(

  struct tcp_chan *chan,
  unsigned int     timeout)

  {
  int rc = DIS_SUCCESS;
  char ret_val;
  if ((rc = tcp_gets(chan, &ret_val, 1, timeout)) < 0)
    return rc;
  return (int)ret_val;
  }  /* END tcp_getc() */
Beispiel #4
0
int disrfst(

  struct tcp_chan *chan,
  size_t  achars,
  char   *value)

  {
  int  locret;
  /*int           rc;*/

  int  negate;
  unsigned count;

  assert(value != NULL);
  
  locret = disrsi_(chan, &negate, &count, 1, pbs_tcp_timeout);

  if (locret == DIS_SUCCESS)
    {
    if (negate)
      locret = DIS_BADSIGN;
    else if (count > achars)
      locret = DIS_OVERFLOW;
    else if (tcp_gets(chan, value, (size_t)count, pbs_tcp_timeout) != (int)count)
      locret = DIS_PROTO;

#ifndef NDEBUG
    else if (memchr(value, 0, (size_t)count))
      locret = DIS_NULLSTR;

#endif
    else
      value[count] = '\0';
    }

  /*
    if (locret == DIS_SUCCESS)
      rc = tcp_rcommit(chan,TRUE);
    else
      rc = tcp_rcommit(chan,FALSE);

    locret = (rc != 0) ? rc : DIS_NOCOMMIT;
  */

  locret = tcp_rcommit(chan, locret == DIS_SUCCESS) ?
           DIS_NOCOMMIT :
           locret;

  if (locret != DIS_SUCCESS)
    *value = '\0';

  return(locret);
  }  /* END disrfst() */
Beispiel #5
0
char *disrcs(
    
  struct tcp_chan *chan,
  size_t *nchars,
  int    *retval)
  
  {
  int  locret;
  int  negate;
  unsigned count = 0;
  char  *value = NULL;

  assert(nchars != NULL);
  assert(retval != NULL);

  locret = disrsi_(chan, &negate, &count, 1);
  locret = negate ? DIS_BADSIGN : locret;

  if (locret == DIS_SUCCESS)
    {
    value = (char *)calloc(1, (size_t)count + 1);

    if (value == NULL)
      locret = DIS_NOMALLOC;
    else
      {
      if (tcp_gets(chan, value,
                      (size_t)count) != (int)count)
        locret = DIS_PROTO;
      else
        value[count] = '\0';
      }
    }

  locret = (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0) ?

           DIS_NOCOMMIT : locret;

  if ((*retval = locret) != DIS_SUCCESS && value != NULL)
    {
    count = 0;
    free(value);
    value = NULL;
    }

  *nchars = count;

  return (value);
  }
Beispiel #6
0
int disrsl_(

  struct tcp_chan *chan,
  int             *negate,
  unsigned long   *value,
  unsigned long    count)

  {
  int            c;
  unsigned long  locval;
  unsigned long  ndigs;
  char          *cp;
  char           scratch[DIS_BUFSIZ];

  assert(negate != NULL);
  assert(value != NULL);
  assert(count);

  memset(scratch, 0, sizeof(scratch));

  if (ulmaxdigs == 0)
    {
    cp = discul_(scratch + sizeof(scratch) - 1, ULONG_MAX, &ulmaxdigs);

    ulmax = (char *)calloc(1, ulmaxdigs);

    if (ulmax == NULL)
      {
      return(DIS_NOMALLOC);
      }

    memcpy(ulmax, cp, ulmaxdigs);

    if (dis_umaxd == 0)
      disiui_();
    }

  if (count >= ulmaxdigs)
    {
    if (count > ulmaxdigs)
      goto overflow;

    if (memcmp(scratch, ulmax, ulmaxdigs) > 0)
      goto overflow;
    }

  c = tcp_getc(chan);

  /* FORMAT:  +2+1+0+0+64+2079+22+251175826.teva.westgrid.ubc2+362+21+8Job_Name+02+11run32_.2557+02+ ... */

  switch (c)
    {

    case '-':

    case '+':

      *negate = (c == '-');

      if (tcp_gets(chan, scratch, count) != (int)count)
        {
        return(DIS_EOD);
        }

      if (count >= ulmaxdigs)
        {
        if (count > ulmaxdigs)
          goto overflow;

        if (memcmp(scratch, ulmax, ulmaxdigs) > 0)
          goto overflow;
        }

      cp = scratch;

      locval = 0;

      do
        {
        if ((c = *cp++) < '0' || c > '9')
          {
          return(DIS_NONDIGIT);
          }

        locval = 10 * locval + c - '0';
        }
      while (--count);

      *value = locval;

      return(DIS_SUCCESS);

      /*NOTREACHED*/

      break;

    case '0':

      return(DIS_LEADZRO);

      /*NOTREACHED*/

      break;

    case '1':

    case '2':

    case '3':

    case '4':

    case '5':

    case '6':

    case '7':

    case '8':

    case '9':

      ndigs = c - '0';

      if (count > 1)
        {
        if (tcp_gets(chan, scratch + 1, count - 1) != (int)count - 1)
          {
          /* FAILURE */

          return(DIS_EOD);
          }

        cp = scratch;

        if (count >= ulmaxdigs)
          {
          if (count > ulmaxdigs)
            break;

          *cp = c;

          if (memcmp(scratch, ulmax, ulmaxdigs) > 0)
            break;
          }

        while (--count)
          {
          if (((c = *++cp) < '0') || (c > '9'))
            {
            /* FAILURE */
            return(DIS_NONDIGIT);
            }

          ndigs = 10 * ndigs + c - '0';
          }
        }

      return(disrsl_(chan, negate, value, ndigs));

      /*NOTREACHED*/

      break;

    case - 1:

      /* FAILURE */

      return(DIS_EOD);

      /*NOTREACHED*/

      break;

    case -2:

      /* FAILURE */

      return(DIS_EOF);

      /*NOTREACHED*/

      break;

    default:

      /* FAILURE */

      return(DIS_NONDIGIT);

      /*NOTREACHED*/

      break;
    }  /* END switch (c) */

  *negate = FALSE;

overflow:

  *value = ULONG_MAX;

  return(DIS_OVERFLOW);
  }  /* END disrsl_() */
Beispiel #7
0
int disrsi_(

  struct tcp_chan *chan,
  int             *negate,
  unsigned        *value,
  unsigned         count)

  {
  int       c;
  unsigned  locval;
  unsigned  ndigs;
  char     *cp = NULL;
  char      scratch[DIS_BUFSIZ];

  if (negate == NULL)
    return DIS_INVALID;
  if (value == NULL)
    return DIS_INVALID;
  if (count == 0)
    return DIS_INVALID;

  memset(scratch, 0, sizeof(scratch));

  if (dis_umaxd == 0)
    disiui_();
  
  if (count > sizeof(scratch) - 1)
    return DIS_INVALID;

  switch (c = tcp_getc(chan))
    {

    case '-':
    case '+':

      *negate = c == '-';

      if (tcp_gets(chan, scratch, count) != (int)count)
        {
        return(DIS_EOD);
        }

      if (count > dis_umaxd)
        goto overflow;
      if (count == dis_umaxd)
        {
        if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
          goto overflow;
        }

      cp = scratch;

      locval = 0;

      do
        {
        if (((c = *cp++) < '0') || (c > '9'))
          return(DIS_NONDIGIT);

        locval = 10 * locval + c - '0';
        }
      while (--count);

      *value = locval;
      return (DIS_SUCCESS);
      break;

    case '0':
      return (DIS_LEADZRO);
      break;

    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':

      ndigs = c - '0';

      if (count > 1)
        {
        if (tcp_gets(chan, scratch + 1, count - 1) != (int)count - 1)
          {
          return(DIS_EOD);
          }

        cp = scratch;

        if (count >= dis_umaxd)
          {
          if (count > dis_umaxd)
            break;

          *cp = c;

          if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
            break;
          }

        while (--count)
          {
          if (((c = *++cp) < '0') || (c > '9'))
            {
            return(DIS_NONDIGIT);
            }

          ndigs = 10 * ndigs + c - '0';
          }
        }    /* END if (count > 1) */

      return(disrsi_(chan, negate, value, ndigs));
      break;

    case -1:
      return(DIS_EOD);
      break;

    case -2:
      return(DIS_EOF);
      break;

    default:

      return(DIS_NONDIGIT);
      break;
    }

  *negate = FALSE;

overflow:

  *value = UINT_MAX;

  return(DIS_OVERFLOW);
  }  /* END disrsi_() */