So it looks like the curlpp examples are working, but the program I
need to work still isn't. Here's the code, what in here would make
perform() die?
Note: perform() also dies if I comment out all the options except
host.
//--------------------------------------------------------------------
// Includes
//--------------------------------------------------------------------
#include "verisign_io.h"
#include "file_io.h"
#include "error_lib.h"
#include "logging.h"
#include "toolkit.h"
#include "parm.h"
//using current time in seconds and credit card number for unique
transaction id
#include <time.h>
#include <string>
#include <sstream>
#include <iostream>
//#include "curl/curl.h"
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>
#ifdef CGI_VERSION
#include "cgic.h"
#endif
//
*********************************************************************
// Global Functions
//
*********************************************************************
//--------------------------------------------------------------------
// GetValueFromResponseString
//--------------------------------------------------------------------
bool GetValueFromResponseString (const char* key,
TString& value,
TString responseString)
{
char* startPtr = NULL;
char* endPtr = NULL;
size_t offset = 0;
size_t length = 0;
value = "";
startPtr = responseString.Find (key);
if (startPtr)
{
startPtr += strlen(key);
offset = responseString.PointerToOffset (startPtr);
endPtr = responseString.Find ("&", true, offset);
if (endPtr)
length = endPtr - startPtr;
else
length = strlen(startPtr);
value = responseString.SubString(offset,length);
}
return (startPtr != NULL);
}
//--------------------------------------------------------------------
// CallVerisign
//--------------------------------------------------------------------
bool CallVerisign (const TDBSplitReport* dbObjPtr,
TString creditCardNumber,
TString expirationDate,
float amount,
TString customerZipCode,
TString customerAddress,
TString authorizationCode,
TString transactionType,
TString comment,
TString& answerText,
TString& referenceID)
{
bool success = false;
bool isTest = false;
//int verisignContext;
int resultCode;
TString localAmount;
TString verisignArgs;
TString responseMessage;
//TString referenceID;
TString tmpString;
TString responseString;
TString logEntry;
//char *responseBuffer;
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tAbout to setup
environment");
// Setup the environment so it can find the certificate
setenv("PFPRO_CERT_PATH", "/usr/local/verisign/payflowpro/
linux/certs", 1);
// Nullify the answer text
answerText = "";
// Adjust some arguments
creditCardNumber.NumbersOnly();
expirationDate.NumbersOnly();
customerZipCode.NumbersOnly();
if (customerZipCode.IsEmpty())
customerZipCode = "99999";
customerZipCode = customerZipCode.SubString(0,5);
if (comment.IsEmpty())
comment = "---";
comment = comment.SubString(0,18);
localAmount.CopyFrom(amount,2);
// convert expiration from YYYY to MMYY format
tmpString = expirationDate;
expirationDate = tmpString.SubString(4,2);
expirationDate += tmpString.SubString(2,2);
// setup the log entry
logEntry = "Verisign Transaction\t";
logEntry += transactionType;
logEntry += "\t";
logEntry += comment;
logEntry += "\t";
logEntry += localAmount;
logEntry += "\t";
tmpString = creditCardNumber.SubString(0,1);
tmpString += "-";
tmpString += creditCardNumber.SubString(0,4,true);
logEntry += tmpString;
logEntry += "\t";
logEntry += expirationDate;
logEntry += "\t";
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tEntering Try");
try{
if (strcasecmp(creditCardNumber,kTestCreditCardNumber) == 0)
{
isTest = true;
//answerText = kApprovedPrefixString;
answerText += "987654321";
}
else
{
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tNot A Test");
// Build up the application's piped arguments
verisignArgs += "TRXTYPE=";
verisignArgs += transactionType;
verisignArgs += "&TENDER=C";
verisignArgs += "&PARTNER=";
verisignArgs += kVerisignPartner;
verisignArgs += "&VENDOR=";
verisignArgs += kVerisignVendor;
verisignArgs += "&USER=";
verisignArgs += kVerisignUser;
verisignArgs += "&PWD=";
verisignArgs += kVerisignPassword;
verisignArgs += "&ACCT=";
verisignArgs += creditCardNumber;
verisignArgs += "&EXPDATE=";
verisignArgs += expirationDate;
verisignArgs += "&AMT=";
verisignArgs += localAmount;
verisignArgs += "&COMMENT1[";
verisignArgs += comment.GetLength();
verisignArgs += "]=";
verisignArgs += comment;
verisignArgs += "&STREET[";
verisignArgs += customerAddress.GetLength();
verisignArgs += "]=";
verisignArgs += customerAddress;
verisignArgs += "&ZIP=";
verisignArgs += customerZipCode;
verisignArgs += "\r\n";
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tArgs Set Up");
//Using credit card number and time in seconds to
create unique id
char uniqueID[64];
strcpy(uniqueID, creditCardNumber);
sprintf(uniqueID, "%s%ld", uniqueID, time(NULL));
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tBuilt Unique ID");
//set the headers.
std::list<std::string> headers;
headers.push_back("Content-Type: text/namevalue");
headers.push_back("Content-Length: " +
verisignArgs.GetLength());
headers.push_back("X-VPS-Timeout: 45");
headers.push_back("X-VPS-Request_ID:" + std::string
(uniqueID));
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tRest Of Headers Set");
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tInit Curl");
cURLpp::Cleanup myCleanup;
cURLpp::Easy myRequest;
myRequest.setOpt(new cURLpp::Options::Url
(kVerisignHost));
myRequest.setOpt(new cURLpp::Options::Port
(kVerisignPort));
myRequest.setOpt(new cURLpp::Options::Timeout
(kVerisignTimeout));
myRequest.setOpt(new cURLpp::Options::Header(1));
myRequest.setOpt(new cURLpp::Options::FollowLocation
(0));
myRequest.setOpt(new cURLpp::Options::SslVerifyPeer
(0));
myRequest.setOpt(new cURLpp::Options::SslVerifyHost
(2));
myRequest.setOpt(new cURLpp::Options::ForbidReuse
(true));
myRequest.setOpt(new cURLpp::Options::Post(1));
myRequest.setOpt(new cURLpp::Options::HttpHeader
(headers));
myRequest.setOpt(new cURLpp::Options::PostFields
(std::string(verisignArgs)));
myRequest.setOpt(new cURLpp::Options::UserAgent
("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/
20070725 Firefox/2.0.0.6"));
//myRequest.setOpt(new cURLpp::Options::Verbose
(true));
std::ostringstream responseBuffer;
//AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tSet up output stream.
About to perform shorthand version");
//responseBuffer << myRequest;
cURLpp::Options::WriteStream ws(&responseBuffer);
myRequest.setOpt(ws);
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tSet up output stream. About
to perform");
// cout << "Content-type: text/plain" << endl << endl;
myRequest.perform();
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tPerformed request");
const char* temp = responseBuffer.str().c_str();
responseString.CopyFrom(temp);
AddLogEntry(dbObjPtr, "INFO\tVerisign.cc\tSet Response String");
if (! responseString.IsEmpty())
{
// get the reponse code
if ( GetValueFromResponseString
(kVSResponseFieldResult,tmpString, responseString) )
{
resultCode =
tmpString.AsSInt();
GetValueFromResponseString(kVSResponseFieldRespMsg,responseMessage,
responseString);
GetValueFromResponseString(kVSResponseFieldPnref,referenceID,
responseString);
if (resultCode == 0)
{
// approved
GetValueFromResponseString(kVSResponseFieldAuthCode, answerText,
responseString);
success =
true;
logEntry +=
"\tAuthorized";
logEntry +=
"\t";
logEntry +=
answerText;
logEntry +=
"\t";
logEntry +=
referenceID;
}
else if (resultCode >
0)
{
// declined
answerText +=
resultCode;
answerText +=
": ";
answerText +=
responseMessage;
logEntry +=
"\tDeclined";
logEntry +=
"\t";
logEntry +=
resultCode;
logEntry +=
"\t";
logEntry +=
referenceID;
logEntry +=
"\t";
logEntry +=
responseMessage;
}
else
{
// errror
answerText +=
resultCode;
answerText +=
": ";
answerText +=
responseMessage;
logEntry +=
"\tDeclined";
logEntry +=
"\t";
logEntry +=
resultCode;
logEntry +=
"\t";
logEntry +=
referenceID;
logEntry +=
"\t";
logEntry +=
responseMessage;
}
}
}
else
{
answerText += "Received empty
response from Verisign client.";
logEntry += "\tError";
logEntry += "\t";
logEntry += answerText;
}
}
}
catch( cURLpp::RuntimeError &e){
logEntry += "\tError\t";
logEntry += e.what();
logEntry += "\t";
AddLogEntry(dbObjPtr, "Runtime Error");
}
catch( cURLpp::LogicError &e ){
logEntry += "\tError\t";
logEntry += e.what();
logEntry += "\t";
AddLogEntry(dbObjPtr, "Logic Error");
}
catch(...){
AddLogEntry(dbObjPtr, "General Error");
}
AddLogEntry(dbObjPtr,logEntry);
return success;
}
Thanks,
Brandon
On Aug 14, 9:43 am, Jean-Philippe Barette-LaPierre
<[email protected]> wrote:
> On Fri, Aug 14, 2009 at 8:54 AM, tatebn <[email protected]> wrote:
>
> > Where do I get the version of cURLpp that uses libcurl.so.2?
>
> Well, on the website, except of windows, there's no binary distribution of
> cURLpp. Some distributions offers it, but it's rare.
> Most probably, one of your co-worker compiled it himself and installed it.
> You need to recompile it with the right library.
>
>
>
> > On Aug 14, 8:31 am, Jean-Philippe Barette-LaPierre
> > <[email protected]> wrote:
> > > If I understand correctly:
>
> > > libcURL is now linked to libcurl.so.2 because you did something
> > different.
> > > Now you need to
> > > do the same thing for cURLpp. Then, libcurl, curpp and your program will
> > be
> > > linked to the
> > > same library.
>
> > > On Fri, Aug 14, 2009 at 12:03 AM, tatebn <[email protected]> wrote:
>
> > > > Alright, this is getting absolutely out of control.
>
> > > > getting this still
>
> > > > /usr/bin/ld: warning: libssl.so.2, needed by /usr/lib/libcurl.so.4,
> > > > may conflict with libssl.so.4
> > > > /usr/bin/ld: warning: libcrypto.so.2, needed by /usr/lib/libcurl.so.4,
> > > > may conflict with libcrypto.so.4
>
> > > > However, if I downgrade libcrypto.so.4 to libcrypto.2 I get this
>
> > > > /usr/bin/ld: warning: libssl.so.4, needed by /usr/lib/gcc-lib/i386-
> > > > redhat-linux/3.2.2/../../../libcurlpp.so, may conflict with libssl.so.
> > > > 2
> > > > /usr/bin/ld: warning: libcrypto.so.4, needed by /usr/lib/gcc-lib/i386-
> > > > redhat-linux/3.2.2/../../../libcurlpp.so, may conflict with
> > > > libcrypto.so.2
>
> > > > So as far as I can tell, libcurl needs .so.2 of both of those files,
> > > > but libcurlpp needs .so.4
> > > > But libcurlpp also needs libcurl so this is just a cycle of not
> > > > working things.
>
> > > > For the love of God, help me. Maybe point me at some definitive
> > > > versions of all these libraries that will work?
>
> > > > On Aug 13, 10:43 am, Jean-Philippe Barette-LaPierre
> > > > <[email protected]> wrote:
> > > > > On Thu, Aug 13, 2009 at 10:36 AM, tatebn <[email protected]>
> > wrote:
>
> > > > > > > Try to remove the ostringstream usage, it will just print on the
> > > > stdout.
> > > > > > > Then, we'll be able to
> > > > > > > know if it's the WriteStream which is the offender or something
> > else.
>
> > > > > > I just get a plain white screen. Nothing printed.
>
> > > > > > > Can you tell which version
> > > > > > > of libcurl and cURLpp you're using?
>
> > > > > > cURLpp: Latest stable version as of about 2 weeks ago
> > > > > > libcurl: Not entirely sure.
>
> > > > > > I got these warnings when compiling though. Not sure if this could
> > be
> > > > > > the issue or not. Nor would I know how to fix it. I'm not a unix
> > > > > > noobie, but I'm not a guru either.
>
> > > > > > /usr/bin/ld: warning: libssl.so.2, needed by /usr/lib/gcc-lib/i386-
> > > > > > redhat-linux/3.2.2/../../../libcurl.so, may conflict with
> > libssl.so.4
> > > > > > /usr/bin/ld: warning: libcrypto.so.2, needed by
> > /usr/lib/gcc-lib/i386-
> > > > > > redhat-linux/3.2.2/../../../libcurl.so, may conflict with
> > libcrypto.so.
> > > > > > 4
>
> > > > > Honestly I wouldn't even try to debug the cURLpp code without fixing
> > > > those
> > > > > issues first. This has a very high probability to be the source of
> > your
> > > > > problems.
>
> > > > > You can send an email to libcurl mailing-list (they got a way much
> > > > larger
> > > > > audience). However, you should send here and there the description of
> > > > > your libraries setup. Why do you have two libssl.so libraries
> > installed?
> > > > > Where are they installed? Have you checked which versions are needed
> > > > > by libcurl? If you need a specific one, you can give to configure an
> > > > option
> > > > > to select a specific one.
>
> > > > > libcurl mailing-list:
> >http://cool.haxx.se/mailman/listinfo/curl-library
>
> > > > > > On Aug 13, 10:11 am, Jean-Philippe Barette-LaPierre
> > > > > > <[email protected]> wrote:
> > > > > > > On Thu, Aug 13, 2009 at 9:44 AM, tatebn <[email protected]>
> > > > wrote:
>
> > > > > > > > > As far as using ostringstream
> > > > > > > > > goes, as soon as that response comes back from reform it's
> > > > converted
> > > > > > > > > to a TString which won't accept a string.'
>
> > > > > > > > the reponse come back from perform() not reform. Sorry.
>
> > > > > > > Try to remove the ostringstream usage, it will just print on the
> > > > stdout.
> > > > > > > Then, we'll be able to
> > > > > > > know if it's the WriteStream which is the offender or something
> > else.
> > > > Can
> > > > > > > you tell which version
> > > > > > > of libcurl and cURLpp you're using?
>
> > > > > > > > On Aug 13, 9:42 am, tatebn <[email protected]> wrote:
> > > > > > > > > How complete an example? I think this is all the curl related
> > > > stuff,
> > > > > > > > > would you need to whole file?
>
> > > > > > > > > > > //Using credit card number and time in seconds to create
> > > > unique
> > > > > > id
> > > > > > > > > > > char uniqueID[64];
> > > > > > > > > > > strcpy(uniqueID, creditCardNumber);
> > > > > > > > > > > sprintf(uniqueID, "%s%ld", uniqueID,
> > > > time(NULL));
>
> > > > > > > > > > Since you used ostringstream already below, why don't you
> > use
> > > > it
> > > > > > here?
>
> > > > > > > > > I used this method because there was an issue in that
> > > > > > creditCardNumber
> > > > > > > > > is a TString which is a custom class that I did not create
> > nor
> > > > know
> > > > > > > > > where to find. I didn't build this system, I just have to
> > take
> > > > care
> > > > > > > > > of this part of it. TString was causing all sorts of type
> > issues
> > > > and
> > > > > > > > > this is how it ended up working out. As far as using
> > > > ostringstream
> > > > > > > > > goes, as soon as that response comes back from reform it's
> > > > converted
> > > > > > > > > to a TString which won't accept a string. So this keeps
> > > > everything
> > > > > > > > > more conformed.
>
> > > > > > > > > I'll remove the cleanup class, but this is dying at
> > perform(). I
> > > > > > > > > traced it out with log statements that I didn't include here.
> > So
> > > > let
> > > > > > > > > me know what you need from me, complete function? complete
> > file?
> > > > and
> > > > > > > > > I'll get it up here later today.
>
> > > > > > > > > Thanks a lot. I'm on a tight deadline here and I'm stumped.
>
> > > > > > > > > On Aug 13, 9:11 am, Jean-Philippe Barette-LaPierre
>
> > > > > > > > > <[email protected]> wrote:
> > > > > > > > > > On Wed, Aug 12, 2009 at 8:58 PM, tatebn <
> > > > [email protected]>
> > > > > > > > wrote:
>
> > > > > > > > > > > I'm using curlpp to communicate with paypal. I'm having
> > an
> > > > issue
> > > > > > > > > > > where when the perform() function is called my cgi dies.
> > No
> > > > > > error,
> > > > > > > > > > > nothing.
>
> > > > > > > > > > > I'm really under the gun here. Any help would be greatly
> > > > > > > > appreciated.
>
> > > > > > > > > > The best thing would be to have a complete example which
> > would
> > > > be a
> > > > > > > > small
> > > > > > > > > > as possible that you could send. Then we would be more able
> > to
> > > > > > > > reproduce
> > > > > > > > > > and test. However I can point to possible mistakes
>
> > > > > > > > > > > Here's what I'm doing:
>
> > > > > > > > > > > //Using credit card number and time in seconds to create
> > > > unique
> > > > > > id
> > > > > > > > > > > char uniqueID[64];
> > > > > > > > > > > strcpy(uniqueID, creditCardNumber);
> > > > > > > > > > > sprintf(uniqueID, "%s%ld", uniqueID,
> > > > time(NULL));
>
> > > > > > > > > > Since you used ostringstream already below, why don't you
> > use
> > > > it
> > > > > > here?
>
> > > > > > > > > > > //set the headers.
> > > > > > > > > > > std::list<std::string> headers;
> > > > > > > > > > > headers.push_back("Content-Type:
> > > > text/namevalue");
> > > > > > > > > > > headers.push_back("Content-Length: " +
> > > > > > > > > > > verisignArgs.GetLength());
> > > > > > > > > > > headers.push_back("X-VPS-Timeout: 45");
> > > > > > > > > > > headers.push_back("X-VPS-Request_ID:" +
> > > > > > std::string
> > > > > > > > > > > (uniqueID));
>
> > > > > > > > > > > cURLpp::Cleanup myCleanup;
>
> > > > > > > > > > Don't use cleanup class. That is meant to be removed from
> > API
>
> > > > > > > > > > > cURLpp::Easy myRequest;
> > > > > > > > > > > myRequest.setOpt(new cURLpp::Options::Url
> > > > > > > > > > > (kVerisignHost));
> > > > > > > > > > > myRequest.setOpt(new cURLpp::Options::Port
> > > > > > > > > > > (kVerisignPort));
> > > > > > > > > > > myRequest.setOpt(new
> > cURLpp::Options::Timeout
> > > > > > > > > > > (kVerisignTimeout));
> > > > > > > > > > > myRequest.setOpt(new
> > > > cURLpp::Options::Header(1));
> > > > > > > > > > > myRequest.setOpt(new
> > > > > > cURLpp::Options::FollowLocation
> > > > > > > > > > > (0));
> > > > > > > > > > > myRequest.setOpt(new
> > > > > > cURLpp::Options::SslVerifyPeer
> > > > > > > > > > > (0));
> > > > > > > > > > > myRequest.setOpt(new
> > > > > > cURLpp::Options::SslVerifyHost
> > > > > > > > > > > (2));
> > > > > > > > > > > myRequest.setOpt(new
> > > > cURLpp::Options::ForbidReuse
> > > > > > > > > > > (true));
> > > > > > > > > > > myRequest.setOpt(new
> > > > cURLpp::Options::Post(1));
> > > > > > > > > > > myRequest.setOpt(new
> > > > cURLpp::Options::HttpHeader
> > > > > > > > > > > (headers));
> > > > > > > > > > > myRequest.setOpt(new
> > > > cURLpp::Options::PostFields
> > > > > > > > > > > (std::string(verisignArgs)));
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"curlpp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/curlpp?hl=en
-~----------~----~----~----~------~----~------~--~---