cURL / Mailing Lists / curl-library / Single Mail

curl-library

Please HELP. Cant even get Debug function to work

From: Crypt Master <cryptmaster_at_hotmail.com>
Date: Mon, 24 Nov 2003 16:32:08 +0000

Hi

I am having serious issues with libcurl 7.10.7. It is compiled on my box, a
win2k machine with VC6. The command used to compile it is as follows: nmake
-f makefile.vc6 -CFG=release-dll. There are no problems with this as far as
I can see. SSL is not used.

I get acceptable results on my machine usually, but on other machines also
win2k boxes it doesnt work even when copying the dll from my box where it
does. It simply memory violates during the perform which is doing an HTTP
post. I am trying to get DEBUG verbosing to work to provide more information
to this group, but even that is memory violating. If I turn on debugging and
provide an empty debug function, the perform violates. If I turn off the
debug function it works fine. Since the debug function is blank I cant see
it being a problem with the debug function. I have included my code below so
you can hopefully spot whatever I am doing wrong here, if you would be so
kind. It falls over on the easy perform. The debug function is at the bottom
of the code dump, it just returns 0:

Thanks,

   /************************************************************************
    * Variable declarations
    
************************************************************************/

    ID idReturnValue = ER_SUCCESS;
    CURLcode curlCode = CURLE_OK;
    CURL* easyhandle = NULL;
    char* outputXML = NULL;
        char* urlEncodedStr = NULL;
        char errorText[255] = {0};
        LPTSTR errorMsg = NULL;
// char* szLibPath =
"c:\\b7\\system\\bin32\\libcurl.dll";
        char* szLibPath = "libcurl";

        HINSTANCE hLibCurl = NULL;
        curl_easy_init_proc curl_easy_init = NULL;
    curl_easy_setopt_proc curl_easy_setopt = NULL;
        curl_easy_perform_proc curl_easy_perform = NULL;
        curl_easy_cleanup_proc curl_easy_cleanup = NULL;
    curl_global_init_proc curl_global_init = NULL;
        curl_global_cleanup_proc curl_global_cleanup = NULL;
    curl_escape_proc curl_escape = NULL;
    curl_free_proc curl_free = NULL;

   /************************************************************************
    * Main Processing
    
************************************************************************/

        /* Prepare the output xml - As a URL paramter called xml
servelt?xml=<XMLSTR> */
    I550001_AppendStr(&outputXML, servletParams);
    I550001_AppendStr(&outputXML, urlEncodedStr);*/

        /* Load CURL library */
        jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----B4-LoadLibrary");

    hLibCurl = LoadLibrary(szLibPath);

    /* Get the proc Addresses */
        if (hLibCurl != NULL)
        {
              jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----B4-GetProcAddresses");

       curl_easy_init = (curl_easy_init_proc)
GetProcAddress(hLibCurl, "curl_easy_init");
       curl_easy_setopt = (curl_easy_setopt_proc)
GetProcAddress(hLibCurl, "curl_easy_setopt");
       curl_easy_perform = (curl_easy_perform_proc)
GetProcAddress(hLibCurl, "curl_easy_perform");
       curl_easy_cleanup = (curl_easy_cleanup_proc)
GetProcAddress(hLibCurl, "curl_easy_cleanup");
       curl_global_init = (curl_global_init_proc)
GetProcAddress(hLibCurl, "curl_global_init");
       curl_global_cleanup = (curl_global_cleanup_proc)
GetProcAddress(hLibCurl, "curl_global_cleanup");
       curl_escape = (curl_escape_proc)
GetProcAddress(hLibCurl, "curl_escape");

           if (curl_easy_init == NULL ||
           curl_easy_setopt == NULL ||
                   curl_easy_perform == NULL ||
                   curl_escape == NULL ||
                   curl_global_init == NULL ||
                   curl_global_cleanup == NULL ||
           curl_easy_cleanup == NULL)
           {
                   idReturnValue = ER_ERROR;
           jdeWriteLogEntry(JDELOG, "CURLERROR", "CURLERROR", 212, 0, "CURL
Get Proc Address failed. Check you have the correct library installed");
           }

        }
        else
        {
                idReturnValue = ER_ERROR;

        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
                                  NULL,
                                          GetLastError(),
                                          0,
                                          (LPTSTR) &errorMsg,
                                          0,
                                          NULL);

        jdeWriteLogEntry(JDELOG, "CURLERROR", "CURLERROR", 212, 0,
errorMsg);
        jdeWriteLogEntry(JDELOG, "CURLERROR", "CURLERROR", 212, 0, "CURL
Library Failed to Load. Please check its in the path.");
        }

    /* Call Curl to do the post */
        if (idReturnValue == ER_SUCCESS)
        {
              jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----B4-BeforeEasyInit");

           curl_global_init(CURL_GLOBAL_ALL);

       easyhandle = curl_easy_init();

       /* Prepare the output xml - As a URL paramter called xml
servelt?xml=<XMLSTR> */
             //urlEncodedStr = I550001_URLEncodeStr(XMLStr);
       urlEncodedStr = curl_escape(XMLStr, 0);

           I550001_AppendStr(&outputXML, servletParams);
       I550001_AppendStr(&outputXML, urlEncodedStr);

       curlCode = curl_easy_setopt(easyhandle, CURLOPT_VERBOSE, 100);
       curlCode = curl_easy_setopt(easyhandle, CURLOPT_DEBUGFUNCTION,
curl_debug_callback);
       curlCode = curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS,
outputXML);

       if (curlCode == CURLE_OK)
           {
               jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----B4-setopt");
               jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----servletURL: ");
               jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0, servletURL);
          curlCode = curl_easy_setopt(easyhandle, CURLOPT_URL, servletURL);

              if (curlCode == CURLE_OK)
                  {
                    jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----B4-Easy-Perform");
             curlCode = curl_easy_perform(easyhandle);
                  }
           }

              jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----B4-Easy-Cleanup");

           if (curlCode != CURLE_OK)
           {
          idReturnValue = ER_ERROR;

                  jdeWriteLogEntry(JDELOG, "CURLERROR", "CURLERRO", 212, 0, "CURL Failed
with ERROR");
                  itoa (curlCode, errorText, 10);
                  jdeWriteLogEntry(JDELOG, "CURLERROR", "CURLERRO", 212, 0, errorText);
           }
        }

   /************************************************************************
    * Function Clean Up
    
************************************************************************/

    curl_free(urlEncodedStr);
    curl_easy_cleanup(easyhandle);
        curl_global_cleanup();

        if (outputXML != NULL)
           jdeFree(outputXML);

// if (outputXML != NULL)
// jdeFree(urlEncodedStr);

        if (hLibCurl != NULL)
           FreeLibrary(hLibCurl);

   jdeWriteLogEntry(JDEDEBUGLOG, "DEBUG", "DEBUG", 212, 0,
"I550001_HTTPPostXMLData----End");

   return idReturnValue;

int curl_debug_callback (CURL * easyHandle, curl_infotype cType, char *
data, size_t datasize, void * userRef)
{

   return 0;
}

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-11-24