Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_HTTP_astrcpyFieldFromUrlEncode - Extract a field value from a URL-Encoded query-string

#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/html.h>

char *
librock_HTTP_astrcpyFieldFromUrlEncode(
    char **ppasz,
    const char *pszFieldName,
    const char *pszQuerystring
);

DESCRIPTION

Returns a decoded value for the first named field matching pszFieldName. Returns a pointer to the name in pszQueryString. (See below for how to extract fields of identical names.)

If pszFieldName is 0, the first part of pszQueryString is processed, and the string stored at *ppasz is of the form 'name=value'. The return value points to the next part of pszQueryString or is 0.

Typical use is to obtain values from HTTP form submissions and query strings.

#ifdef librock_TYPICAL_USE_HTTP_astrcpyFieldFromUrlEncode
    char *asz = 0;
    librock_HTTP_astrcpyFieldFromUrlEncode(&asz,
        "file","name=value&%66ile=a+test");
    printf("Query had file='%s'\n",asz);
    librock_astrfree(&asz);
#endif
When the query string might have a field encoded multiple times, use code such as the following. Note the use of p+1 on subsequent calls.
#ifdef librock_TYPICAL_USE_2_HTTP_astrcpyFieldFromUrlEncode
    char *aszValue  = 0;
    const char *p;
    if (p = librock_HTTP_astrcpyFieldFromUrlEncode(&aszValue,"file","name=value&%66ile=a+test&file=another+test")) {
        /* Append all */
        char *asz = 0;
        while (p = librock_HTTP_astrcpyFieldFromUrlEncode(&asz,"file",p+1)) {
            librock_astrcat(&aszValue,",");
            librock_astrcat(&aszValue,asz);
        }
        librock_astrfree(&asz);
    }
    printf("file(s)=%s\n",aszValue);
    librock_astrfree(&aszValue);
#endif

To iterate all values of the query string, use code similar to the following.
#ifdef librock_TYPICAL_USE_3_HTTP_astrcpyFieldFromUrlEncode
    char *aszNameValue  = 0;
    const char *p = "field1=test&field2=test2&file=a&file=b";
    while(p) {
        p = librock_HTTP_astrcpyFieldFromUrlEncode(&aszNameValue,0,p);
        if (p) {
            printf("%s\n",aszNameValue);
        }
    }
    librock_astrfree(&aszNameValue);
#endif

USES

    strlen() strncmp() strchr()
    librock_counttoch()
    librock_astrensure() librock_astrfree()

LICENSE

  Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com
  Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block.
  License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45

Source Code

./spec/infotool/www/html.c (implementation, plus source of this manual page)

Tests and Supported Platform Types

This is a representative sample. Librock code is highly portable. For a particular platform not reported here, request paid support

librock_HTTP_astrcpyFieldFromUrlEncode passed tests in thtml (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_HTTP_astrcpyFieldFromUrlEncode passed tests in thtml (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)


This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)

Want to help? We welcome comments, patches. -- Need help? Request paid support.