Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ippErrorResponse.cpp

Go to the documentation of this file.
00001 // 
00002 // DISCLAIMER: 
00003 //  This software was produced by the National Institute of Standards 
00004 //  and Technology (NIST), an agency of the U.S. government, and by statute is 
00005 //  not subject to copyright in the United States.  Recipients of this 
00006 //  software assume all responsibility associated with its operation,
00007 //  modification,maintenance, and subsequent redistribution. 
00008 //
00009 //  See NIST Administration Manual 4.09.07 b and Appendix I. 
00010 //
00011 #include "stdafx.h"
00012 #include "ippdme/Response/ippErrorResponse.h"
00013 #include "ippdme/ippError.h"
00014 #include "ippdme/Command/ippGetErrorInfoCommand.h"
00015 #include "ippdme/misc/ippStringBuilder.h"
00016 
00017 
00018 /* ippErrorResponse::ippErrorResponse ***************************************
00019 
00020 This uses the inErrorName to calculate an index into the allErrors
00021 array.
00022 
00023 */
00024 
00025 
00026 static void replaceQuotes(const char * in,char* out,int nbsize)  {
00027   
00028   int n = strlen(in);
00029   if ( in[n-2] == '\r'  && in[n-1] == '\n') {
00030     n -=2;
00031   }
00032   bool bEllipsis = false;
00033   if (n > nbsize  - 10) { 
00034      n = 100;
00035      bEllipsis = true;
00036   }
00037   int quoteCount = 0;
00038   int j=0;
00039   for(int i=0; i<n; i++) {
00040     if(in[i] == '\r') {
00041       out[j++]='\\';
00042       out[j++]='r';
00043     } else if(in[i] == '\n') {
00044       out[j++]='\\';
00045       out[j++]='n';
00046     } else if(in[i] < ' ') {
00047       out[j++]='?';
00048     } else    if(in[i] == '"') {
00049       out[j++]='#';
00050     } else {
00051       out[j++]=in[i];
00052     }
00053   }
00054   if (bEllipsis) { 
00055     out[j++]='.';
00056     out[j++]='.';
00057     out[j++]='.';
00058   }
00059   out[j++] =0;
00060 }
00061 
00062 
00063 
00064 ippErrorResponse::ippErrorResponse(
00065   unsigned int inTagNumber,
00066   tagIdType inTagType,
00067   ippErrorNameType inErrorName, 
00068   const char * inErrorCausingMethod
00069 ) 
00070   : ippResponse(inTagNumber, inTagType, ErrorError)
00071   , _theError(inErrorName)
00072 {
00073   static char tmp[100];
00074   replaceQuotes(inErrorCausingMethod,tmp,sizeof(tmp));
00075   _errorCausingMethod = tmp;
00076 }
00077 ippErrorResponse::ippErrorResponse(
00078   const ippTag& tag,
00079   ippErrorNameType inErrorName, 
00080   const char * inErrorCausingMethod
00081 ) 
00082   : ippResponse(tag.getTagNumber(), tag.getTagType(), ErrorError)
00083   , _theError(inErrorName)
00084 {
00085   static char tmp[100];
00086   replaceQuotes(inErrorCausingMethod,tmp,sizeof(tmp));
00087   _errorCausingMethod = tmp;
00088 }
00089 
00090 ippErrorResponse::~ippErrorResponse()
00091 {
00092 }
00093 
00094 std::string ippErrorResponse::getResponseString() const
00095 {  
00096   ippStringBuilder builder(_tag,"!");
00097   builder.StartFunc("Error");
00098     std::string str_severity=" ";
00099     str_severity.at(0) =_theError.getSeverity()  ;
00100     builder.Append(str_severity.c_str());
00101 
00102     builder.Append(", ");
00103     builder.AppendParam(_theError.getName());
00104     builder.AppendParam(_errorCausingMethod);
00105     builder.AppendParam(_theError.getText());
00106   builder.EndFunc();
00107   return builder.ToString();
00108 }

Generated on Wed Nov 8 00:20:06 2006 for IPPDME by  doxygen 1.4.1