Thread: Apache Module - string question

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    Apache Module - string question

    Hi guys,
    i've been trying too modify an apache module to write some stuff to a text file - and i'm struggling to get the last character off the url (trying to match against "/" or print to a file)

    i've tried the methods from here - How do I get the last character of a string?

    But I think i'm missing something... this is the code i've got

    Code:
    	    char mystr[50];
    	    mystr = "this is a string//"; //r->uri;
    	    end_char = mystr[(strlen(mystr)-1)];
    
    		if(strrchr(mystr,"/") == (strlen(mystr) - 1)) {
    		    fprintf(files, "end char: %s\n",  "slash");
    		} else {
    		    fprintf(files, "end char: %s\n",  "no slash");
    		}
    		    fprintf(files, "efef: %s\n", end_char );
    		    
    		    fprintf(files, "str length: %u - %u\n",  strlen(mystr),strrchr(mystr,"/"));
    many different methods - trying to get the last character.

    Can anyone shed any light on what i'm doing wrong.

    EDIT: The writing to files works - and this is just a snippet

    Thanks

    Mark Willis
    Last edited by markwillis82; 03-24-2010 at 04:54 AM.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    You're trying to write an Apache module and you don't know basic string handling??? That's ambitious.

    Code:
    "/"
    is not a single character; it's an array of two characters, '/' and '\0'.

    strrchr returns a pointer to the last character...why are you comparing the return value to the length of the string - 1?

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    I'm not writing an apache module - just making a few tweaks too an already working one, i'm a web developer by day (LAMP) and all off my other modifications work lovely - just this one causing me a headache.

    All I need to do is check whether the last character in the string is a trailing slash (so: "domain.com/something/this" returns false, but "domain.com/something/this/" returns true

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your end_char gives you the last char of the string, I don't understand why you don't use it?

    Code:
    if( end_char == '/') {
      do this
      and that
    }
    else {
      do something else
      and then this too
    }

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    I see where I went wrong - I guess " and ' act differently in C. as that works lovely - Thanks Adak.

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    I've got some more questions if your able to help me?

    At the moment i've modified the mod_evasive apache module to log attacks rather then ban them - this lets me do some post processing on the log files - currently it uses hash tables (ntt?) to store timestamps and hit counts, I would like to modify this to store a list of hit urls also - but this is beyond my current level of C.

    Would someone be able to take a quick look?

    Thanks...

    (see attached file)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reusing a string pointer question
    By chiefmonkey in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2009, 04:53 PM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  3. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM