diff options
Diffstat (limited to 'projects/mongrel_experimental')
18 files changed, 0 insertions, 1675 deletions
diff --git a/projects/mongrel_experimental/CHANGELOG b/projects/mongrel_experimental/CHANGELOG deleted file mode 100644 index abefe87..0000000 --- a/projects/mongrel_experimental/CHANGELOG +++ /dev/null @@ -1,2 +0,0 @@ - -v1.1. First release. diff --git a/projects/mongrel_experimental/COPYING b/projects/mongrel_experimental/COPYING deleted file mode 100644 index b1e3f5a..0000000 --- a/projects/mongrel_experimental/COPYING +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - <one line to give the library's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - <signature of Ty Coon>, 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/projects/mongrel_experimental/LICENSE b/projects/mongrel_experimental/LICENSE deleted file mode 100644 index e5a926e..0000000 --- a/projects/mongrel_experimental/LICENSE +++ /dev/null @@ -1,55 +0,0 @@ -Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw -<zedshaw at zedshaw dot com> and contributors. You can redistribute it -and/or modify it under either the terms of the GPL2 or the conditions below: - -1. You may make and give away verbatim copies of the source form of the - software without restriction, provided that you duplicate all of the - original copyright notices and associated disclaimers. - -2. You may modify your copy of the software in any way, provided that - you do at least ONE of the following: - - a) place your modifications in the Public Domain or otherwise make them - Freely Available, such as by posting said modifications to Usenet or an - equivalent medium, or by allowing the author to include your - modifications in the software. - - b) use the modified software only within your corporation or - organization. - - c) rename any non-standard executables so the names do not conflict with - standard executables, which must also be provided. - - d) make other distribution arrangements with the author. - -3. You may distribute the software in object code or executable - form, provided that you do at least ONE of the following: - - a) distribute the executables and library files of the software, - together with instructions (in the manual page or equivalent) on where - to get the original distribution. - - b) accompany the distribution with the machine-readable source of the - software. - - c) give non-standard executables non-standard names, with - instructions on where to get the original software distribution. - - d) make other distribution arrangements with the author. - -4. You may modify and include the part of the software into any other - software (possibly commercial). But some files in the distribution - are not written by the author, so that they are not under this terms. - -5. The scripts and library files supplied as input to or produced as - output from the software do not automatically fall under the - copyright of the software, but belong to whomever generated them, - and may be sold commercially, and may be aggregated with this - software. - -6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE. - - diff --git a/projects/mongrel_experimental/Manifest b/projects/mongrel_experimental/Manifest deleted file mode 100644 index 43bfdff..0000000 --- a/projects/mongrel_experimental/Manifest +++ /dev/null @@ -1,17 +0,0 @@ -CHANGELOG -COPYING -ext/uri_classifier/ext_help.h -ext/uri_classifier/extconf.rb -ext/uri_classifier/tst.h -ext/uri_classifier/tst_cleanup.c -ext/uri_classifier/tst_delete.c -ext/uri_classifier/tst_grow_node_free_list.c -ext/uri_classifier/tst_init.c -ext/uri_classifier/tst_insert.c -ext/uri_classifier/tst_search.c -ext/uri_classifier/uri_classifier.c -lib/mongrel_experimental.rb -LICENSE -Manifest -README -test/test_uriclassifier.rb diff --git a/projects/mongrel_experimental/README b/projects/mongrel_experimental/README deleted file mode 100644 index 49102d2..0000000 --- a/projects/mongrel_experimental/README +++ /dev/null @@ -1,3 +0,0 @@ -= Mongrel Experimental - - diff --git a/projects/mongrel_experimental/Rakefile b/projects/mongrel_experimental/Rakefile deleted file mode 100644 index 5bc3b41..0000000 --- a/projects/mongrel_experimental/Rakefile +++ /dev/null @@ -1,15 +0,0 @@ - -require 'echoe' - -Echoe.new("mongrel_experimental") do |p| - p.summary = "Backports and experimental features for Mongrel." - p.project = "mongrel" - p.author="The Mongrel Team" - p.dependencies = ['mongrel =1.1'] - - p.need_tar_gz = false - p.need_tgz = true - p.certificate_chain = ['~/p/configuration/gem_certificates/mongrel/mongrel-public_cert.pem', - '~/p/configuration/gem_certificates/evan_weaver-mongrel-public_cert.pem'] - p.require_signed = true -end diff --git a/projects/mongrel_experimental/ext/uri_classifier/ext_help.h b/projects/mongrel_experimental/ext/uri_classifier/ext_help.h deleted file mode 100644 index 8b4d754..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/ext_help.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef ext_help_h -#define ext_help_h - -#define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be."); -#define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name); -#define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T); - -#ifdef DEBUG -#define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__) -#else -#define TRACE() -#endif - -#endif diff --git a/projects/mongrel_experimental/ext/uri_classifier/extconf.rb b/projects/mongrel_experimental/ext/uri_classifier/extconf.rb deleted file mode 100644 index 06b1cd0..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/extconf.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'mkmf' - -dir_config("uri_classifier") -have_library("c", "main") -create_makefile("uri_classifier") diff --git a/projects/mongrel_experimental/ext/uri_classifier/tst.h b/projects/mongrel_experimental/ext/uri_classifier/tst.h deleted file mode 100644 index 3a58a65..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/tst.h +++ /dev/null @@ -1,40 +0,0 @@ - - -struct node -{ - unsigned char value; - struct node *left; - struct node *middle; - struct node *right; -}; - -struct tst -{ - int node_line_width; - struct node_lines *node_lines; - struct node *free_list; - struct node *head[127]; -}; - -struct node_lines -{ - struct node *node_line; - struct node_lines *next; -}; - -enum tst_constants -{ - TST_OK, TST_ERROR, TST_NULL_KEY, TST_DUPLICATE_KEY, TST_REPLACE, TST_LONGEST_MATCH -}; - -struct tst *tst_init(int node_line_width); - -int tst_insert(unsigned char *key, void *data, struct tst *tst, int option, void **exist_ptr); - -void *tst_search(const unsigned char *key, struct tst *tst, int option, unsigned int *match_len); - -void *tst_delete(unsigned char *key, struct tst *tst); - -void tst_cleanup(struct tst *tst); - - diff --git a/projects/mongrel_experimental/ext/uri_classifier/tst_cleanup.c b/projects/mongrel_experimental/ext/uri_classifier/tst_cleanup.c deleted file mode 100644 index a85491d..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/tst_cleanup.c +++ /dev/null @@ -1,23 +0,0 @@ - -#include "tst.h" -#include <stdio.h> -#include <stdlib.h> - -void tst_cleanup(struct tst *tst) -{ - struct node_lines *current_line; - struct node_lines *next_line; - - next_line = tst->node_lines; - - do - { - current_line = next_line; - next_line = current_line->next; - free(current_line->node_line); - free(current_line); - } - while(next_line != NULL); - - free(tst); -} diff --git a/projects/mongrel_experimental/ext/uri_classifier/tst_delete.c b/projects/mongrel_experimental/ext/uri_classifier/tst_delete.c deleted file mode 100644 index cb18f16..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/tst_delete.c +++ /dev/null @@ -1,146 +0,0 @@ - -#include "tst.h" -#include <stdio.h> -#include <stdlib.h> - -void *tst_delete(unsigned char *key, struct tst *tst) -{ - struct node *current_node; - struct node *current_node_parent; - struct node *last_branch; - struct node *last_branch_parent; - struct node *next_node; - struct node *last_branch_replacement; - struct node *last_branch_dangling_child; - int key_index; - - - if(key[0] == 0) - return NULL; - if(tst->head[(int)key[0]] == NULL) - return NULL; - - last_branch = NULL; - last_branch_parent = NULL; - current_node = tst->head[(int)key[0]]; - current_node_parent = NULL; - key_index = 1; - while(current_node != NULL) - { - if(key[key_index] == current_node->value) - { - - if( (current_node->left != NULL) || (current_node->right != NULL) ) - { - last_branch = current_node; - last_branch_parent = current_node_parent; - } - if(key[key_index] == 0) - break; - else - { - current_node_parent = current_node; - current_node = current_node->middle; - key_index++; - continue; - } - } - else if( ((current_node->value == 0) && (key[key_index] < 64)) || - ((current_node->value != 0) && (key[key_index] < - current_node->value)) ) - { - last_branch_parent = current_node; - current_node_parent = current_node; - current_node = current_node->left; - last_branch = current_node; - continue; - } - else - { - last_branch_parent = current_node; - current_node_parent = current_node; - current_node = current_node->right; - last_branch = current_node; - continue; - } - - } - if(current_node == NULL) - return NULL; - - if(last_branch == NULL) - { - - next_node = tst->head[(int)key[0]]; - tst->head[(int)key[0]] = NULL; - } - else if( (last_branch->left == NULL) && (last_branch->right == NULL) ) - { - - if(last_branch_parent->left == last_branch) - last_branch_parent->left = NULL; - else - last_branch_parent->right = NULL; - - next_node = last_branch; - } - else - { - - if( (last_branch->left != NULL) && (last_branch->right != NULL) ) - { - last_branch_replacement = last_branch->right; - last_branch_dangling_child = last_branch->left; - } - else if(last_branch->right != NULL) - { - last_branch_replacement = last_branch->right; - last_branch_dangling_child = NULL; - } - else - { - last_branch_replacement = last_branch->left; - last_branch_dangling_child = NULL; - } - - if(last_branch_parent == NULL) - tst->head[(int)key[0]]=last_branch_replacement; - else - { - if (last_branch_parent->left == last_branch) - last_branch_parent->left = last_branch_replacement; - else if (last_branch_parent->right == last_branch) - last_branch_parent->right = last_branch_replacement; - else - last_branch_parent->middle = last_branch_replacement; - } - - if(last_branch_dangling_child != NULL) - { - current_node = last_branch_replacement; - - while (current_node->left != NULL) - current_node = current_node->left; - - current_node->left = last_branch_dangling_child; - } - - next_node = last_branch; - } - - do - { - current_node = next_node; - next_node = current_node->middle; - - current_node->left = NULL; - current_node->right = NULL; - current_node->middle = tst->free_list; - tst->free_list = current_node; - } - while(current_node->value != 0); - - return next_node; - -} - diff --git a/projects/mongrel_experimental/ext/uri_classifier/tst_grow_node_free_list.c b/projects/mongrel_experimental/ext/uri_classifier/tst_grow_node_free_list.c deleted file mode 100644 index da21333..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/tst_grow_node_free_list.c +++ /dev/null @@ -1,38 +0,0 @@ - -#include "tst.h" -#include <stdio.h> -#include <stdlib.h> - -int tst_grow_node_free_list(struct tst *tst) -{ - struct node *current_node; - struct node_lines *new_line; - int i; - - - if((new_line = (struct node_lines *) malloc(sizeof(struct node_lines))) == NULL) - return TST_ERROR; - - if((new_line->node_line = (struct node *) - calloc(tst->node_line_width, sizeof(struct node))) == NULL) - { - free(new_line); - return TST_ERROR; - } - else - { - new_line->next = tst->node_lines; - tst->node_lines = new_line; - } - - current_node = tst->node_lines->node_line; - tst->free_list = current_node; - for (i = 1; i < tst->node_line_width; i++) - { - current_node->middle = &(tst->node_lines->node_line[i]); - current_node = current_node->middle; - } - current_node->middle = NULL; - return 1; -} - diff --git a/projects/mongrel_experimental/ext/uri_classifier/tst_init.c b/projects/mongrel_experimental/ext/uri_classifier/tst_init.c deleted file mode 100644 index 259734a..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/tst_init.c +++ /dev/null @@ -1,41 +0,0 @@ - -#include "tst.h" -#include <stdio.h> -#include <stdlib.h> - -struct tst *tst_init(int width) -{ - struct tst *tst; - struct node *current_node; - int i; - - -if((tst = (struct tst *) calloc(1, sizeof(struct tst))) == NULL) - return NULL; - -if ((tst->node_lines = (struct node_lines *) calloc(1, sizeof(struct node_lines))) == NULL) -{ - free(tst); - return NULL; -} - -tst->node_line_width = width; -tst->node_lines->next = NULL; -if ((tst->node_lines->node_line = (struct node *) calloc(width, sizeof(struct node))) == NULL) -{ - free(tst->node_lines); - free(tst); - return NULL; -} - -current_node = tst->node_lines->node_line; -tst->free_list = current_node; -for (i = 1; i < width; i++) -{ - current_node->middle = &(tst->node_lines->node_line[i]); - current_node = current_node->middle; -} -current_node->middle = NULL; -return tst; -} - diff --git a/projects/mongrel_experimental/ext/uri_classifier/tst_insert.c b/projects/mongrel_experimental/ext/uri_classifier/tst_insert.c deleted file mode 100644 index de50f4a..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/tst_insert.c +++ /dev/null @@ -1,218 +0,0 @@ - -#include "tst.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -int tst_grow_node_free_list(struct tst *tst); -int tst_insert(unsigned char *key, void *data, struct tst *tst, int option, void **exist_ptr) -{ - struct node *current_node; - struct node *new_node_tree_begin = NULL; - struct node *new_node; - int key_index; - int perform_loop = 1; - - if (key == NULL) - return TST_NULL_KEY; - - if(key[0] == 0) - return TST_NULL_KEY; - - if(tst->head[(int)key[0]] == NULL) - { - - if(tst->free_list == NULL) - { - if(tst_grow_node_free_list(tst) != 1) - return TST_ERROR; - } - tst->head[(int)key[0]] = tst->free_list; - - tst->free_list = tst->free_list->middle; - current_node = tst->head[(int)key[0]]; - current_node->value = key[1]; - if(key[1] == 0) - { - current_node->middle = data; - return TST_OK; - } - else - perform_loop = 0; - } - - current_node = tst->head[(int)key[0]]; - key_index = 1; - while(perform_loop == 1) - { - if(key[key_index] == current_node->value) - { - - if(key[key_index] == 0) - { - if (option == TST_REPLACE) - { - if (exist_ptr != NULL) - *exist_ptr = current_node->middle; - - current_node->middle = data; - return TST_OK; - } - else - { - if (exist_ptr != NULL) - *exist_ptr = current_node->middle; - return TST_DUPLICATE_KEY; - } - } - else - { - if(current_node->middle == NULL) - { - - if(tst->free_list == NULL) - { - if(tst_grow_node_free_list(tst) != 1) - return TST_ERROR; - } - current_node->middle = tst->free_list; - - tst->free_list = tst->free_list->middle; - new_node_tree_begin = current_node; - current_node = current_node->middle; - current_node->value = key[key_index]; - break; - } - else - { - current_node = current_node->middle; - key_index++; - continue; - } - } - } - if(key[key_index] == 0) - { - if(tst->free_list == NULL) - { - if(tst_grow_node_free_list(tst) != 1) - return TST_ERROR; - } - new_node = tst->free_list; - tst->free_list = tst->free_list->middle; - - memcpy((void*)new_node, (void*)current_node, sizeof(struct node)); - current_node->value = 0; - if(new_node->value < 64) - { - current_node->left = new_node; - current_node->right = '\0'; - } - else - { - current_node->left = '\0'; - current_node->right = new_node; - } - - current_node->middle = data; - return TST_OK; - } - - if( ((current_node->value == 0) && (key[key_index] < 64)) || - ((current_node->value != 0) && (key[key_index] < - current_node->value)) ) - { - - if (current_node->left == NULL) - { - - if(tst->free_list == NULL) - { - if(tst_grow_node_free_list(tst) != 1) - return TST_ERROR; - } - current_node->left = tst->free_list; - - tst->free_list = tst->free_list->middle; - new_node_tree_begin = current_node; - current_node = current_node->left; - current_node->value = key[key_index]; - if(key[key_index] == 0) - { - current_node->middle = data; - return TST_OK; - } - else - break; - } - else - { - current_node = current_node->left; - continue; - } - } - else - { - - if (current_node->right == NULL) - { - - if(tst->free_list == NULL) - { - if(tst_grow_node_free_list(tst) != 1) - return TST_ERROR; - } - current_node->right = tst->free_list; - - tst->free_list = tst->free_list->middle; - new_node_tree_begin = current_node; - current_node = current_node->right; - current_node->value = key[key_index]; - break; - } - else - { - current_node = current_node->right; - continue; - } - } - } - - do - { - key_index++; - - if(tst->free_list == NULL) - { - if(tst_grow_node_free_list(tst) != 1) - { - current_node = new_node_tree_begin->middle; - - while (current_node->middle != NULL) - current_node = current_node->middle; - - current_node->middle = tst->free_list; - tst->free_list = new_node_tree_begin->middle; - new_node_tree_begin->middle = NULL; - - return TST_ERROR; - } - } - - - if(tst->free_list == NULL) - { - if(tst_grow_node_free_list(tst) != 1) - return TST_ERROR; - } - current_node->middle = tst->free_list; - - tst->free_list = tst->free_list->middle; - current_node = current_node->middle; - current_node->value = key[key_index]; - } while(key[key_index] !=0); - - current_node->middle = data; - return TST_OK; -} - diff --git a/projects/mongrel_experimental/ext/uri_classifier/tst_search.c b/projects/mongrel_experimental/ext/uri_classifier/tst_search.c deleted file mode 100644 index 176f953..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/tst_search.c +++ /dev/null @@ -1,73 +0,0 @@ - -#include "tst.h" -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - - -void *tst_search(const unsigned char *key, struct tst *tst, int option, - unsigned int *match_len) -{ - struct node *current_node; - struct node *longest_match = NULL; - unsigned int longest_match_len = 0; - int key_index; - - assert(key != NULL && "key can't be NULL"); - assert(tst != NULL && "tst can't be NULL"); - - if (key[0] == 0) - return NULL; - - if (tst->head[(int) key[0]] == NULL) - return NULL; - - if (match_len) - *match_len = 0; - - current_node = tst->head[(int) key[0]]; - key_index = 1; - - while (current_node != NULL) { - if (key[key_index] == current_node->value) { - if (current_node->value == 0) { - if (match_len) - *match_len = key_index; - return current_node->middle; - } else { - current_node = current_node->middle; - key_index++; - continue; - } - } else { - if (current_node->value == 0) { - if (option & TST_LONGEST_MATCH) { - longest_match = current_node->middle; - longest_match_len = key_index; - } - - if (key[key_index] < 64) { - current_node = current_node->left; - continue; - } else { - current_node = current_node->right; - continue; - } - } else { - if (key[key_index] < current_node->value) { - current_node = current_node->left; - continue; - } else { - current_node = current_node->right; - continue; - } - } - } - } - - if (match_len) - *match_len = longest_match_len; - - return longest_match; - -} diff --git a/projects/mongrel_experimental/ext/uri_classifier/uri_classifier.c b/projects/mongrel_experimental/ext/uri_classifier/uri_classifier.c deleted file mode 100644 index 05603fd..0000000 --- a/projects/mongrel_experimental/ext/uri_classifier/uri_classifier.c +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Copyright (c) 2005 Zed A. Shaw - * You can redistribute it and/or modify it under the same terms as Ruby. - */ -#include "ruby.h" -#include "ext_help.h" -#include <assert.h> -#include <string.h> -#include <ctype.h> -#include "tst.h" - -static VALUE mMongrel; -static VALUE cURIClassifier; - -#define id_handler_map rb_intern("@handler_map") - -#define TRIE_INCREASE 30 - -void URIClassifier_free(void *data) -{ - TRACE(); - - if(data) { - tst_cleanup((struct tst *)data); - } -} - -VALUE URIClassifier_alloc(VALUE klass) -{ - VALUE obj; - struct tst *tst = tst_init(TRIE_INCREASE); - TRACE(); - assert(tst && "failed to initialize trie structure"); - - obj = Data_Wrap_Struct(klass, NULL, URIClassifier_free, tst); - - return obj; -} - -/** - * call-seq: - * URIClassifier.new -> URIClassifier - * - * Initializes a new URIClassifier object that you can use to associate URI sequences - * with objects. You can actually use it with any string sequence and any objects, - * but it's mostly used with URIs. - * - * It uses TST from http://www.octavian.org/cs/software.html to build an ternary search - * trie to hold all of the URIs. It uses this to do an initial search for the a URI - * prefix, and then to break the URI into SCRIPT_NAME and PATH_INFO portions. It actually - * will do two searches most of the time in order to find the right handler for the - * registered prefix portion. - * - */ -VALUE URIClassifier_init(VALUE self) -{ - VALUE hash; - - /* we create an internal hash to protect stuff from the GC */ - hash = rb_hash_new(); - rb_ivar_set(self, id_handler_map, hash); - - return self; -} - - -/** - * call-seq: - * uc.register("/someuri", SampleHandler.new) -> nil - * - * Registers the SampleHandler (one for all requests) with the "/someuri". - * When URIClassifier::resolve is called with "/someuri" it'll return - * SampleHandler immediately. When called with "/someuri/iwant" it'll also - * return SomeHandler immediatly, with no additional searches, but it will - * return path info with "/iwant". - * - * You actually can reuse this class to register nearly anything and - * quickly resolve it. This could be used for caching, fast mapping, etc. - * The downside is it uses much more memory than a Hash, but it can be - * a lot faster. It's main advantage is that it works on prefixes, which - * is damn hard to get right with a Hash. - */ -VALUE URIClassifier_register(VALUE self, VALUE uri, VALUE handler) -{ - int rc = 0; - void *ptr = NULL; - struct tst *tst = NULL; - DATA_GET(self, struct tst, tst); - - rc = tst_insert((unsigned char *)StringValueCStr(uri), (void *)handler , tst, 0, &ptr); - - if(rc == TST_DUPLICATE_KEY) { - rb_raise(rb_eStandardError, "Handler already registered with that name"); - } else if(rc == TST_ERROR) { - rb_raise(rb_eStandardError, "Memory error registering handler"); - } else if(rc == TST_NULL_KEY) { - rb_raise(rb_eStandardError, "URI was empty"); - } - - rb_hash_aset(rb_ivar_get(self, id_handler_map), uri, handler); - - return Qnil; -} - - -/** - * call-seq: - * uc.unregister("/someuri") - * - * Yep, just removes this uri and it's handler from the trie. - */ -VALUE URIClassifier_unregister(VALUE self, VALUE uri) -{ - void *handler = NULL; - struct tst *tst = NULL; - DATA_GET(self, struct tst, tst); - - handler = tst_delete((unsigned char *)StringValueCStr(uri), tst); - - if(handler) { - rb_hash_delete(rb_ivar_get(self, id_handler_map), uri); - - return (VALUE)handler; - } else { - return Qnil; - } -} - - -/** - * call-seq: - * uc.resolve("/someuri") -> "/someuri", "", handler - * uc.resolve("/someuri/pathinfo") -> "/someuri", "/pathinfo", handler - * uc.resolve("/notfound/orhere") -> nil, nil, nil - * uc.resolve("/") -> "/", "/", handler # if uc.register("/", handler) - * uc.resolve("/path/from/root") -> "/", "/path/from/root", handler # if uc.register("/", handler) - * - * Attempts to resolve either the whole URI or at the longest prefix, returning - * the prefix (as script_info), path (as path_info), and registered handler - * (usually an HttpHandler). If it doesn't find a handler registered at the longest - * match then it returns nil,nil,nil. - * - * Because the resolver uses a trie you are able to register a handler at *any* character - * in the URI and it will be handled as long as it's the longest prefix. So, if you - * registered handler #1 at "/something/lik", and #2 at "/something/like/that", then a - * a search for "/something/like" would give you #1. A search for "/something/like/that/too" - * would give you #2. - * - * This is very powerful since it means you can also attach handlers to parts of the ; - * (semi-colon) separated path params, any part of the path, use off chars, anything really. - * It also means that it's very efficient to do this only taking as long as the URI has - * characters. - * - * A slight modification to the CGI 1.2 standard is given for handlers registered to "/". - * CGI expects all CGI scripts to be at some script path, so it doesn't really say anything - * about a script that handles the root. To make this work, the resolver will detect that - * the requested handler is at "/", and return that for script_name, and then simply return - * the full URI back as path_info. - * - * It expects strings with no embedded '\0' characters. Don't try other string-like stuff yet. - */ -VALUE URIClassifier_resolve(VALUE self, VALUE uri) -{ - void *handler = NULL; - int pref_len = 0; - struct tst *tst = NULL; - VALUE result; - unsigned char *uri_str = NULL; - - DATA_GET(self, struct tst, tst); - uri_str = (unsigned char *)StringValueCStr(uri); - - handler = tst_search(uri_str, tst, TST_LONGEST_MATCH, &pref_len); - - /* setup for multiple return values */ - result = rb_ary_new(); - - if(handler) { - rb_ary_push(result, rb_str_substr (uri, 0, pref_len)); - /* compensate for a script_name="/" where we need to add the "/" to path_info to keep it consistent */ - if(pref_len == 1 && uri_str[0] == '/') { - /* matches the root URI so we have to use the whole URI as the path_info */ - rb_ary_push(result, uri); - } else { - /* matches a script so process like normal */ - rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING(uri)->len)); - } - - rb_ary_push(result, (VALUE)handler); - } else { - /* not found so push back nothing */ - rb_ary_push(result, Qnil); - rb_ary_push(result, Qnil); - rb_ary_push(result, Qnil); - } - - return result; -} - -VALUE URIClassifier_uris(VALUE self) { - return rb_funcall(rb_ivar_get(self, id_handler_map), rb_intern("keys"), 0); -} - -void Init_uri_classifier() -{ - - mMongrel = rb_define_module("Mongrel"); - - cURIClassifier = rb_define_class_under(mMongrel, "URIClassifier", rb_cObject); - rb_define_alloc_func(cURIClassifier, URIClassifier_alloc); - rb_define_method(cURIClassifier, "initialize", URIClassifier_init, 0); - rb_define_method(cURIClassifier, "register", URIClassifier_register, 2); - rb_define_method(cURIClassifier, "unregister", URIClassifier_unregister, 1); - rb_define_method(cURIClassifier, "resolve", URIClassifier_resolve, 1); - rb_define_method(cURIClassifier, "uris", URIClassifier_uris, 0); -} diff --git a/projects/mongrel_experimental/lib/mongrel_experimental.rb b/projects/mongrel_experimental/lib/mongrel_experimental.rb deleted file mode 100644 index 1825fe1..0000000 --- a/projects/mongrel_experimental/lib/mongrel_experimental.rb +++ /dev/null @@ -1,3 +0,0 @@ - -require 'uri_classifier' -STDERR.puts "** Mongrel_experimental loaded" diff --git a/projects/mongrel_experimental/test/test_uriclassifier.rb b/projects/mongrel_experimental/test/test_uriclassifier.rb deleted file mode 100644 index b83eac4..0000000 --- a/projects/mongrel_experimental/test/test_uriclassifier.rb +++ /dev/null @@ -1,262 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'lib/uri_classifier' -require 'test/unit' - -include Mongrel - -class URIClassifierTest < Test::Unit::TestCase - - def test_uri_finding - uri_classifier = URIClassifier.new - uri_classifier.register("/test", 1) - - script_name, path_info, value = uri_classifier.resolve("/test") - assert_equal 1, value - assert_equal "/test", script_name - end - - def test_root_handler_only - uri_classifier = URIClassifier.new - uri_classifier.register("/", 1) - - script_name, path_info, value = uri_classifier.resolve("/test") - assert_equal 1, value - assert_equal "/", script_name - assert_equal "/test", path_info - end - - def test_uri_prefix_ops - test = "/pre/fix/test" - prefix = "/pre" - - uri_classifier = URIClassifier.new - uri_classifier.register(prefix,1) - - script_name, path_info, value = uri_classifier.resolve(prefix) - script_name, path_info, value = uri_classifier.resolve(test) - assert_equal 1, value - assert_equal prefix, script_name - assert_equal test[script_name.length .. -1], path_info - - assert uri_classifier.inspect - assert_equal prefix, uri_classifier.uris[0] - end - - def test_not_finding - test = "/cant/find/me" - uri_classifier = URIClassifier.new - uri_classifier.register(test, 1) - - script_name, path_info, value = uri_classifier.resolve("/nope/not/here") - assert_nil script_name - assert_nil path_info - assert_nil value - end - - def test_exceptions - uri_classifier = URIClassifier.new - - uri_classifier.register("/test", 1) - - failed = false - begin - uri_classifier.register("/test", 1) - rescue => e - failed = true - end - - assert failed - - failed = false - begin - uri_classifier.register("", 1) - rescue => e - failed = true - end - - assert failed - end - - - def test_register_unregister - uri_classifier = URIClassifier.new - - 100.times do - uri_classifier.register("/stuff", 1) - value = uri_classifier.unregister("/stuff") - assert_equal 1, value - end - - uri_classifier.register("/things",1) - script_name, path_info, value = uri_classifier.resolve("/things") - assert_equal 1, value - - uri_classifier.unregister("/things") - script_name, path_info, value = uri_classifier.resolve("/things") - assert_nil value - - end - - - def test_uri_branching - uri_classifier = URIClassifier.new - uri_classifier.register("/test", 1) - uri_classifier.register("/test/this",2) - - script_name, path_info, handler = uri_classifier.resolve("/test") - script_name, path_info, handler = uri_classifier.resolve("/test/that") - assert_equal "/test", script_name, "failed to properly find script off branch portion of uri" - assert_equal "/that", path_info - assert_equal 1, handler, "wrong result for branching uri" - end - - def test_all_prefixing - tests = ["/test","/test/that","/test/this"] - uri = "/test/this/that" - uri_classifier = URIClassifier.new - - current = "" - uri.each_byte do |c| - current << c.chr - uri_classifier.register(current, c) - end - - - # Try to resolve everything with no asserts as a fuzzing - tests.each do |prefix| - current = "" - prefix.each_byte do |c| - current << c.chr - script_name, path_info, handler = uri_classifier.resolve(current) - assert script_name - assert path_info - assert handler - end - end - - # Assert that we find stuff - tests.each do |t| - script_name, path_info, handler = uri_classifier.resolve(t) - assert handler - end - - # Assert we don't find stuff - script_name, path_info, handler = uri_classifier.resolve("chicken") - assert_nil handler - assert_nil script_name - assert_nil path_info - end - - - # Verifies that a root mounted ("/") handler resolves - # such that path info matches the original URI. - # This is needed to accommodate real usage of handlers. - def test_root_mounted - uri_classifier = URIClassifier.new - root = "/" - path = "/this/is/a/test" - - uri_classifier.register(root, 1) - - script_name, path_info, handler = uri_classifier.resolve(root) - assert_equal 1, handler - assert_equal root, path_info - assert_equal root, script_name - - script_name, path_info, handler = uri_classifier.resolve(path) - assert_equal path, path_info - assert_equal root, script_name - assert_equal 1, handler - end - - # Verifies that a root mounted ("/") handler - # is the default point, doesn't matter the order we use - # to register the URIs - def test_classifier_order - tests = ["/before", "/way_past"] - root = "/" - path = "/path" - - uri_classifier = URIClassifier.new - uri_classifier.register(path, 1) - uri_classifier.register(root, 2) - - tests.each do |uri| - script_name, path_info, handler = uri_classifier.resolve(uri) - assert_equal root, script_name, "#{uri} did not resolve to #{root}" - assert_equal uri, path_info - assert_equal 2, handler - end - end - - if ENV['BENCHMARK'] - # Eventually we will have a suite of benchmarks instead of lamely installing a test - - def test_benchmark - - # This URI set should favor a TST. Both versions increase linearly until you hit 14 - # URIs, then the TST flattens out. - @uris = %w( - / - /dag /dig /digbark /dog /dogbark /dog/bark /dug /dugbarking /puppy - /c /cat /cat/tree /cat/tree/mulberry /cats /cot /cot/tree/mulberry /kitty /kittycat -# /eag /eig /eigbark /eog /eogbark /eog/bark /eug /eugbarking /iuppy -# /f /fat /fat/tree /fat/tree/mulberry /fats /fot /fot/tree/mulberry /jitty /jittyfat -# /gag /gig /gigbark /gog /gogbark /gog/bark /gug /gugbarking /kuppy -# /h /hat /hat/tree /hat/tree/mulberry /hats /hot /hot/tree/mulberry /litty /littyhat -# /ceag /ceig /ceigbark /ceog /ceogbark /ceog/cbark /ceug /ceugbarking /ciuppy -# /cf /cfat /cfat/ctree /cfat/ctree/cmulberry /cfats /cfot /cfot/ctree/cmulberry /cjitty /cjittyfat -# /cgag /cgig /cgigbark /cgog /cgogbark /cgog/cbark /cgug /cgugbarking /ckuppy -# /ch /chat /chat/ctree /chat/ctree/cmulberry /chats /chot /chot/ctree/cmulberry /citty /cittyhat - ) - - @requests = %w( - / - /dig - /digging - /dogging - /dogbarking/ - /puppy/barking - /c - /cat - /cat/shrub - /cat/tree - /cat/tree/maple - /cat/tree/mulberry/tree - /cat/tree/oak - /cats/ - /cats/tree - /cod - /zebra - ) - - @classifier = URIClassifier.new - @uris.each do |uri| - @classifier.register(uri, 1) - end - - puts "#{@uris.size} URIs / #{@requests.size * 10000} requests" - - Benchmark.bm do |x| - x.report do - # require 'ruby-prof' - # profile = RubyProf.profile do - 10000.times do - @requests.each do |request| - @classifier.resolve(request) - end - end - # end - # File.open("profile.html", 'w') { |file| RubyProf::GraphHtmlPrinter.new(profile).print(file, 0) } - end - end - end - end - -end - |