Commit f0c68430 f0c684302da2cb3a6dc0c313692a78fbd387a0f7 by Sergey Poznyakoff

Fixed indentation

1 parent 0908e210
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
39 TODO: implement functions to create a url and encode it properly. 39 TODO: implement functions to create a url and encode it properly.
40 */ 40 */
41 41
42 static int url_parse0(url_t, char*); 42 static int url_parse0 (url_t, char *);
43 43
44 int 44 int
45 url_create (url_t * purl, const char *name) 45 url_create (url_t * purl, const char *name)
...@@ -58,7 +58,7 @@ url_create (url_t * purl, const char *name) ...@@ -58,7 +58,7 @@ url_create (url_t * purl, const char *name)
58 } 58 }
59 59
60 void 60 void
61 url_destroy (url_t *purl) 61 url_destroy (url_t * purl)
62 { 62 {
63 if (purl && *purl) 63 if (purl && *purl)
64 { 64 {
...@@ -102,13 +102,13 @@ url_parse (url_t url) ...@@ -102,13 +102,13 @@ url_parse (url_t url)
102 { 102 {
103 int err = 0; 103 int err = 0;
104 char *n = NULL; 104 char *n = NULL;
105 struct _url u = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0, 0}; 105 struct _url u = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
106 106
107 if (!url || !url->name) 107 if (!url || !url->name)
108 return EINVAL; 108 return EINVAL;
109 109
110 /* can't have been parsed already */ 110 /* can't have been parsed already */
111 if(url->scheme || url->user || url->passwd || url->auth || 111 if (url->scheme || url->user || url->passwd || url->auth ||
112 url->host || url->path || url->query) 112 url->host || url->path || url->query)
113 return EINVAL; 113 return EINVAL;
114 114
...@@ -123,8 +123,8 @@ url_parse (url_t url) ...@@ -123,8 +123,8 @@ url_parse (url_t url)
123 { 123 {
124 /* Dup the strings we found. We wouldn't have to do this 124 /* Dup the strings we found. We wouldn't have to do this
125 if we did a single alloc of the source url name, and 125 if we did a single alloc of the source url name, and
126 kept it around. It's also a good time to do hex decoding, 126 kept it around. It's also a good time to do hex decoding,
127 though. 127 though.
128 */ 128 */
129 129
130 130
...@@ -137,17 +137,12 @@ url_parse (url_t url) ...@@ -137,17 +137,12 @@ url_parse (url_t url)
137 u.X = NULL; \ 137 u.X = NULL; \
138 } 138 }
139 139
140 UALLOC (scheme) 140 UALLOC (scheme)
141 UALLOC (user) 141 UALLOC (user)
142 UALLOC (passwd) 142 UALLOC (passwd)
143 UALLOC (auth) 143 UALLOC (auth) UALLOC (host) UALLOC (path) UALLOC (query)
144 UALLOC (host)
145 UALLOC (path)
146 UALLOC (query)
147
148 #undef UALLOC 144 #undef UALLOC
149 145 url->port = u.port;
150 url->port = u.port;
151 } 146 }
152 147
153 CLEANUP: 148 CLEANUP:
...@@ -157,14 +152,11 @@ CLEANUP: ...@@ -157,14 +152,11 @@ CLEANUP:
157 { 152 {
158 #define UFREE(X) if(X) { free(X); X = 0; } 153 #define UFREE(X) if(X) { free(X); X = 0; }
159 154
160 UFREE(url->scheme) 155 UFREE (url->scheme)
161 UFREE(url->user) 156 UFREE (url->user)
162 UFREE(url->passwd) 157 UFREE (url->passwd)
163 UFREE(url->auth) 158 UFREE (url->auth)
164 UFREE(url->host) 159 UFREE (url->host) UFREE (url->path) UFREE (url->query)
165 UFREE(url->path)
166 UFREE(url->query)
167
168 #undef UFREE 160 #undef UFREE
169 } 161 }
170 162
...@@ -199,7 +191,7 @@ Is this required to be % quoted, though? I hope so! ...@@ -199,7 +191,7 @@ Is this required to be % quoted, though? I hope so!
199 static int 191 static int
200 url_parse0 (url_t u, char *name) 192 url_parse0 (url_t u, char *name)
201 { 193 {
202 char *p; /* pointer into name */ 194 char *p; /* pointer into name */
203 195
204 /* reject the obvious */ 196 /* reject the obvious */
205 if (name == NULL) 197 if (name == NULL)
...@@ -217,20 +209,20 @@ url_parse0 (url_t u, char *name) ...@@ -217,20 +209,20 @@ url_parse0 (url_t u, char *name)
217 u->scheme = name; 209 u->scheme = name;
218 210
219 /* RFC 1738, section 2.1, lower the scheme case */ 211 /* RFC 1738, section 2.1, lower the scheme case */
220 for ( ; name < p; name++) 212 for (; name < p; name++)
221 *name = tolower(*name); 213 *name = tolower (*name);
222 214
223 name = p; 215 name = p;
224 216
225 /* Check for nothing following the scheme. */ 217 /* Check for nothing following the scheme. */
226 if(!*name) 218 if (!*name)
227 return 0; 219 return 0;
228 220
229 if (strncmp (name, "//", 2) != 0) 221 if (strncmp (name, "//", 2) != 0)
230 { 222 {
231 u->path = name; 223 u->path = name;
232 return 0; 224 return 0;
233 } 225 }
234 226
235 name += 2; 227 name += 2;
236 228
...@@ -247,7 +239,7 @@ url_parse0 (url_t u, char *name) ...@@ -247,7 +239,7 @@ url_parse0 (url_t u, char *name)
247 239
248 /* Try to split the user into a: 240 /* Try to split the user into a:
249 <user>:<password> 241 <user>:<password>
250 or 242 or
251 <user>;AUTH=<auth> 243 <user>;AUTH=<auth>
252 */ 244 */
253 245
...@@ -286,7 +278,7 @@ url_parse0 (url_t u, char *name) ...@@ -286,7 +278,7 @@ url_parse0 (url_t u, char *name)
286 u->port = strtol (p, &p, 10); 278 u->port = strtol (p, &p, 10);
287 279
288 /* Check for garbage after the port: we should be on the start 280 /* Check for garbage after the port: we should be on the start
289 of a path, a query, or at the end of the string. */ 281 of a path, a query, or at the end of the string. */
290 if (*p && strcspn (p, "/?") != 0) 282 if (*p && strcspn (p, "/?") != 0)
291 return EPARSE; 283 return EPARSE;
292 } 284 }
...@@ -306,12 +298,12 @@ url_parse0 (url_t u, char *name) ...@@ -306,12 +298,12 @@ url_parse0 (url_t u, char *name)
306 *p++ = 0; 298 *p++ = 0;
307 u->path = p; 299 u->path = p;
308 } 300 }
309 301
310 return 0; 302 return 0;
311 } 303 }
312 304
313 int 305 int
314 url_get_scheme (const url_t url, char *scheme, size_t len, size_t *n) 306 url_get_scheme (const url_t url, char *scheme, size_t len, size_t * n)
315 { 307 {
316 size_t i; 308 size_t i;
317 if (url == NULL) 309 if (url == NULL)
...@@ -325,7 +317,7 @@ url_get_scheme (const url_t url, char *scheme, size_t len, size_t *n) ...@@ -325,7 +317,7 @@ url_get_scheme (const url_t url, char *scheme, size_t len, size_t *n)
325 } 317 }
326 318
327 int 319 int
328 url_get_user (const url_t url, char *user, size_t len, size_t *n) 320 url_get_user (const url_t url, char *user, size_t len, size_t * n)
329 { 321 {
330 size_t i; 322 size_t i;
331 if (url == NULL) 323 if (url == NULL)
...@@ -341,7 +333,7 @@ url_get_user (const url_t url, char *user, size_t len, size_t *n) ...@@ -341,7 +333,7 @@ url_get_user (const url_t url, char *user, size_t len, size_t *n)
341 /* FIXME: We should not store passwd in clear, but rather 333 /* FIXME: We should not store passwd in clear, but rather
342 have a simple encoding, and decoding mechanism */ 334 have a simple encoding, and decoding mechanism */
343 int 335 int
344 url_get_passwd (const url_t url, char *passwd, size_t len, size_t *n) 336 url_get_passwd (const url_t url, char *passwd, size_t len, size_t * n)
345 { 337 {
346 size_t i; 338 size_t i;
347 if (url == NULL) 339 if (url == NULL)
...@@ -355,7 +347,7 @@ url_get_passwd (const url_t url, char *passwd, size_t len, size_t *n) ...@@ -355,7 +347,7 @@ url_get_passwd (const url_t url, char *passwd, size_t len, size_t *n)
355 } 347 }
356 348
357 int 349 int
358 url_get_auth (const url_t url, char *auth, size_t len, size_t *n) 350 url_get_auth (const url_t url, char *auth, size_t len, size_t * n)
359 { 351 {
360 size_t i; 352 size_t i;
361 if (url == NULL) 353 if (url == NULL)
...@@ -369,7 +361,7 @@ url_get_auth (const url_t url, char *auth, size_t len, size_t *n) ...@@ -369,7 +361,7 @@ url_get_auth (const url_t url, char *auth, size_t len, size_t *n)
369 } 361 }
370 362
371 int 363 int
372 url_get_host (const url_t url, char *host, size_t len, size_t *n) 364 url_get_host (const url_t url, char *host, size_t len, size_t * n)
373 { 365 {
374 size_t i; 366 size_t i;
375 if (url == NULL) 367 if (url == NULL)
...@@ -394,28 +386,28 @@ url_get_port (const url_t url, long *pport) ...@@ -394,28 +386,28 @@ url_get_port (const url_t url, long *pport)
394 } 386 }
395 387
396 int 388 int
397 url_get_path (const url_t url, char *path, size_t len, size_t *n) 389 url_get_path (const url_t url, char *path, size_t len, size_t * n)
398 { 390 {
399 size_t i; 391 size_t i;
400 if (url == NULL) 392 if (url == NULL)
401 return EINVAL; 393 return EINVAL;
402 if (url->_get_path) 394 if (url->_get_path)
403 return url->_get_path (url, path, len, n); 395 return url->_get_path (url, path, len, n);
404 i = mu_cpystr(path, url->path, len); 396 i = mu_cpystr (path, url->path, len);
405 if (n) 397 if (n)
406 *n = i; 398 *n = i;
407 return 0; 399 return 0;
408 } 400 }
409 401
410 int 402 int
411 url_get_query (const url_t url, char *query, size_t len, size_t *n) 403 url_get_query (const url_t url, char *query, size_t len, size_t * n)
412 { 404 {
413 size_t i; 405 size_t i;
414 if (url == NULL) 406 if (url == NULL)
415 return EINVAL; 407 return EINVAL;
416 if (url->_get_query) 408 if (url->_get_query)
417 return url->_get_query (url, query, len, n); 409 return url->_get_query (url, query, len, n);
418 i = mu_cpystr(query, url->query, len); 410 i = mu_cpystr (query, url->query, len);
419 if (n) 411 if (n)
420 *n = i; 412 *n = i;
421 return 0; 413 return 0;
...@@ -429,9 +421,10 @@ url_to_string (const url_t url) ...@@ -429,9 +421,10 @@ url_to_string (const url_t url)
429 return url->name; 421 return url->name;
430 } 422 }
431 423
432 int url_is_scheme (url_t url, const char* scheme) 424 int
425 url_is_scheme (url_t url, const char *scheme)
433 { 426 {
434 if(url && scheme && url->scheme && strcasecmp(url->scheme, scheme) == 0) 427 if (url && scheme && url->scheme && strcasecmp (url->scheme, scheme) == 0)
435 return 1; 428 return 1;
436 429
437 return 0; 430 return 0;
...@@ -452,11 +445,11 @@ url_is_same_scheme (url_t url1, url_t url2) ...@@ -452,11 +445,11 @@ url_is_same_scheme (url_t url1, url_t url2)
452 url_get_scheme (url1, s1, i + 1, NULL); 445 url_get_scheme (url1, s1, i + 1, NULL);
453 s2 = calloc (j + 1, sizeof (char)); 446 s2 = calloc (j + 1, sizeof (char));
454 if (s2) 447 if (s2)
455 { 448 {
456 url_get_scheme (url2, s2, j + 1, NULL); 449 url_get_scheme (url2, s2, j + 1, NULL);
457 ret = !strcasecmp (s1, s2); 450 ret = !strcasecmp (s1, s2);
458 free (s2); 451 free (s2);
459 } 452 }
460 free (s1); 453 free (s1);
461 } 454 }
462 return ret; 455 return ret;
...@@ -477,11 +470,11 @@ url_is_same_user (url_t url1, url_t url2) ...@@ -477,11 +470,11 @@ url_is_same_user (url_t url1, url_t url2)
477 url_get_user (url1, s1, i + 1, NULL); 470 url_get_user (url1, s1, i + 1, NULL);
478 s2 = calloc (j + 1, sizeof (char)); 471 s2 = calloc (j + 1, sizeof (char));
479 if (s2) 472 if (s2)
480 { 473 {
481 url_get_user (url2, s2, j + 1, NULL); 474 url_get_user (url2, s2, j + 1, NULL);
482 ret = !strcmp (s1, s2); 475 ret = !strcmp (s1, s2);
483 free (s2); 476 free (s2);
484 } 477 }
485 free (s1); 478 free (s1);
486 } 479 }
487 return ret; 480 return ret;
...@@ -502,11 +495,11 @@ url_is_same_path (url_t url1, url_t url2) ...@@ -502,11 +495,11 @@ url_is_same_path (url_t url1, url_t url2)
502 url_get_path (url1, s1, i + 1, NULL); 495 url_get_path (url1, s1, i + 1, NULL);
503 s2 = calloc (j + 1, sizeof (char)); 496 s2 = calloc (j + 1, sizeof (char));
504 if (s2) 497 if (s2)
505 { 498 {
506 url_get_path (url2, s2, j + 1, NULL); 499 url_get_path (url2, s2, j + 1, NULL);
507 ret = !strcmp (s1, s2); 500 ret = !strcmp (s1, s2);
508 free (s2); 501 free (s2);
509 } 502 }
510 free (s1); 503 free (s1);
511 } 504 }
512 return ret; 505 return ret;
...@@ -527,11 +520,11 @@ url_is_same_host (url_t url1, url_t url2) ...@@ -527,11 +520,11 @@ url_is_same_host (url_t url1, url_t url2)
527 url_get_host (url1, s1, i + 1, NULL); 520 url_get_host (url1, s1, i + 1, NULL);
528 s2 = calloc (j + 1, sizeof (char)); 521 s2 = calloc (j + 1, sizeof (char));
529 if (s2) 522 if (s2)
530 { 523 {
531 url_get_host (url2, s2, j + 1, NULL); 524 url_get_host (url2, s2, j + 1, NULL);
532 ret = !strcasecmp (s1, s2); 525 ret = !strcasecmp (s1, s2);
533 free (s2); 526 free (s2);
534 } 527 }
535 free (s1); 528 free (s1);
536 } 529 }
537 return ret; 530 return ret;
...@@ -588,44 +581,43 @@ url_decode (const char *s) ...@@ -588,44 +581,43 @@ url_decode (const char *s)
588 return d; 581 return d;
589 } 582 }
590 583
591 static int defined(const char* s) 584 static int
585 defined (const char *s)
592 { 586 {
593 if(s && strcmp("*", s) != 0) 587 if (s && strcmp ("*", s) != 0)
594 return 1; 588 return 1;
595 return 0; 589 return 0;
596 } 590 }
597 591
598 int 592 int
599 url_is_ticket (url_t ticket, url_t url) 593 url_is_ticket (url_t ticket, url_t url)
600 { 594 {
601 if(!ticket || !url) 595 if (!ticket || !url)
602 return 0; 596 return 0;
603 597
604 /* If ticket has a scheme, host, port, or path, then the queries 598 /* If ticket has a scheme, host, port, or path, then the queries
605 equivalent must be defined and match. */ 599 equivalent must be defined and match. */
606 if(defined(ticket->scheme)) 600 if (defined (ticket->scheme))
607 { 601 {
608 if(!url->scheme || strcasecmp(ticket->scheme, url->scheme) != 0) 602 if (!url->scheme || strcasecmp (ticket->scheme, url->scheme) != 0)
609 return 0; 603 return 0;
610 } 604 }
611 if(defined(ticket->host)) 605 if (defined (ticket->host))
612 { 606 {
613 if(!url->host || strcasecmp(ticket->host, url->host) != 0) 607 if (!url->host || strcasecmp (ticket->host, url->host) != 0)
614 return 0; 608 return 0;
615 } 609 }
616 if(ticket->port && ticket->port != url->port) 610 if (ticket->port && ticket->port != url->port)
617 return 0; 611 return 0;
618 /* If ticket has a user or pass, but url doesn't thats OK, were 612 /* If ticket has a user or pass, but url doesn't thats OK, were
619 urling for this info. But if url does have a user/pass, it 613 urling for this info. But if url does have a user/pass, it
620 must match the ticket. */ 614 must match the ticket. */
621 if(url->user) 615 if (url->user)
622 { 616 {
623 if(defined(ticket->user) && strcmp(ticket->user, url->user) != 0) 617 if (defined (ticket->user) && strcmp (ticket->user, url->user) != 0)
624 return 0; 618 return 0;
625 } 619 }
626 620
627 /* Guess it matches. */ 621 /* Guess it matches. */
628 return 1; 622 return 1;
629 } 623 }
630
631
......