Beispiel #1
0
/** @fn int parse_at_item(char *at_item, char *at_name, char *host_name)
 * @brief	parse a single name[@host] item and return name and host
 *
 * @param[in]	at_item
 * @param[out]	at_name
 * @param[out]	host_name
 *
 * @return	int
 * @retval	1	success
 * @retval	0	parsing failure

 * @par MT-Safe:	yes
 * @par Side Effects:
 *	None
 *
 * @par Note:
 *	This function requires caller to provide output parameters with
 *	required memory allocated.  Checks in this function are removed
 *	for speed.
 */
int
parse_at_item(char *at_item, char *at_name, char *host_name)
{
	char *c;
	int a_pos = 0;
	int h_pos = 0;

	/* Begin the parse */
	c = at_item;
	while (isspace(*c))
		c++;

	/* Looking for something before the @ sign */
	while (*c != '\0') {
		if (ISNAMECHAR(*c)) {
			if (a_pos >= MAXPATHLEN)
				return 1;
			at_name[a_pos++]=*c;
		} else
			break;
		c++;
	}
	if (a_pos == 0)
		return 1;

	/* Looking for a server */
	if (*c == '@') {
		c++;
		while (*c != '\0') {
			if (ISNAMECHAR(*c)) {
				if (h_pos >= PBS_MAXSERVERNAME)
					return 1;
				host_name[h_pos++]=*c;
			} else
				break;
			c++;
		}
		if (h_pos == 0)
			return 1;
	}

	if (*c != '\0')
		return 1;

	/* set null chars at the end of the string */
	at_name[a_pos] = '\0';
	host_name[h_pos] = '\0';

	return (0);
}
Beispiel #2
0
static ag_bool
insertEnvVal(
    char*   pzBuf,
    int     bufSize,
    tCC*    pzName,
    tCC*    pzProgPath )
{
    char* pzDir = pzBuf;

    for (;;) {
        int ch = (int)*++pzName;
        if (! ISNAMECHAR( ch ))
            break;
        *(pzDir++) = (char)ch;
    }

    if (pzDir == pzBuf)
        return AG_FALSE;

    *pzDir = NUL;

    pzDir = getenv( pzBuf );

    /*
     *  Environment value not found -- skip the home list entry
     */
    if (pzDir == NULL)
        return AG_FALSE;

    if (strlen( pzDir ) + 1 + strlen( pzName ) >= bufSize)
        return AG_FALSE;

    sprintf( pzBuf, "%s%s", pzDir, pzName );
    return AG_TRUE;
}
Beispiel #3
0
/*  handleStructure
 *
 *  "pzText" points to a '<' character, followed by an alpha.
 *  The end of the entry is either the "/>" following the name, or else a
 *  "</name>" string.
 */
static char*
handleStructure(
    tOptions*     pOpts,
    tOptState*    pOS,
    char*         pzText,
    int           direction )
{
    tOptionLoadMode mode = option_load_mode;
    tOptionValue     valu;

    char* pzName = ++pzText;
    char* pzData;
    char* pcNulPoint;

    while (ISNAMECHAR( *pzText ))  pzText++;
    pcNulPoint = pzText;
    valu.valType = OPARG_TYPE_STRING;

    switch (*pzText) {
    case ' ':
    case '\t':
        pzText = parseAttributes( pOpts, pzText, &mode, &valu );
        if (*pzText == '>')
            break;
        if (*pzText != '/')
            return NULL;
        /* FALLTHROUGH */

    case '/':
        if (pzText[1] != '>')
            return NULL;
        *pzText = NUL;
        pzText += 2;
        loadOptionLine( pOpts, pOS, pzName, direction, mode );
        return pzText;

    case '>':
        break;

    default:
        pzText = strchr( pzText, '>');
        if (pzText != NULL)
            pzText++;
        return pzText;
    }

    /*
     *  If we are here, we have a value.  "pzText" points to a closing angle
     *  bracket.  Separate the name from the value for a moment.
     */
    *pcNulPoint = NUL;
    pzData = ++pzText;

    /*
     *  Find the end of the option text and NUL terminate it
     */
    {
        char   z[64], *pz = z;
        size_t len = strlen(pzName) + 4;
        if (len > sizeof(z))
            pz = AGALOC(len, "scan name");

        sprintf( pz, "</%s>", pzName );
        *pzText = ' ';
        pzText = strstr( pzText, pz );
        if (pz != z) AGFREE(pz);

        if (pzText == NULL)
            return pzText;

        *pzText = NUL;

        pzText += len-1;
    }

    /*
     *  Rejoin the name and value for parsing by "loadOptionLine()".
     *  Erase any attributes parsed by "parseAttributes()".
     */
    memset(pcNulPoint, ' ', pzData - pcNulPoint);

    /*
     *  "pzName" points to what looks like text for one option/configurable.
     *  It is NUL terminated.  Process it.
     */
    loadOptionLine( pOpts, pOS, pzName, direction, mode );

    return pzText;
}
Beispiel #4
0
/*  handleConfig
 *
 *  "pzText" points to the start of some value name.
 *  The end of the entry is the end of the line that is not preceded by
 *  a backslash escape character.  The string value is always processed
 *  in "cooked" mode.
 */
