Re: Was [Re: [evolution-patches] itip-formatter plugin invocation URI fix.]



On Thu, 2005-07-07 at 16:45 -0400, Jeffrey Stedfast wrote:
> On Fri, 2005-07-08 at 01:45 +0530, Veerapuram Varadhan wrote:
> > -               slash = uri_string + strcspn (uri_string, "/#");
> > +               /* 
> > +                * Play safe. ;-)
> > +                * If username, password, host, port things are not 
> > +                * specified in the url, find a way to not crib about
> > +                * them.  So, check for the "existance" of magic "/"
> > or 
> > +                * "#" which will give a clue about the presence of
> > something
> > +                * that we are looking for.
> > +                */
> > +
> > +               slash = strchr (uri_string, '/');
> > +               if (!slash)
> > +                       slash = strchr (uri_string, '#');
> > +               if (slash)
> > +                       slash = uri_string + strcspn (uri_string,
> > "/#");
> > +               else
> > +                       slash = uri_string;
> > +
> 
> read up on what strcspn does. your above code changes duplicate the code
> you replaced (almost) but does it in a less efficient manner.

>From the man page of strcspn....

size_t strcspn(const char *s, const char *reject);
strcspn() returns the number of characters in the initial segment of s
which are not  in  the  string reject.

Here is a sample program to verify strcspn.

#include <unistd.h>
#include <stdio.h>
#include <string.h>
                                                                                                                             
int
main ()
{
  int len = 0;
  char * url =
"calendar://?startdate=20050601T0000Z&enddate=20050602T0000Z";
                                                                                                                             
  len = strcspn (url+11, "/#");
  printf ("Len: %d\n", len);
  printf ("url = %s\n", url);
  printf ("url+len = %s\n", url+len);
                                                                                                                             
  return 0;
}

So, it does mean that when "/" or "#" is not found in string uri_string,
it will return the "rest-of-the-string". So, the code

	slash = uri_string+strcspn (uri_string, "/#");

will make slash point to the end-of-the-string, in case of "/" or "#"
not present in the uri_string.

> instead, the following change is simpler:
> 
> if ((slash = uri_string + strcspn (uri_string, "/#"))[0] == 0)
>    slash = uri_string;
> 
I don't think this will ever be "TRUE" unless and otherwise the string
url string contains just the protocol.

IMO, the above change will never work.

> however, looking over the e-url.c code, I fail to see how this actually
> solves the problem. In fact, I fail to see any problem at all in the
> original code. Please explain what exactly the problem is...
> 
Now lets discuss the problem in detail.

Consider the url-string passed from the itip-formatter plugin,
"calendar://?startdate=20050601T0000Z&enddate=20050602T0000Z"

When it get passed to the e_uri_new (url_string), the function parses
the url and extracts the individual fields/components of a passed url.

Right after fetching the protocol correctly, the parser starts to parse
the "authority" fields, (i.e) username, password, host and port.

So, in a normal url, these fields are passed as..

"ftp://username:password host:port/path/file"

After parsing through the protocol, (i.e.) "calendar:", the following
code gets executed.
        if (strncmp (uri_string, "//", 2) == 0) {
                uri_string += 2;
now the uri_string will be
"?startdate=20050601T0000Z&enddate=20050602T0000Z"

Now, when the following gets executed
(179)  slash = uri_string + strcspn (uri_string, "/#");

slash points to the "end-of-the-uri-string", because, both "/" and "#"
are not present in the string and strcspn returns 
len (?startdate=20050601T0000Z&enddate=20050602T0000Z)

So, uri_string+len (uri_string) == end-of-string.

And rest of the conditions for "@" and others fail and the code reaches,

(221)		 uri_string = slash;
which makes uri_string to point to the end-of-it.

Thereby the rest of code for finding queries, parameters etc fails and
uri->query returns NULL for urls that dont have proper "authority"
fields.

P.S:-
Having said/done all these.. i have a question...

should the url that we are currently using in itip-formatter plugin be 
"calendar:///?startdate=<date-time>&enddate=<date-time>"?

because "calendar://" is the protocol and "?" should follow a path,
isn't it?

Thanks,

V. Varadhan





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]