cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: reagrding error in getting complete server response

From: Sunil Chandrasekharan <sunil.kainat_at_gmail.com>
Date: Tue, 12 Nov 2013 15:02:38 +0900

Hi All,

Kindly find the code snippet

typedef struct pageInfo_t {
  char *data;
  int len;
} pageInfo_t;

static size_t HTTPData(void *buffer, size_t size, size_t nmemb, void
*userData)
 {
  int len = size * nmemb;
  pageInfo_t *page = (pageInfo_t *)userData;
  page->data = realloc(page->data,page->len + len +1);
//if(buffer && page->data && (page->len + len <(16 * 4096))) {
    memcpy(&page->data[page->len], buffer, len);
    page->len += len;
    page->data[page->len] = 0;
  //}
  return len;
}
 //Inteface funciton that will recieve web page fom Java
jstring Java_com_samsung_jnitest_MainActivity_JNIGetWebpage( JNIEnv*
env,jobject entryObject,jstring webpageJStr,jstring host, jint port
,jstring userid, jstring pass)
{
  pageInfo_t page;
  CURL *curl;
  CURLcode res;
  char *buffer;
int memorysize = 19189;
 page.data = (char *)malloc(16 * memorysize);
    page.len = 0;

if (page.data)
    memset(page.data, 32, 16 * memorysize);

  buffer = (char *)malloc(memorysize);

   curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, webpage);
    gs_strLastResponse = "";
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPData);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
    res = curl_easy_perform(curl);

curl_easy_cleanup(curl);
    (*env)->ReleaseStringUTFChars(env, webpageJStr, webpage);
    if(res == 0) {
    if(response_code == 200) {
      if (buffer) {
       page.data[page.len] = '\0';
       //page.data[page.len < memorysize ? page.len : memorysize-1] = '\0';
      sprintf(buffer, "%ld:%s \n", response_code, page.data);
 //sprintf(buffer, "pagedata(%d): %s. done.\n", page.len, page.data);
        return (*env)->NewStringUTF(env, buffer);
      }
    }
  else {
    sprintf(buffer, "Else Result %ld", response_code);
    return (*env)->NewStringUTF(env, buffer);
     // return (*env)->NewStringUTF(env, "Unable to init cURL");
   }
}

 I have given my c code snippet in my last response , regarding the buffer
size and allocation. Kindly help to dynamically increase the buffer to
accomodate the big response data

On Tue, Nov 12, 2013 at 1:54 PM, Sunil Chandrasekharan <
sunil.kainat_at_gmail.com> wrote:

