/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* url-util.c : utility functions to parse URLs */ /* * Copyright (C) 1999 Bertrand Guiheneuf * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /* Here we deal with URL following the general scheme: protocol://user:password@host:port/name where name is a path-like string (ie dir1/dir2/....) See rfc1738 for the complete description of Uniform Ressource Locators Bertrand. */ #include /* for isalpha */ #include /* for atoi */ #include "url-util.h" static gboolean find_protocol(GString *url, GString **protocol, guint *position, gboolean *error) { guint i; gchar *str_url; gint len_url; gchar *str_protocol; str_url = url->str; len_url = url->len; *protocol = NULL; *error = FALSE; i=*position; /* find a ':' */ while ( (istr; len_url = url->len; *user = NULL; i=*position; /* find a '@' */ while ((istr; len_url = url->len; *passwd = NULL; i=*position; /* find a '@' */ while ((istr); /* Try to find the protocol */ found = find_protocol(url, &protocol, &position, &error); if (found) { printf("protocol found : %s\n", protocol->str); } else printf("protocol not found in URL\n\n"); printf("posistion of the next item:\n"); printf("%s\n", url->str); for(i=0; istr); } else printf("user name not found in URL\n"); printf("posistion of the next item:\n"); printf("%s\n", url->str); for(i=0; istr); printf("\n"); } else printf("passwd not found in URL\n"); printf("posistion of the next item:\n"); printf("%s\n", url->str); for(i=0; i