static char*
handleConfig(
    tOptions*     pOpts,
    tOptState*    pOS,
    char*         pzText,
    int           direction )
{
    char* pzName = pzText++;
    char* pzEnd  = strchr( pzText, '\n' );

    if (pzEnd == NULL)
        return pzText + strlen(pzText);

    while (ISNAMECHAR( (int)*pzText ))  pzText++;
    while (isspace( (int)*pzText )) pzText++;
    if (pzText > pzEnd) {
    name_only:
        *pzEnd++ = NUL;
        loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED );
        return pzEnd;
    }

    /*
     *  Either the first character after the name is a ':' or '=',
     *  or else we must have skipped over white space.  Anything else
     *  is an invalid format and we give up parsing the text.
     */
    if ((*pzText == '=') || (*pzText == ':')) {
        while (isspace( (int)*++pzText ))   ;
        if (pzText > pzEnd)
            goto name_only;
    } else if (! isspace((int)pzText[-1]))
        return NULL;

    /*
     *  IF the value is continued, remove the backslash escape and push "pzEnd"
     *  on to a newline *not* preceded by a backslash.
     */
    if (pzEnd[-1] == '\\') {
        char* pcD = pzEnd-1;
        char* pcS = pzEnd;

        for (;;) {
            char ch = *(pcS++);
            switch (ch) {
            case NUL:
                pcS = NULL;

            case '\n':
                *pcD = NUL;
                pzEnd = pcS;
                goto copy_done;

            case '\\':
                if (*pcS == '\n') {
                    ch = *(pcS++);
                }
                /* FALLTHROUGH */
            default:
                *(pcD++) = ch;
            }
        } copy_done:;

    } else {
        /*
         *  The newline was not preceded by a backslash.  NUL it out
         */
        *(pzEnd++) = NUL;
    }

    /*
     *  "pzName" points to what looks like text for one option/configurable.
     *  It is NUL terminated.  Process it.
     */
    loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED );

    return pzEnd;
}
Beispiel #5
0
int
parse_at_item(char *at_item, char **at_name_out, char **host_name_out)
  {
  int i;
  char *c;
  static char at_name[MAXPATHLEN+1];
  static int a_pos;
  static char host_name[PBS_MAXSERVERNAME];
  static int h_pos;

  /* initialize static data for this parsing call */

  for (i = 0; i < MAXPATHLEN + 1; i++) at_name[i] = '\0';

  a_pos = 0;

  for (i = 0; i < PBS_MAXSERVERNAME; i++) host_name[i] = '\0';

  h_pos = 0;

  /* Begin the parse */
  c = at_item;

  while (isspace(*c)) c++;

  /* Looking for something before the @ sign */
  while (*c != '\0')
    {
    if (ISNAMECHAR(*c))
      {
      if (a_pos >= MAXPATHLEN) return 1;

      at_name[a_pos++] = *c;
      }
    else
      break;

    c++;
    }

  if (a_pos == 0) return 1;

  /* Looking for a server */
  if (*c == '@')
    {
    c++;

    while (*c != '\0')
      {
      if (ISNAMECHAR(*c))
        {
        if (h_pos >= PBS_MAXSERVERNAME) return 1;

        host_name[h_pos++] = *c;
        }
      else
        break;

      c++;
      }

    if (h_pos == 0) return 1;
    }

  if (*c != '\0') return 1;

  /* set char * pointers to static data, to arguments */
  if (at_name_out != NULL) *at_name_out = at_name;

  if (host_name_out != NULL) *host_name_out = host_name;

  return 0;
  }