> Hi All,
>
> one more finding
>
> >>> What happens if you use the curl command-line tool to do the same
> transfer?
> Does that return the whole response? Is the response simply longer than
> your
> buffer length and is therefore deliberately truncated?
>
>
> Ans.
>
> When i use curl command line tool and i moved the rsponse to a output
> file, I could see the entire response data. So i can agrre that curl
> command is retrieving the entire response properly.
> i get the whole response, but the response is longer than my buffer length
> and hence it is getting truncated.
>
> I have given my c code snippet in my last response , regarding the buffer
> size and allocation. Kindly help to dynamically increase the buffer to
> accomodate the big response data
>
> Thanks
>
>
> On Tue, Nov 12, 2013 at 11:33 AM, Sunil Chandrasekharan <
> sunil.kainat_at_gmail.com> wrote:
>
>> Hi All,
>>
>> As pointed out, This is the android custom log . I am prinintg the log to
>> see the response data.
>> From what i see the orginal output and the current output, i can find
>> that there are still around 10 to 15 more lines to be prinited, when using
>> CURL implementation.
>>
>> Hence as you said i could make out that the response is longer than the
>> buffer length and so it is getting truncated.
>>
>> Currently i tried to hardcord the buffer length as
>>
>>
>> * int*memorysize = 4096;
>>
>> buffer = (
>> *char* *)malloc(memorysize);
>>
>> But even when i try to increase the buffer length , it jsut print the
>> same number of lines. there is no change in the output even if i increase
>> the buffer length manually.
>>
>>
>>
>> I reffered to this blog link when i wrote my curltest 'c' file :
>> http://thesoftwarerogue.blogspot.kr/2010/05/porting-of-libcurl-to-android-os-using.html
>>
>> So most of the contents are same from the c file as shown in the blog
>> there.
>>
>> =======
>>
>> * typedef**struct* pageInfo_t {
>>
>> *char* *data;
>>
>> *int* len;
>>
>> }
>> pageInfo_t;
>>
>> * static*size_t
>>
>> * HTTPData*(*void* *buffer, size_t size, size_t nmemb, *void* *userData)
>> {
>>
>> *int* len = size * nmemb;
>>
>> pageInfo_t *page = (pageInfo_t *)userData;
>>
>> *if* (buffer && page->data && (page->len + len < (16 * 4096)) ) {
>>
>> memcpy(&page->
>> data[page->len], buffer, len);
>>
>> page->
>> len += len;
>>
>> }
>>
>> *return* len;
>>
>> }
>>
>> ------
>>
>> * int*memorysize = 9189;
>>
>> page.
>> data = (*char* *)malloc(16 * memorysize);
>>
>> page.
>> len = 0;
>>
>> *if* (page.data)
>>
>> memset(page.
>> data, 32, 16 * memorysize);
>>
>> buffer = (
>> *char* *)malloc(memorysize);
>>
>> -----
>>
>> * if*(buffer) {
>>
>> //page.data[page.len] = '\0';
>>
>> page.
>> data[page.len < memorysize ? page.len : memorysize-1] = '\0';
>>
>> sprintf(buffer,
>> "%*ld*:%s \n", response_code, page.data);
>>
>> *return* (*env)->NewStringUTF(env, buffer);
>>
>> }
>>
>>
>> These are the main chunk of the c code..the section shows how i declared
>> my buffer size .
>> Please help me understand how the response data of my cgi script page can
>> be completely added into the buffer (not getting truncated in the middle)
>>
>>
>>
>> On Sat, Oct 26, 2013 at 3:32 AM, G Drukier <gdrukier_at_imageinsightinc.com>wrote:
>>
>>> On 25 Oct 2013, at 14:16 , Dan Fandrich <dan_at_coneharvesters.com> wrote:
>>>
>>> > On 25 Oct 2013, at 3:29 , Sunil Chandrasekharan <
>>> sunil.kainat_at_gmail.com> wrote:
>>> >> .....
>>> >> 10-25 15:53:22.264: XXX(14847): Security.8021x:true
>>> >> 10-25 15:53:22.264: XXX(14847): Event.AlarmInput:true
>>> >> 10-25 15:53:22.264: XXX(14847):
>>> Event.AlarmInput.Notification.HTTP.CGI:true
>>> >> 10-25 15:53:22.264: XXX(14847):
>>> >> Event.AlarmInput.Notification.HTTP.CGI.SingleSession:true
>>> >> 10-25 15:53:22.264: XXX(14847): Event.AlarmInpu
>>> >>
>>> >> There are around 10 more lines in the response, but my current log
>>> shows that
>>> >> after "Event.AlarmInpu" there is no output.
>>> >
>>> > I don't know what this is. Is this some kind of custom logging output?
>>> Is this
>>> > the truncated output of the server as received by your program?
>>>
>>> This looks like Android logcat output. That it's Java related is also
>>> suggested by this method definition
>>>
>>> On 25 Oct 2013, at 3:29 , Sunil Chandrasekharan <sunil.kainat_at_gmail.com>
>>> wrote:
>>>
>>> > jstring Java_com_example_JNIGetWebpage( JNIEnv* env,jobject
>>> entryObject,jstring webpageJStr,jstring host, jint port ,jstring userid,
>>> jstring pass,jint timeout)
>>> >
>>>
>>> More detail on what the original poster is up to would likely be helpful.
>>> -------------------------------------------------------------------
>>> List admin: http://cool.haxx.se/list/listinfo/curl-library
>>> Etiquette: http://curl.haxx.se/mail/etiquette.html
>>>
>>
>>
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-11-12