cvs commit: mod_parrot/eg demo2.pasm

[email protected]
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
cvsuser     02/05/28 11:17:28

  Modified:    .        apache.pmc
               eg       demo2.pasm
  Log:
  turned get_string_keyed into an ugly if/else statement, but it now looks
  at what is passed in as the key to decide what value to return (current
  the arg string from the GET or the remote ip of the user (a patch of
  Ask's patch))
  
  updated demo2.pasm to demonstrate
  
  Revision  Changes    Path
  1.2       +32 -12    mod_parrot/apache.pmc
  
  Index: apache.pmc
  ===================================================================
  RCS file: /cvs/public/mod_parrot/apache.pmc,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- apache.pmc	17 May 2002 03:20:42 -0000	1.1
  +++ apache.pmc	28 May 2002 18:17:26 -0000	1.2
  @@ -1,7 +1,6 @@
  -/* parrotpointer.pmc
  - *  Copyright: (When this is determined...it will go here)
  +/* apache.pmc
    *  CVS Info
  - *     $Id: apache.pmc,v 1.1 2002/05/17 03:20:42 falcone Exp $
  + *     $Id: apache.pmc,v 1.2 2002/05/28 18:17:26 falcone Exp $
    *  Overview:
    *     Access to the Apache r object
    *  Data Structure and Algorithms:
  @@ -18,8 +17,28 @@
   #define APACHE_ERROR internal_exception(APACHE_PARROT_ERROR, "An illegal operation was performed on an Apache object (vtable function at %s line %d).\n", __FILE__, __LINE__);
   
   int modparrot_printf(const char *format, ...) { return 0; }
  -
   char* modparrot_getargs(void) { return NULL; }
  +char* modparrot_get_remoteip(void) { return NULL; }
  +
  +static STRING* get_args(Interp* interpreter, KEY * key) {
  +   char* args;
  +   args = modparrot_getargs();
  +
  +   if (args)
  +       return string_make(interpreter,args,strlen(args),NULL,0,NULL);
  +   else
  +       return string_make(interpreter,NULL,0,NULL,0,NULL);
  +}
  +
  +static STRING* get_remoteip(Interp* interpreter, KEY * key) {
  +   char* remote_ip;
  +   remote_ip = modparrot_get_remoteip();
  +
  +   if (remote_ip)
  +       return string_make(interpreter,remote_ip,strlen(remote_ip),NULL,0,NULL);
  +   else
  +       return string_make(interpreter,NULL,0,NULL,0,NULL);
  +}
   
   pmclass Apache {
   
  @@ -33,7 +52,6 @@
   
      void init (INTVAL size) {
         SELF->data=NULL;
  -      SELF->flags=PMC_private_GC_FLAG;
      }
   
      BOOLVAL move_to (void * destination) {
  @@ -134,11 +152,13 @@
      }
   
      STRING* get_string_keyed (KEY * key) {
  -       char* args;
  -       args = modparrot_getargs();
  -       printf("%s\n",args);
  -       if (args)
  -	   return string_make(INTERP,args,strlen(args),NULL,0,NULL);
  +      STRING* action = (&(key->atom))->val.string_val;
  +      
  +      /* should store these STRINGS premade for speed */
  +     if (string_compare(INTERP,action,string_make(INTERP,"get",3,NULL,0,NULL)) == 0) 
  +	  return get_args(INTERP,key);
  +      else if (string_compare(INTERP,action,string_make(INTERP,"remote_ip",9,NULL,0,NULL)) == 0)
  +	  return get_remoteip(INTERP,key);
          else
              return string_make(INTERP,NULL,0,NULL,0,NULL);
      }
  
  
  
  1.2       +4 -2      mod_parrot/eg/demo2.pasm
  
  Index: demo2.pasm
  ===================================================================
  RCS file: /cvs/public/mod_parrot/eg/demo2.pasm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- demo2.pasm	23 May 2002 03:23:35 -0000	1.1
  +++ demo2.pasm	28 May 2002 18:17:28 -0000	1.2
  @@ -1,6 +1,8 @@
           new P0,Apache
          	get_keyed S0,P0,"get"
  +	concat S0, "you passed me ", S0
  +        set_keyed P0,"print",S0
  +	get_keyed S0,P0,"remote_ip"
  +	concat S0, "Hello there at ", S0
           set_keyed P0,"print",S0
  -        set_keyed P0,"print","hello again"
  -        print P0
   	end
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.