Changeset 16712

Show
Ignore:
Timestamp:
12.08.2008 12:13:25 (11 years ago)
Author:
mdewsnip
Message:

Removed the abstractlistaction::validateAction() function and duplicated the code in listidsaction::validateAction() and listrecsaction::validateAction(), since the handling of the metadataPrefix is slightly different.

Location:
gsdl/trunk/runtime-src/src/oaiservr
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.cpp

    r16710 r16712  
    33 
    44#include "oaitools.h" 
    5  
    6 bool abstractlistaction::validateAction(recptproto *protocol, oaiargs &params) 
    7 { 
    8   // ---------------------------------------------------------------------------- 
    9   //  1. Check for invalid arguments 
    10   // ---------------------------------------------------------------------------- 
    11   bool invalid_argument_supplied = false; 
    12   text_tmap::const_iterator param_iterator = params.begin(); 
    13   while (param_iterator != params.end()) 
    14   { 
    15     // Check for arguments that aren't valid for this action 
    16     if (param_iterator->first != "verb" && 
    17     param_iterator->first != "from" && 
    18     param_iterator->first != "until" && 
    19     param_iterator->first != "set" && 
    20     param_iterator->first != "resumptionToken" && 
    21     param_iterator->first != "metadataPrefix") 
    22     { 
    23       // We've found an invalid argument 
    24       invalid_argument_supplied = true; 
    25  
    26       // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned 
    27       params.erase(param_iterator->first); 
    28     } 
    29  
    30     // The metadataPrefix argument is not allowed in OAI v1.1 
    31     else if (param_iterator->first == "metadataPrefix" && this->configuration->getOAIVersion() <= 110) 
    32     { 
    33       // We've found an invalid argument 
    34       invalid_argument_supplied = true; 
    35  
    36       // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned 
    37       params.erase(param_iterator->first); 
    38     } 
    39  
    40     param_iterator++; 
    41   } 
    42  
    43   // If we found an invalid argument it's an error, so don't go any further  
    44   if (invalid_argument_supplied) 
    45   { 
    46     this->errorType = "badArgument"; 
    47     return false; 
    48   } 
    49  
    50   // ---------------------------------------------------------------------------- 
    51   //  2. Handle any exclusive arguments 
    52   // ---------------------------------------------------------------------------- 
    53  
    54   //  The resumptionToken argument is exclusive 
    55   if (params["resumptionToken"] != "") 
    56   { 
    57     // This argument is exclusive, so no other arguments are allowed (except "verb" of course) 
    58     if (params.getSize() != 2) 
    59     { 
    60       this->errorType = "badArgument"; 
    61       return false; 
    62     } 
    63  
    64     // Check the resumption token is valid 
    65     ResumptionToken token(params["resumptionToken"]); 
    66     if (token.isValid()) 
    67     { 
    68       // Everything is fine, and we don't continue further because this is an exclusive argument 
    69       this->errorType = ""; 
    70       return true; 
    71     } 
    72     else 
    73     { 
    74       // There was an error with the resumption token 
    75       this->errorType = "badResumptionToken"; 
    76       return false; 
    77     } 
    78   } 
    79  
    80   // ---------------------------------------------------------------------------- 
    81   //  3. Handle any required arguments 
    82   // ---------------------------------------------------------------------------- 
    83  
    84   // OAI v2.0 requires metadataPrefix 
    85   if (this->configuration->getOAIVersion() > 110) 
    86   { 
    87     text_t metadataPrefix = params["metadataPrefix"]; 
    88  
    89     // Check that the metadataPrefix argument exists 
    90     if (metadataPrefix == "") 
    91     { 
    92       this->errorType = "badArgument"; 
    93       return false; 
    94     } 
    95     // Check that the metadataPrefix is a format we support 
    96     if (this->formatNotSupported(metadataPrefix)) 
    97     { 
    98       this->errorType = "cannotDisseminateFormat"; 
    99       return false; 
    100     } 
    101   } 
    102  
    103   // ---------------------------------------------------------------------------- 
    104   // 4. Check any remaining arguments 
    105   // ---------------------------------------------------------------------------- 
    106  
    107   // Check "from" and "until" arguments 
    108   if (params["from"] != "" || params["until"] != "") 
    109   { 
    110     text_t from  = params["from"]; 
    111     text_t until = params["until"]; 
    112  
    113     // Check the from date is in the correct format: YYYY-MM-DD 
    114     if (from != "") 
    115     { 
    116       // Must be in the form YYYY-MM-DD 
    117       if (from.size() != 10 || from[4] != '-' || from[7] != '-') 
    118       { 
    119     this->errorType = "badArgument"; 
    120     params.erase("from"); 
    121       } 
    122     } 
    123     // Check the until date is in the correct format: YYYY-MM-DD 
    124     if (until != "") 
    125     { 
    126       // Must be in the form YYYY-MM-DD 
    127       if (until.size() != 10 || until[4] != '-' || until[7] != '-') 
    128       { 
    129     this->errorType = "badArgument"; 
    130     params.erase("until"); 
    131       } 
    132     } 
    133  
    134     if (this->errorType == "badArgument") 
    135     { 
    136       return false; 
    137     } 
    138  
    139     // If both arguments are supplied the from date must be less than or equal to the until date 
    140     if (from != "" && until != "" && !(from <= until)) 
    141     { 
    142       this->errorType = "badArgument"; 
    143       return false; 
    144     } 
    145   } 
    146  
    147   // Check "set" argument 
    148   if (params["set"] != "") 
    149   { 
    150     // Example set specification: "demo:CL2" 
    151     text_t set = params["set"]; 
    152  
    153     // given 'demo:CL2', toGSDL returns 'demo' in collection and 'CL2' in set. If there is no further 
    154     // set specified after the name of the collection however, then set is empty. 
    155     text_t collection = ""; 
    156     oaiclassifier::toGSDL(collection, set); 
    157  
    158     // Check that the collection is accessible 
    159     ColInfoResponse_t cinfo; 
    160     comerror_t err; 
    161     protocol->get_collectinfo(collection, cinfo, err, cerr); 
    162     if (err != noError) 
    163     { 
    164       this->errorType = "badArgument"; 
    165       return false; 
    166     } 
    167  
    168     // Check the collection is one that is in the list in the oai.cfg file 
    169     text_tarray &collections = this->configuration->getCollectionsList(); 
    170     bool collection_found = false; 
    171     for (int c = 0; c < collections.size(); c++) 
    172     { 
    173       if (collections[c] == collection) 
    174       { 
    175     collection_found = true; 
    176     break; 
    177       } 
    178     } 
    179  
    180     // The collection was not found 
    181     if (!collection_found) 
    182     { 
    183       this->errorType = "badArgument"; 
    184       return false; 
    185     } 
    186  
    187     // Check the child set if it was given 
    188     if (set != "" && !this->check_classifier(protocol, collection, set)) 
    189     { 
    190       this->errorType = "badArgument"; 
    191       return false; 
    192     } 
    193   } 
    194  
    195   // If we've reached here everything must be fine 
    196   this->errorType = ""; 
    197   return true; 
    198 } 
    1995 
    2006//-------------------------------------------------------------------------------------------------- 
  • gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.h

    r16710 r16712  
    99 public: 
    1010  abstractlistaction(const text_t &name) : oaiaction(name) {this->prevDocSeen = false;} 
    11   virtual bool validateAction(recptproto *protocol, oaiargs &params); // Check that this is a valid action 
    1211  virtual bool output_document(ostream &output, recptproto *protocol, const text_t &collection,  
    1312                   const text_t &OID, const text_t &metadataPrefix) = 0; 
  • gsdl/trunk/runtime-src/src/oaiservr/listidsaction.cpp

    r16710 r16712  
    77bool listidsaction::validateAction(recptproto *protocol, oaiargs &params) 
    88{ 
    9   return abstractlistaction::validateAction(protocol, params); 
     9  // ---------------------------------------------------------------------------- 
     10  //  1. Check for invalid arguments 
     11  // ---------------------------------------------------------------------------- 
     12  bool invalid_argument_supplied = false; 
     13  text_tmap::const_iterator param_iterator = params.begin(); 
     14  while (param_iterator != params.end()) 
     15  { 
     16    // Check for arguments that aren't valid for this action 
     17    if (param_iterator->first != "verb" && 
     18    param_iterator->first != "from" && 
     19    param_iterator->first != "until" && 
     20    param_iterator->first != "set" && 
     21    param_iterator->first != "resumptionToken" && 
     22    param_iterator->first != "metadataPrefix") 
     23    { 
     24      // We've found an invalid argument 
     25      invalid_argument_supplied = true; 
     26 
     27      // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned 
     28      params.erase(param_iterator->first); 
     29    } 
     30 
     31    // The metadataPrefix argument is not allowed in OAI v1.1 
     32    else if (param_iterator->first == "metadataPrefix" && this->configuration->getOAIVersion() <= 110) 
     33    { 
     34      // We've found an invalid argument 
     35      invalid_argument_supplied = true; 
     36 
     37      // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned 
     38      params.erase(param_iterator->first); 
     39    } 
     40 
     41    param_iterator++; 
     42  } 
     43 
     44  // If we found an invalid argument it's an error, so don't go any further  
     45  if (invalid_argument_supplied) 
     46  { 
     47    this->errorType = "badArgument"; 
     48    return false; 
     49  } 
     50 
     51  // ---------------------------------------------------------------------------- 
     52  //  2. Handle any exclusive arguments 
     53  // ---------------------------------------------------------------------------- 
     54 
     55  //  The resumptionToken argument is exclusive 
     56  if (params["resumptionToken"] != "") 
     57  { 
     58    // This argument is exclusive, so no other arguments are allowed (except "verb" of course) 
     59    if (params.getSize() != 2) 
     60    { 
     61      this->errorType = "badArgument"; 
     62      return false; 
     63    } 
     64 
     65    // Check the resumption token is valid 
     66    ResumptionToken token(params["resumptionToken"]); 
     67    if (token.isValid()) 
     68    { 
     69      // Everything is fine, and we don't continue further because this is an exclusive argument 
     70      this->errorType = ""; 
     71      return true; 
     72    } 
     73    else 
     74    { 
     75      // There was an error with the resumption token 
     76      this->errorType = "badResumptionToken"; 
     77      return false; 
     78    } 
     79  } 
     80 
     81  // ---------------------------------------------------------------------------- 
     82  //  3. Handle any required arguments 
     83  // ---------------------------------------------------------------------------- 
     84 
     85  // OAI v2.0 requires metadataPrefix 
     86  if (this->configuration->getOAIVersion() > 110) 
     87  { 
     88    text_t metadataPrefix = params["metadataPrefix"]; 
     89 
     90    // Check that the metadataPrefix argument exists 
     91    if (metadataPrefix == "") 
     92    { 
     93      this->errorType = "badArgument"; 
     94      return false; 
     95    } 
     96    // Check that the metadataPrefix is a format we support 
     97    if (this->formatNotSupported(metadataPrefix)) 
     98    { 
     99      this->errorType = "cannotDisseminateFormat"; 
     100      return false; 
     101    } 
     102  } 
     103 
     104  // ---------------------------------------------------------------------------- 
     105  // 4. Check any remaining arguments 
     106  // ---------------------------------------------------------------------------- 
     107 
     108  // Check "from" and "until" arguments 
     109  if (params["from"] != "" || params["until"] != "") 
     110  { 
     111    text_t from  = params["from"]; 
     112    text_t until = params["until"]; 
     113 
     114    // Check the from date is in the correct format: YYYY-MM-DD 
     115    if (from != "") 
     116    { 
     117      // Must be in the form YYYY-MM-DD 
     118      if (from.size() != 10 || from[4] != '-' || from[7] != '-') 
     119      { 
     120    this->errorType = "badArgument"; 
     121    params.erase("from"); 
     122      } 
     123    } 
     124    // Check the until date is in the correct format: YYYY-MM-DD 
     125    if (until != "") 
     126    { 
     127      // Must be in the form YYYY-MM-DD 
     128      if (until.size() != 10 || until[4] != '-' || until[7] != '-') 
     129      { 
     130    this->errorType = "badArgument"; 
     131    params.erase("until"); 
     132      } 
     133    } 
     134 
     135    if (this->errorType == "badArgument") 
     136    { 
     137      return false; 
     138    } 
     139 
     140    // If both arguments are supplied the from date must be less than or equal to the until date 
     141    if (from != "" && until != "" && !(from <= until)) 
     142    { 
     143      this->errorType = "badArgument"; 
     144      return false; 
     145    } 
     146  } 
     147 
     148  // Check "set" argument 
     149  if (params["set"] != "") 
     150  { 
     151    // Example set specification: "demo:CL2" 
     152    text_t set = params["set"]; 
     153 
     154    // given 'demo:CL2', toGSDL returns 'demo' in collection and 'CL2' in set. If there is no further 
     155    // set specified after the name of the collection however, then set is empty. 
     156    text_t collection = ""; 
     157    oaiclassifier::toGSDL(collection, set); 
     158 
     159    // Check that the collection is accessible 
     160    ColInfoResponse_t cinfo; 
     161    comerror_t err; 
     162    protocol->get_collectinfo(collection, cinfo, err, cerr); 
     163    if (err != noError) 
     164    { 
     165      this->errorType = "badArgument"; 
     166      return false; 
     167    } 
     168 
     169    // Check the collection is one that is in the list in the oai.cfg file 
     170    text_tarray &collections = this->configuration->getCollectionsList(); 
     171    bool collection_found = false; 
     172    for (int c = 0; c < collections.size(); c++) 
     173    { 
     174      if (collections[c] == collection) 
     175      { 
     176    collection_found = true; 
     177    break; 
     178      } 
     179    } 
     180 
     181    // The collection was not found 
     182    if (!collection_found) 
     183    { 
     184      this->errorType = "badArgument"; 
     185      return false; 
     186    } 
     187 
     188    // Check the child set if it was given 
     189    if (set != "" && !this->check_classifier(protocol, collection, set)) 
     190    { 
     191      this->errorType = "badArgument"; 
     192      return false; 
     193    } 
     194  } 
     195 
     196  // If we've reached here everything must be fine 
     197  this->errorType = ""; 
     198  return true; 
    10199} 
    11200 
  • gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.cpp

    r16710 r16712  
    66bool listrecsaction::validateAction(recptproto *protocol, oaiargs &params) 
    77{  
    8   return abstractlistaction::validateAction(protocol, params); 
     8  // ---------------------------------------------------------------------------- 
     9  //  1. Check for invalid arguments 
     10  // ---------------------------------------------------------------------------- 
     11  bool invalid_argument_supplied = false; 
     12  text_tmap::const_iterator param_iterator = params.begin(); 
     13  while (param_iterator != params.end()) 
     14  { 
     15    // Check for arguments that aren't valid for this action 
     16    if (param_iterator->first != "verb" && 
     17    param_iterator->first != "from" && 
     18    param_iterator->first != "until" && 
     19    param_iterator->first != "set" && 
     20    param_iterator->first != "resumptionToken" && 
     21    param_iterator->first != "metadataPrefix") 
     22    { 
     23      // We've found an invalid argument 
     24      invalid_argument_supplied = true; 
     25 
     26      // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned 
     27      params.erase(param_iterator->first); 
     28    } 
     29 
     30    // The metadataPrefix argument is not allowed in OAI v1.1 
     31    else if (param_iterator->first == "metadataPrefix" && this->configuration->getOAIVersion() <= 110) 
     32    { 
     33      // We've found an invalid argument 
     34      invalid_argument_supplied = true; 
     35 
     36      // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned 
     37      params.erase(param_iterator->first); 
     38    } 
     39 
     40    param_iterator++; 
     41  } 
     42 
     43  // If we found an invalid argument it's an error, so don't go any further  
     44  if (invalid_argument_supplied) 
     45  { 
     46    this->errorType = "badArgument"; 
     47    return false; 
     48  } 
     49 
     50  // ---------------------------------------------------------------------------- 
     51  //  2. Handle any exclusive arguments 
     52  // ---------------------------------------------------------------------------- 
     53 
     54  //  The resumptionToken argument is exclusive 
     55  if (params["resumptionToken"] != "") 
     56  { 
     57    // This argument is exclusive, so no other arguments are allowed (except "verb" of course) 
     58    if (params.getSize() != 2) 
     59    { 
     60      this->errorType = "badArgument"; 
     61      return false; 
     62    } 
     63 
     64    // Check the resumption token is valid 
     65    ResumptionToken token(params["resumptionToken"]); 
     66    if (token.isValid()) 
     67    { 
     68      // Everything is fine, and we don't continue further because this is an exclusive argument 
     69      this->errorType = ""; 
     70      return true; 
     71    } 
     72    else 
     73    { 
     74      // There was an error with the resumption token 
     75      this->errorType = "badResumptionToken"; 
     76      return false; 
     77    } 
     78  } 
     79 
     80  // ---------------------------------------------------------------------------- 
     81  //  3. Handle any required arguments 
     82  // ---------------------------------------------------------------------------- 
     83 
     84  // OAI v2.0 requires metadataPrefix 
     85  if (this->configuration->getOAIVersion() > 110) 
     86  { 
     87    text_t metadataPrefix = params["metadataPrefix"]; 
     88 
     89    // Check that the metadataPrefix argument exists 
     90    if (metadataPrefix == "") 
     91    { 
     92      this->errorType = "badArgument"; 
     93      return false; 
     94    } 
     95    // Check that the metadataPrefix is a format we support 
     96    if (this->formatNotSupported(metadataPrefix)) 
     97    { 
     98      this->errorType = "cannotDisseminateFormat"; 
     99      return false; 
     100    } 
     101  } 
     102 
     103  // ---------------------------------------------------------------------------- 
     104  // 4. Check any remaining arguments 
     105  // ---------------------------------------------------------------------------- 
     106 
     107  // Check "from" and "until" arguments 
     108  if (params["from"] != "" || params["until"] != "") 
     109  { 
     110    text_t from  = params["from"]; 
     111    text_t until = params["until"]; 
     112 
     113    // Check the from date is in the correct format: YYYY-MM-DD 
     114    if (from != "") 
     115    { 
     116      // Must be in the form YYYY-MM-DD 
     117      if (from.size() != 10 || from[4] != '-' || from[7] != '-') 
     118      { 
     119    this->errorType = "badArgument"; 
     120    params.erase("from"); 
     121      } 
     122    } 
     123    // Check the until date is in the correct format: YYYY-MM-DD 
     124    if (until != "") 
     125    { 
     126      // Must be in the form YYYY-MM-DD 
     127      if (until.size() != 10 || until[4] != '-' || until[7] != '-') 
     128      { 
     129    this->errorType = "badArgument"; 
     130    params.erase("until"); 
     131      } 
     132    } 
     133 
     134    if (this->errorType == "badArgument") 
     135    { 
     136      return false; 
     137    } 
     138 
     139    // If both arguments are supplied the from date must be less than or equal to the until date 
     140    if (from != "" && until != "" && !(from <= until)) 
     141    { 
     142      this->errorType = "badArgument"; 
     143      return false; 
     144    } 
     145  } 
     146 
     147  // Check "set" argument 
     148  if (params["set"] != "") 
     149  { 
     150    // Example set specification: "demo:CL2" 
     151    text_t set = params["set"]; 
     152 
     153    // given 'demo:CL2', toGSDL returns 'demo' in collection and 'CL2' in set. If there is no further 
     154    // set specified after the name of the collection however, then set is empty. 
     155    text_t collection = ""; 
     156    oaiclassifier::toGSDL(collection, set); 
     157 
     158    // Check that the collection is accessible 
     159    ColInfoResponse_t cinfo; 
     160    comerror_t err; 
     161    protocol->get_collectinfo(collection, cinfo, err, cerr); 
     162    if (err != noError) 
     163    { 
     164      this->errorType = "badArgument"; 
     165      return false; 
     166    } 
     167 
     168    // Check the collection is one that is in the list in the oai.cfg file 
     169    text_tarray &collections = this->configuration->getCollectionsList(); 
     170    bool collection_found = false; 
     171    for (int c = 0; c < collections.size(); c++) 
     172    { 
     173      if (collections[c] == collection) 
     174      { 
     175    collection_found = true; 
     176    break; 
     177      } 
     178    } 
     179 
     180    // The collection was not found 
     181    if (!collection_found) 
     182    { 
     183      this->errorType = "badArgument"; 
     184      return false; 
     185    } 
     186 
     187    // Check the child set if it was given 
     188    if (set != "" && !this->check_classifier(protocol, collection, set)) 
     189    { 
     190      this->errorType = "badArgument"; 
     191      return false; 
     192    } 
     193  } 
     194 
     195  // If we've reached here everything must be fine 
     196  this->errorType = ""; 
     197  return true; 
    9198} 
    10199