slang-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] curl_easy_unescape sample and problem


Here is an unescape that works fine, but only on strings.  I found a
problem I didn't know how to solve when I tried to do unescape on more
general input data.  First I am not sure what form the input data
wouldbe in - probably not a hashed string.  Secondly I need to return
both the malloced string and the length of the malloced string.  Would
I push two items back onto the stack?  How would I grab them to use
them through the interpreter?

Here is the unescape sample.  The escape one is also included.  I'll
make a patch of these when I'm happy with them:


static void unescape_intrin (void)
{
  SLang_MMT_Type *mmt;
  Easy_Type *ez;
  char *escaped_string = NULL;
  char *unescaped_string = NULL;

  if (-1 == SLang_pop_slstring (&escaped_string))
       return;

  if (NULL == (mmt = pop_easy_type (&ez, 0))) {
    SLang_free_slstring(escaped_string);
    return;
  }

  unescaped_string = curl_easy_unescape(ez->handle, escaped_string, 0, NULL);

  if (unescaped_string == NULL) {
       SLang_free_mmt(mmt);
       SLang_free_slstring(escaped_string);
       SLang_set_error(Curl_Error);
       return;
  }

  (void) SLang_push_malloced_string (unescaped_string);

  SLang_free_slstring(escaped_string);
  SLang_free_mmt(mmt);

}


Here is a good curl_easy escape:


static void escape_intrin (void)
{
  SLang_MMT_Type *mmt;
  Easy_Type *ez;
  char *unescaped_string = NULL;
  char *escaped_string = NULL;

  if (-1 == SLang_pop_slstring (&unescaped_string))
       return;

  if (NULL == (mmt = pop_easy_type (&ez, 0))) {
    SLang_free_slstring(unescaped_string);
    return;
  }

  escaped_string = curl_easy_escape(ez->handle, unescaped_string, 0);

  if (escaped_string == NULL) {
       SLang_free_mmt(mmt);
       SLang_free_slstring(unescaped_string);
       SLang_set_error(Curl_Error);
       return;
  }

  (void) SLang_push_malloced_string (escaped_string);

  SLang_free_slstring(unescaped_string);
  SLang_free_mmt(mmt);
}



[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]