Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Here's a library (MYSQL + ...)

From: m::koopmans2::chello::nl at: 21-Feb-2001 12:04

Hi all, Here is a first beta release of a library. You are free to use it under the BSD license. What is it: - session management: some session management functions for generating and validating session keys in a web environment. - erebol: a rebol based preprocessor for text files. If you add the erebol_sample.r as a filter to your webserver you can dump PHP (especially when used with mysql and command). - mysql integration. Change the load/library line to whatever is convenient for you. Works with Command only (and Command is worth having!) All of this plus more will soon be available from my site www.erebol.com (or .org .net). under the BSD license. You are allowed to use this under the BSD license. If you don't agree to the bsd license attached, you are not allowed to use this. What's more: - database to rebol and xml conversion functions. - ? Make your request/ contribute your code to [m--koopmans2--chello--nl] (home email) - documentation I hope I have made your web programming a bit easier. The goal is to provide some sort of rebol standard libs for all versions. Comments and additions are... appreciated. Enjoy at your own risk :) Maarten Koopmans -- Attached file included as plaintext by Listar -- -- File: erebol.r REBOL [] erebol: func [ {Preprocesses a text file and evaluates al rebol code between <% and %> tags. Everything that is printed is visible in the output. Who needs PHP?} content [file! string!] /local text] [ either file? content [ text: read content ] [ text: copy content ] ; two rules for parsing ; first the comment rule ; removes any comment between <%# and %>, useful for debugging comment-rule: [ copy pre to "<%#" cs: thru "%>" ce: (remove/part cs ((index? ce) - (index? cs)))] ; next, we copy anything that is between <% and %> and try to execute that ; we save the remainder of the page in page-end blok: [ do code ] bind blok 'do exec-rule: [ copy pre to "<%" thru "<%" copy code thru "%>" page-end: (print pre error? try blok) ] bind exec-rule 'do ; now remove the comments parse text [ any comment-rule ] ; execute the commands parse text [any exec-rule] ;and... print the end of the page that doesn't contain any code print page-end ] -- Attached file included as plaintext by Listar -- -- File: erebol_sample.r REBOL [] erebol: func [ {Preprocesses a text file and evaluates al rebol code between <% and %> tags. Everything that is printed is visible in the output. Who needs PHP?} content [file! string!] /local text] [ either file? content [ text: read content ] [ text: copy content ] ; two rules for parsing ; first the comment rule ; removes any comment between <%# and %>, useful for debugging comment-rule: [ copy pre to "<%#" cs: thru "%>" ce: (remove/part cs ((index? ce) - (index? cs)))] ; next, we copy anything that is between <% and %> and try to execute that ; we save the remainder of the page in page-end blok: [ do code ] bind blok 'do exec-rule: [ copy pre to "<%" thru "<%" copy code thru "%>" page-end: (print pre error? try blok) ] bind exec-rule 'do ; now remove the comments parse text [ any comment-rule ] ; execute the commands parse text [any exec-rule] ;and... print the end of the page that doesn't contain any code print page-end ] print "Content-Type: text/html" input-text: make string! 65538 read-io system/ports/input input-text 65536 erebol input-text -- Attached file included as plaintext by Listar -- -- File: mysql.r REBOL[] mysql-lib: load/library %libmysql.dll mysql-init: make routine! [ [save] in [integer!] return: [integer!] ] mysql-lib "mysql_init" mysql-connect: make routine! [ [save] mysql [integer!] host [string!] user [string!] passwd [string!] db [string!] port [integer!] socket [integer!] clientflag [integer!] return: [integer!] ] mysql-lib "mysql_real_connect" mysql-close: make routine! [ mysql [integer!] ] mysql-lib "mysql_close" mysql-query: make routine! [ mysql [integer!] query [string!] return: [integer!] ] mysql-lib "mysql_query" mysql-ping: make routine! [ mysql [integer!] return: [integer!] ] mysql-lib "mysql_ping" mysql-store-result: make routine! [ mysql [integer!] return: [integer!] ] mysql-lib "mysql_store_result" mysql-free-result: make routine! [ mysql_res [integer!] ] mysql-lib "mysql_free_result" mysql-num-rows: make routine! [ mysqlres [integer!] return: [integer!] ] mysql-lib "mysql_num_rows" mysql-num-fields: make routine! [ mysqlres [integer!] return: [integer!] ] mysql-lib "mysql_num_fields" query-conn: func [conn [integer!] qu [string!] {/local res routine-spec result-struct result-list num-fields num-rows result-row fields }] [ mysql-query conn qu res: mysql-store-result conn if res = 0 [ return []] num-rows: mysql-num-rows res if num-rows = 0 [ return []] num-fields: mysql-num-fields res result-list: make block! copy [] routine-spec: make block! [ mysql-res [integer!] return: ] result-struct-spec: make block! [] for fields 1 num-fields 1 [ append result-struct-spec to-word join "a" fields append/only result-struct-spec copy [string!] ] append/only routine-spec append/only [struct!] copy result-struct-spec mysql-fetch-row: make routine! :routine-spec mysql-lib "mysql_fetch_row" for fields 1 num-rows 1 [ result-row: copy second mysql-fetch-row res append/only result-list result-row ] mysql-free-result res return copy result-list ] -- Attached file included as plaintext by Listar -- -- File: sessionmgt.r REBOL [ Author: "Maarten Koopmans" Purpose: "Session management library" ] retrieve-user-data: func [{Return the cgi data as an object}] [ return make object! decode-cgi either system/options/cgi/request-method = "POST" [ input ][ system/options/cgi/query-string ] ] generate-sid: func [{Generate a session-id based on a string and the current date and the time passed in.} name [string!] {The user name for the session} time [time!] {The timestamp for the session id.} ][ return to-string to-integer checksum/secure rejoin [ name now/date time ] ] check-sid: func [{Check a session-id on validity for today.} name [string!]{The name to check on} sid [string!]{The session id to check} time [time!] {The time the session id was generated} window [time!] {The relative window before expiration} ][ either sid-expired? time window [ return sid = generate-sid name time] [ return false] ] sid-expired?: func [ {Check if a session-id is expired.} time [time!] {The time the session id was generated} window [time!] {The relative window before expiration} ] [ return (time + window) > now/time ] -- Attached file included as plaintext by Listar -- -- File: License.txt Copyright (c) 2001, Maarten Koopmans All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Maarten Koopmans nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.