~ubuntu-branches/ubuntu/utopic/suricata/utopic

« back to all changes in this revision

Viewing changes to libhtp/htp/htp_util.c

  • Committer: Package Import Robot
  • Author(s): Pierre Chifflier
  • Date: 2011-11-17 23:20:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20111117232051-wlo0g2fyinx0zi25
Tags: 1.1-1
* Imported Upstream version 1.1
* Add instructions on getting new rules using oinkmaster
* Add Recommends on oinkmaster
* Move snort-rules-default to Recommends

Show diffs side-by-side

added added

removed removed

Lines of Context:
198
198
 
199
199
/**
200
200
 * Does line consist entirely of whitespace characters?
201
 
 *
 
201
 * 
202
202
 * @param data
203
203
 * @param len
204
204
 * @return 0 or 1
241
241
/**
242
242
 * A forgiving parser for a positive integer in a given base.
243
243
 * White space is allowed before and after the number.
244
 
 *
 
244
 * 
245
245
 * @param data
246
246
 * @param len
247
247
 * @param base
271
271
 
272
272
/**
273
273
 * Prints one log message to stderr.
274
 
 *
 
274
 * 
275
275
 * @param log
276
276
 */
277
277
void htp_print_log(FILE *stream, htp_log_t *log) {
286
286
 
287
287
/**
288
288
 * Records one log message.
289
 
 *
 
289
 * 
290
290
 * @param connp
291
291
 * @param file
292
292
 * @param line
428
428
            // Failed to parse port
429
429
            htp_log(connp, HTP_LOG_MARK, HTP_LOG_ERROR, 0, "Invalid server port information in request");
430
430
        } else if ((port > 0) && (port < 65536)) {
431
 
            // Valid port
 
431
            // Valid port            
432
432
            (*uri)->port_number = port;
433
433
        } else {
434
434
            htp_log(connp, HTP_LOG_MARK, HTP_LOG_ERROR, 0, "Invalid authority port");
440
440
 
441
441
/**
442
442
 * Parses request URI, making no attempt to validate the contents.
443
 
 *
 
443
 * 
444
444
 * @param input
445
445
 * @param uri
446
446
 * @return HTP_ERROR on memory allocation failure, HTP_OK otherwise
467
467
    // Scheme test: if it doesn't start with a forward slash character (which it must
468
468
    // for the contents to be a path or an authority, then it must be the scheme part
469
469
    if (data[0] != '/') {
470
 
        // Parse scheme
 
470
        // Parse scheme        
471
471
 
472
472
        // Find the colon, which marks the end of the scheme part
473
473
        start = pos;
1716
1716
bstr *htp_unparse_uri_noencode(htp_uri_t *uri) {
1717
1717
    if (uri == NULL) {
1718
1718
        return NULL;
1719
 
    }
 
1719
    }   
1720
1720
 
1721
1721
    // On the first pass determine the length of the final string
1722
1722
    size_t len = 0;
1738
1738
        }
1739
1739
 
1740
1740
        len += 1; // "@"
1741
 
    }
 
1741
    }   
1742
1742
 
1743
1743
    if (uri->hostname != NULL) {
1744
1744
        len += bstr_len(uri->hostname);
1745
 
    }
 
1745
    }   
1746
1746
 
1747
1747
    if (uri->port != NULL) {
1748
1748
        len += 1; // ":"
1761
1761
    if (uri->fragment != NULL) {
1762
1762
        len += 1; // "#"
1763
1763
        len += bstr_len(uri->fragment);
1764
 
    }
 
1764
    }    
1765
1765
 
1766
1766
    // On the second pass construct the string
1767
1767
    bstr *r = bstr_alloc(len);
1768
1768
    if (r == NULL) {
1769
1769
        return NULL;
1770
 
    }
 
1770
    }   
1771
1771
 
1772
1772
    if (uri->scheme != NULL) {
1773
1773
        bstr_add_str_noex(r, uri->scheme);
1774
1774
        bstr_add_cstr_noex(r, "://");
1775
 
    }
 
1775
    }   
1776
1776
 
1777
1777
    if ((uri->username != NULL) || (uri->password != NULL)) {
1778
1778
        if (uri->username != NULL) {
1786
1786
        }
1787
1787
 
1788
1788
        bstr_add_cstr_noex(r, "@");
1789
 
    }
 
1789
    }   
1790
1790
 
1791
1791
    if (uri->hostname != NULL) {
1792
1792
        bstr_add_str_noex(r, uri->hostname);
1793
 
    }
 
1793
    }   
1794
1794
 
1795
1795
    if (uri->port != NULL) {
1796
1796
        bstr_add_cstr(r, ":");
1797
1797
        bstr_add_str_noex(r, uri->port);
1798
 
    }
 
1798
    }   
1799
1799
 
1800
1800
    if (uri->path != NULL) {
1801
1801
        bstr_add_str_noex(r, uri->path);
1802
 
    }
 
1802
    }  
1803
1803
 
1804
1804
    if (uri->query != NULL) {
1805
1805
        bstr *query = bstr_strdup(uri->query);
1807
1807
        bstr_add_cstr_noex(r, "?");
1808
1808
        bstr_add_str_noex(r, query);
1809
1809
        bstr_free(query);
1810
 
    }
 
1810
    }     
1811
1811
 
1812
1812
    if (uri->fragment != NULL) {
1813
1813
        bstr_add_cstr_noex(r, "#");
1814
1814
        bstr_add_str_noex(r, uri->fragment);
1815
1815
    }
1816
 
 
 
1816
   
1817
1817
    return r;
1818
1818
}
1819
1819