int Pigeon::getKeyValue(MyString line, MyString *key, MyString *value) { int type = AD_NULL; int tokenno = -1; char *s1 = 0; line.Tokenize(); while( (s1 = const_cast<char*>(line.GetNextToken(" ", true))) != NULL) { tokenno++; if (strlen(s1) < 1) goto end; //dprintf(D_FULLDEBUG, "Tokens %d: %s\n", tokenno, s1); switch (tokenno) { case 0: if (strcmp(s1, "START_AD") != 0) goto end; break; case 1: if (s1[0] == 'S') type = AD_STRING; else if (s1[0] == 'I') type = AD_INT; else if (s1[0] == 'D') type = AD_DOUBLE; else if (s1[0] == 'B') type = AD_BOOLEAN; break; case 2: *key = s1; break; case 3: *value = s1; break; case 4: if (strcmp(s1, "END_AD") != 0) type = AD_NULL; break; } } //wrong number of tokens if (tokenno < 4) type = AD_NULL; end: return type; }
//--------------------------------------------------------------------------- // This does only partial parsing -- only what we need for recovery mode // and rescue initialization. bool JobstateLog::ParseLine( MyString &line, time_t ×tamp, MyString &nodeName, int &seqNum ) { line.chomp(); line.Tokenize(); const char* timestampTok = line.GetNextToken( " ", false ); const char* nodeNameTok = line.GetNextToken( " ", false ); (void)line.GetNextToken( " ", false ); // event name (void)line.GetNextToken( " ", false ); // condor id (void)line.GetNextToken( " ", false ); // job tag (pegasus site) (void)line.GetNextToken( " ", false ); // unused const char* seqNumTok = line.GetNextToken( " ", false ); if ( (timestampTok == NULL) || (nodeNameTok == NULL) ) { debug_printf( DEBUG_QUIET, "Warning: error parsing " "jobstate.log file line <%s>\n", line.Value() ); check_warning_strictness( DAG_STRICT_1 ); return false; } // fetch the number, and get a pointer to the first char after // if the pointer did not advance, then there was no number to parse. char *pend; timestamp = (time_t)strtoll(timestampTok, &pend, 10); if (pend == timestampTok) { debug_printf( DEBUG_QUIET, "Warning: error reading " "timestamp in jobstate.log file line <%s>\n", line.Value() ); check_warning_strictness( DAG_STRICT_1 ); return false; } nodeName = nodeNameTok; seqNum = 0; if ( seqNumTok ) { seqNum = (int)strtol(seqNumTok, &pend, 10); if (pend == seqNumTok) { debug_printf( DEBUG_QUIET, "Warning: error reading " "sequence number in jobstate.log file line <%s>\n", line.Value() ); check_warning_strictness( DAG_STRICT_1 ); return false; } } return true; }
MyString MultiLogFiles::getParamFromSubmitLine(MyString &submitLine, const char *paramName) { MyString paramValue(""); const char *DELIM = "="; submitLine.Tokenize(); const char * rawToken = submitLine.GetNextToken(DELIM, true); if ( rawToken ) { MyString token(rawToken); token.trim(); if ( !strcasecmp(token.Value(), paramName) ) { rawToken = submitLine.GetNextToken(DELIM, true); if ( rawToken ) { paramValue = rawToken; paramValue.trim(); } } } return paramValue; }
/** * This is the logic that is used to take a parameter string * given for a specific field in the cron schedule and expand it * out into a range of int's that can be looked up quickly later on * We must be given the index number of the field we're going to parse * and a min/max for the range of values allowed for the attribute. * If the parameter is invalid, we will report an error and return false * This will prevent them from querying nextRunTime() for runtimes * * @param attribute_idx - the index for the parameter in CronTab::attributes * @param min - the mininum value in the range for this parameter * @param max - the maximum value in the range for this parameter * @return true if we were able to create the range of values **/ bool CronTab::expandParameter( int attribute_idx, int min, int max ) { MyString *param = this->parameters[attribute_idx]; ExtArray<int> *list = this->ranges[attribute_idx]; // // Make sure the parameter is valid // The validation method will have already printed out // the error message to the log // MyString error; if ( ! CronTab::validateParameter( attribute_idx, param->Value(), error ) ) { dprintf( D_ALWAYS, "%s", error.Value() ); // // Store the error in case they want to email // the user to tell them that they goofed // CronTab::errorLog += error; return ( false ); } // // Remove any spaces // param->replaceString(" ", ""); // // Now here's the tricky part! We need to expand their parameter // out into a range that can be put in array of integers // First start by spliting the string by commas // param->Tokenize(); const char *_token; while ( ( _token = param->GetNextToken( CRONTAB_DELIMITER, true ) ) != NULL ) { MyString token( _token ); int cur_min = min, cur_max = max, cur_step = 1; // ------------------------------------------------- // STEP VALUES // The step value is independent of whether we have // a range, the wildcard, or a single number. // ------------------------------------------------- if ( token.find( CRONTAB_STEP ) > 0 ) { // // Just look for the step value to replace // the current step value. The other code will // handle the rest // token.Tokenize(); const char *_temp; // // Take out the numerator, keep it for later // const char *_numerator = token.GetNextToken( CRONTAB_STEP, true ); if ( ( _temp = token.GetNextToken( CRONTAB_STEP, true ) ) != NULL ) { MyString stepStr( _temp ); stepStr.trim(); cur_step = atoi( stepStr.Value() ); } // // Now that we have the denominator, put the numerator back // as the token. This makes it easier to parse later on // token = _numerator; } // STEP // ------------------------------------------------- // RANGE // If it's a range, expand the range but make sure we // don't go above/below our limits // Note that the find will ignore the token if the // range delimiter is in the first character position // ------------------------------------------------- if ( token.find( CRONTAB_RANGE ) > 0 ) { // // Split out the integers // token.Tokenize(); MyString *_temp; int value; // // Min // _temp = new MyString( token.GetNextToken( CRONTAB_RANGE, true ) ); _temp->trim(); value = atoi( _temp->Value() ); cur_min = ( value >= min ? value : min ); delete _temp; // // Max // _temp = new MyString( token.GetNextToken( CRONTAB_RANGE, true ) ); _temp->trim(); value = atoi( _temp->Value() ); cur_max = ( value <= max ? value : max ); delete _temp; // ------------------------------------------------- // WILDCARD // This will select all values for the given range // ------------------------------------------------- } else if ( token.find( CRONTAB_WILDCARD ) >= 0 ) { // // For this we do nothing since it will just // be the min-max range // // Day of Week Special Case // The day of week specifier is kind of weird // If it's the wildcard, then it doesn't mean // include all like the other fields. The reason // why we don't want to do that is because later // on we are going to expand the day of the week // field to be actual dates in a month in order // to figure out when to run next, so we don't // want to expand out the wildcard for all days // if the day of month field is restricted // Read the cron manpage! // if ( attribute_idx == CRONTAB_DOW_IDX ) { continue; } // ------------------------------------------------- // SINGLE VALUE // They just want a single value to be added // Note that a single value with a step like "2/3" will // work in this code but its meaningless unless its whole number // ------------------------------------------------- } else { // // Replace the range to be just this value only if it // fits in the min/max range we were given // int value = atoi(token.Value()); if ( value >= min && value <= max ) { cur_min = cur_max = value; } } // // Fill out the numbers based on the range using // the step value // int ctr; for ( ctr = cur_min; ctr <= cur_max; ctr++ ) { // // Day of Week Special Case // The crontab specifications lets Sunday be // represented with either a 0 or a 7. Our // dayOfWeek() method in date_util.h uses 0-6 // So if this the day of the week attribute and // we are given a 7 for Sunday, just convert it // to a zero // int temp = ctr; if ( attribute_idx == CRONTAB_DOW_IDX && temp == CRONTAB_DAY_OF_WEEK_MAX ) { temp = CRONTAB_DAY_OF_WEEK_MIN; } // // Make sure this value isn't alreay added and // that it falls in our step listing for the range // if ( ( ( temp % cur_step ) == 0 ) && !this->contains( *list, temp ) ) { list->add( temp ); } } // FOR } // WHILE // // Sort! Makes life easier later on // this->sort( *list ); return ( true ); }