Beispiel #6
0
/**
 * @brief
 *	parses the staging file name
 *      syntax:	locat_file@hostname:remote_file
 *		on Windows if remote_file is UNC path then
 *		hostname is optional so syntax can be
 *		local_file@remote_unc_file
 *      Note: The arguments local_name, host_name, remote_name are mandatory and
 *	must be allocated with required memory by the caller.
 *
 * @param[in]       pair        - a staged file name pair
 * @param[in/out]   local_name  - local file name
 * @param[in/out]   host_name   - remote host
 * @param[in/out]   remote_name - remote file namea
 *
 * @return int
 * @retval 0    parsing was successful
 * @retval 1	error in parsing
 */
int
parse_stage_name(char *pair, char *local_name, char *host_name, char *remote_name)
{
	char *c = NULL;
	int l_pos = 0;
	int h_pos = 0;
	int r_pos = 0;

	/* Begin the parse */
	c = pair;
	while (isspace(*c)) c++;

	/* Looking for something before the @ sign */
	while (*c != '\0') {
		if (ISNAMECHAR(*c)) {		/* allow whitespace and stop on '@' */
			if (l_pos >= MAXPATHLEN) return 1;
			local_name[l_pos++]=*c;
		} else
			break;
		c++;
	}
	if (l_pos == 0) return 1;

#ifdef WIN32
	if ((*c == '@') && (c+1 != NULL) && (IS_UNCPATH(c+1))) {
		c++;
		/*
		 * remote_name is UNC path without host part
		 * so skip parsing of host_name and parse
		 * remote_name
		 */
		while (*c != '\0') {
			if (ISNAMECHAR(*c)) {	/* allow whitespace */
				if (r_pos >= MAXPATHLEN) return 1;
				remote_name[r_pos++]=*c;
			} else
				break;
			c++;
		}
	}
#endif
	/* Looking for something between the @ and the : */
	if (*c == '@') {
		c++;
		while (*c != '\0') {
			if (ISNAMECHAR2(*c)) {	/* no whitespace allowed in host */
				if (h_pos >= PBS_MAXSERVERNAME) return 1;
				host_name[h_pos++]=*c;
			} else
				break;
			c++;
		}
		if (h_pos == 0) return 1;
	}

#ifdef WIN32
	/*
	 * h_pos may be 1 if non-UNC path is given
	 * without host part which is not allowed
	 * so return parsing error
	 * example: -Wstagein=C:\testdir@D:\testdir1
	 */
	if (h_pos == 1)
		return 1;
#endif

	/* Looking for something after the : */
	if (*c == ':') {
		c++;
		while (*c != '\0') {
			if (ISNAMECHAR(*c)) {	/* allow whitespace */
				if (r_pos >= MAXPATHLEN) return 1;
				remote_name[r_pos++]=*c;
			} else
				break;
			c++;
		}
	}
	if (r_pos == 0) return 1;

	if (*c != '\0') return 1;


	/* set null chars at end of string */
	local_name[l_pos] = '\0';
	remote_name[r_pos] = '\0';
	host_name[h_pos] = '\0';

	return (0);
}
Beispiel #7
0
/**
 * @brief
 *	parses the job id for current server[:port] part
 *
 * @param[in] job_id - job id
 * @param[out] arg_seq_number - sequence number 
 * @param[out] arg_parent_server - parent server
 * @param[out] arg_current_server - current server
 *
 * @return	int
 * @retval	0	success
 * @retval	1	error
 *
 */
