Changeset 15198


Ignore:
Timestamp:
2008-04-17T13:52:05+12:00 (14 years ago)
Author:
mdewsnip
Message:

Now each action checks for invalid arguments in the params structure and deletes any that aren't valid, so they don't get into the "<request>" tag in the resulting XML and cause OAI validation errors. By DL Consulting Ltd.

Location:
gsdl/trunk/src/oaiservr
Files:
7 edited

Legend:

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

    r11733 r15198  
    66bool abstractlistaction::validateAction(recptproto *protocol, oaiargs &params, int &numArgs)
    77{
     8  // Remove any parameters that aren't valid for this action
     9  text_tmap::const_iterator param_iterator = params.begin();
     10  while (param_iterator != params.end())
     11  {
     12    if (param_iterator->first != "verb" &&
     13    param_iterator->first != "from" &&
     14    param_iterator->first != "until" &&
     15    param_iterator->first != "set" &&
     16    param_iterator->first != "resumptionToken" &&
     17    param_iterator->first != "metadataPrefix")
     18    {
     19      params.erase(param_iterator->first);
     20    }
     21
     22    param_iterator++;
     23  }
     24
    825  text_t from  = params["from"];
    926  text_t until = params["until"];
     
    1936    if(from.size() != 10){
    2037      this->errorType = "badArgument";
    21       return false;
     38      params.erase("from");
    2239    }
    2340    else{
    2441      if(from[4] != '-' || from[7] != '-'){
    2542    this->errorType = "badArgument";
    26     return false;
     43    params.erase("from");
    2744      }
    2845    }
     
    3451    if(until.size() != 10){
    3552      this->errorType = "badArgument";
    36       return false;
     53      params.erase("until");
    3754    }
    3855    else{
    3956      if(until[4] != '-' || until[7] != '-'){
    4057    this->errorType = "badArgument";
    41     return false;
     58    params.erase("until");
    4259      }
    4360    }
    4461    ++numArgs; // Increase valid args count
     62  }
     63
     64  if (this->errorType == "badArgument")
     65  {
     66    return false;
    4567  }
    4668
  • gsdl/trunk/src/oaiservr/identityaction.cpp

    r15193 r15198  
    44bool identityaction::validateAction(recptproto *protocol, oaiargs &params)
    55{
     6  int params_size = params.getSize();
     7
     8  // Remove any parameters that aren't valid for this action
     9  text_tmap::const_iterator param_iterator = params.begin();
     10  while (param_iterator != params.end())
     11  {
     12    if (param_iterator->first != "verb")
     13    {
     14      params.erase(param_iterator->first);
     15    }
     16
     17    param_iterator++;
     18  }
     19 
    620  //"Verb=Identify" should be the only parameter - if there are others, throw an error.
    721  // Don't need to check that the param we have is "Verb=Identify", as it has to be to get to here.
    8  
    9   if(params.getSize() != 1){
     22  if(params_size != 1){
    1023    this->errorType = "badArgument";
    1124    return false;
  • gsdl/trunk/src/oaiservr/listidsaction.cpp

    r8310 r15198  
    77bool listidsaction::validateAction(recptproto *protocol, oaiargs &params)
    88{
     9  int params_size = params.getSize();
    910  int numArgs  = 1; // For "verb" arg
    1011
     
    1516  // In OAI v1.1 metadataPrefix is not allowed.
    1617  if (this->configuration->getOAIVersion() <= 110){
    17     if(numArgs != params.getSize()){
     18    if(numArgs != params_size){
    1819      this->errorType = "badArgument";
    1920      return false;
     
    2728    }
    2829    else { // If it isn't empty, increase the valid args count and compare this to the total num of args
    29       if (++numArgs != params.getSize()){
     30      if (++numArgs != params_size){
    3031    this->errorType = "badArgument";
    3132    return false;
  • gsdl/trunk/src/oaiservr/listrecsaction.cpp

    r9608 r15198  
    66bool listrecsaction::validateAction(recptproto *protocol, oaiargs &params)
    77{
     8  int params_size = params.getSize();
     9
    810  text_t meta    = params["metadataPrefix"];
    911  int    numArgs = 1;                // 1st arg (Verb=ListRecords) must be present for us to be here
     
    2628  // The number of valid args should be exactly equal to the number of args actually there.
    2729  // If not, throw a 'badArgument' error.
    28   if (numArgs != params.getSize()) {
     30  if (numArgs != params_size) {
    2931    this->errorType = "badArgument";
    3032    return false;
  • gsdl/trunk/src/oaiservr/listsetsaction.cpp

    r11311 r15198  
    1111
    1212bool listsetsaction::validateAction(recptproto *protocol, oaiargs &params)
    13 { if(params.getSize() != 1){
     13{
     14  int params_size = params.getSize();
     15
     16  // Remove any parameters that aren't valid for this action
     17  text_tmap::const_iterator param_iterator = params.begin();
     18  while (param_iterator != params.end())
     19  {
     20    if (param_iterator->first != "verb")
     21    {
     22      params.erase(param_iterator->first);
     23    }
     24
     25    param_iterator++;
     26  }
     27
     28  if(params_size != 1){
    1429    this->errorType = "badArgument";
    1530    return false;
  • gsdl/trunk/src/oaiservr/metaformatsaction.cpp

    r9608 r15198  
    55bool metaformatsaction::validateAction(recptproto *protocol, oaiargs &params)
    66{
     7  int params_size = params.getSize();
     8
     9  // Remove any parameters that aren't valid for this action
     10  text_tmap::const_iterator param_iterator = params.begin();
     11  while (param_iterator != params.end())
     12  {
     13    if (param_iterator->first != "verb" &&
     14    param_iterator->first != "identifier")
     15    {
     16      params.erase(param_iterator->first);
     17    }
     18
     19    param_iterator++;
     20  }
     21
    722  int numArgs = 1; // the number of expected arguments
    823 
     
    1530  // If the total number of params isn't equal to the number of valid
    1631  // args (i.e. we have an arg but it isn't the identifier), throw an error 
    17   if((params.getSize() != numArgs)){
     32  if((params_size != numArgs)){
    1833    this->errorType = "badArgument";
    1934    return false;
  • gsdl/trunk/src/oaiservr/recordaction.cpp

    r11311 r15198  
    2929
    3030bool recordaction::validateAction(recptproto *protocol, oaiargs &params)
    31 { text_t meta = params["metadataPrefix"];
     31{
     32  int params_size = params.getSize();
     33
     34  // Remove any parameters that aren't valid for this action
     35  text_tmap::const_iterator param_iterator = params.begin();
     36  while (param_iterator != params.end())
     37  {
     38    if (param_iterator->first != "verb" &&
     39    param_iterator->first != "identifier" &&
     40    param_iterator->first != "metadataPrefix")
     41    {
     42      params.erase(param_iterator->first);
     43    }
     44
     45    param_iterator++;
     46  }
     47
     48  text_t meta = params["metadataPrefix"];
    3249  text_t gsdlId = params["identifier"];
    3350  text_t gsdlCollect;
     
    3754  // The identifier and metadataPrefix args MUST be supplied, and are the only
    3855  // args allowed (excluding verb arg). If we don't have them, throw an error.
    39   if(gsdlId == "" || meta == "" || params.getSize() != 3){
     56  if(gsdlId == "" || meta == "" || params_size != 3){
    4057    this->errorType = "badArgument";
    4158    return false;
Note: See TracChangeset for help on using the changeset viewer.