int
parse_jobid(char *job_id, char **arg_seq_number, char **arg_parent_server, char ** arg_current_server)
{
	int is_resv = 0;
	char *c;
	char *seq_number = NULL;
	int s_pos = 0;
	char *parent_server = NULL;
	int p_pos = 0;
	char *current_server = NULL;
	int c_pos = 0;
	int ret = 0;

	seq_number = calloc(PBS_MAXCLTJOBID+1, 1);
	if (seq_number == NULL) {
		ret = 1;
		goto err;
	}
	parent_server = calloc(MAXSERVERNAME, 1);
	if (parent_server == NULL) {
		ret = 1;
		goto err;
	}
	current_server = calloc(MAXSERVERNAME, 1);
	if (current_server == NULL) {
		ret = 1;
		goto err;
	}

	/* Begin the parse */
	c = job_id;
	while (isspace(*c)) c++;

	/* skip past initial char if reservation */
	if (*c == PBS_RESV_ID_CHAR || *c == PBS_STDNG_RESV_ID_CHAR) {
		is_resv = 1;
		seq_number[s_pos++] = *c;
		c++;
	}

	/* Looking for a seq_number */
	while (*c != '\0') {
		if (isdigit(*c)) {
			if ((s_pos >= PBS_MAXSEQNUM && !is_resv) ||
				(s_pos >= PBS_MAXSEQNUM+1 && is_resv)) {
				ret = 3;
				goto err;
			}
			seq_number[s_pos++]=*c;
		} else
			break;
		c++;
	}
	if (s_pos == 0) {
		ret = 1;
		goto err;
	}

	/* Is this an ArrayJob identifier or a Array subjob id? */
	if (*c == '[') {
		if (is_resv) {
			ret = 1;
			goto err;	/* cannot be both Array... and reservation */
		}

		if (s_pos >= PBS_MAXCLTJOBID) {
			ret = 3;
			goto err;
		}
		seq_number[s_pos++]=*c++;	/* copy over opening brace */
		while (*c != ']') {
			while (isdigit((int)*c)) {
				if (s_pos >= PBS_MAXCLTJOBID) {
					ret = 3;
					goto err;
				}
				seq_number[s_pos++]=*c++;
			}
			if (*c == '-') {
				if (s_pos >= PBS_MAXCLTJOBID) {
					ret = 3;
					goto err;
				}
				seq_number[s_pos++]=*c++;
			} else if (*c == ':') {
				if (s_pos >= PBS_MAXCLTJOBID) {
					ret = 3;
					goto err;
				}
				seq_number[s_pos++]=*c++;
			} else if (*c != ']') {
				ret = 1;
				goto err;
			}
		}
		if (s_pos >= PBS_MAXCLTJOBID) {
			ret = 3;
			goto err;
		}
		seq_number[s_pos++]=*c++;	/* copy in closing brace */
	}

	/* Looking for a parent_server */
	if (*c == '.') {
		c++;
		while (*c != '\0') {
			if (ISNAMECHAR(*c)) {
				if (p_pos >= MAXSERVERNAME) {
					ret = 3;
					goto err;
				}
				parent_server[p_pos++]=*c;
			} else
				break;
			c++;
		}
		if (p_pos == 0) {
			ret = 1;
			goto err;
		}
	}

	/* Looking for a current_server */
	if (*c == '@') {
		c++;
		while (*c != '\0') {
			if (ISNAMECHAR(*c)) {
				if (c_pos >= MAXSERVERNAME) {
					ret = 3;
					goto err;
				}
				current_server[c_pos++]=*c;
			} else
				break;
			c++;
		}
		if (c_pos == 0) {
			ret = 1;
			goto err;
		}
	}

	if (*c != '\0') {
		ret = 2;
		goto err;
	}

	if ((s_pos + p_pos + 2) > PBS_MAXCLTJOBID) {
		ret = 3;
		goto err;
	}

	/* set char * pointers to static data, to arguments */
	if (arg_seq_number != NULL) *arg_seq_number = seq_number;
	if (arg_parent_server != NULL) *arg_parent_server = parent_server;
	if (arg_current_server != NULL) *arg_current_server = current_server;

	return 0;

err:
	if (seq_number) free(seq_number);
	if (current_server) free(current_server);
	if (parent_server) free(parent_server);
	return ret;
}
int parse_jobid(
    
  char *job_id, 
  char **arg_seq_number, 
  char **arg_parent_server, 
  char **arg_current_server)

  {
  int i;
  char *c;

  /* initialize static data for this parsing call */

  for (i = 0; i < PBS_MAXSEQNUM + PBS_MAXJOBARRAYLEN + 1; i++) seq_number[i] = '\0';

  s_pos = 0;

  for (i = 0; i < MAXSERVERNAME; i++) parent_server[i] = '\0';

  p_pos = 0;

  for (i = 0; i < MAXSERVERNAME; i++) current_server[i] = '\0';

  c_pos = 0;

  /* Begin the parse */
  c = job_id;

  while (isspace(*c)) c++;

  /* Looking for a seq_number */
  while (*c != '\0')
    {
    /* look for a digit or array brackets */
    if (isdigit(*c) || *c == '[' || *c == ']')
      {
      if (s_pos >= PBS_MAXSEQNUM + PBS_MAXJOBARRAYLEN) return 3;

      seq_number[s_pos++] = *c;
      }
    else
      break;

    c++;
    }

  if (s_pos == 0) return 1;

  /* Looking for a parent_server */
  if (*c == '.')
    {
    c++;

    while (*c != '\0')
      {
      if (ISNAMECHAR(*c))
        {
        if (p_pos >= MAXSERVERNAME) return 3;

        parent_server[p_pos++] = *c;
        }
      else
        break;

      c++;
      }

    if (p_pos == 0) return 1;
    }

  /* Looking for a current_server */
  if (*c == '@')
    {
    c++;

    while (*c != '\0')
      {
      if (ISNAMECHAR(*c))
        {
        if (c_pos >= MAXSERVERNAME) return 3;

        current_server[c_pos++] = *c;
        }
      else
        break;

      c++;
      }

    if (c_pos == 0) return 1;
    }

  if (*c != '\0') return 2;

  /* set char * pointers to static data, to arguments */
  if (arg_seq_number != NULL) *arg_seq_number = seq_number;

  if (arg_parent_server != NULL) *arg_parent_server = parent_server;

  if (arg_current_server != NULL) *arg_current_server = current_server;

  return 0;
  }
Beispiel #9
0
int parse_destination_id(

  char *destination_in,     /* I */
  char **queue_name_out,    /* O */
  char **server_name_out)   /* O */

  {
  /* FORMAT:  <QUEUE>@<HOST>:<PORT> */

  int i;
  char *c;
  char queue_name[PBS_MAXQUEUENAME+1];
  int q_pos;
  char server_name[MAXSERVERNAME];
  int c_pos;


  /* initialize static data for this parsing call */

  for (i = 0; i < PBS_MAXQUEUENAME + 1; i++) queue_name[i] = '\0';

  q_pos = 0;

  for (i = 0; i < MAXSERVERNAME; i++) server_name[i] = '\0';

  c_pos = 0;

  /* Begin the parse */
  c = destination_in;

  while (isspace(*c)) c++;

  /* Looking for a queue */
  while (*c != '\0')
    {
    if (ISNAMECHAR(*c))
      {
      if (q_pos >= PBS_MAXQUEUENAME) return 1;

      queue_name[q_pos++] = *c;
      }
    else
      break;

    c++;
    }

  /* Looking for a server */
  if (*c == '@')
    {
    c++;

    while (*c != '\0')
      {
      if (ISNAMECHAR(*c))
        {
        if (c_pos >= MAXSERVERNAME) return 1;

        server_name[c_pos++] = *c;
        }
      else
        break;

      c++;
      }

    if (c_pos == 0) return 1;
    }

  if (*c != '\0') return 1;

  /* set char * pointers to static data, to arguments */
  if (queue_name_out != NULL) *queue_name_out = queue_name;

  if (server_name_out != NULL) *server_name_out = server_name;

  return 0;
  }