Re: translate_name and/or map_to_storage hooks
Sam Carleton wrote: On 3/27/07, Sam Carleton [EMAIL PROTECTED] wrote: On 3/27/07, Issac Goldstand [EMAIL PROTECTED] wrote: More importantly, lets say my module is called mod_coolapp and when I have it installed, you get to it at /coolapp. I want /coolapp to be the equivalent to the index.php and then have say, /coolapp/images be the same as imageHandler.php. Is there any trick to knowing which page is being requested or is it simply a matter of doing a string compare to see if the first part of the string passed the actual URL (/coolapp/) is images? You're going to want to parse/compare the string. The Right Way(tm) to do this would probably be during the translate_name or possibly map_to_storage hooks to separate the URI mapping logic from the actual response processing logic. You totally lost me with the translate_name and map_to_storage, I will have to do some reading on it. Issac, I am not exactly sure how I would leverage either the translate_name hook or map_to_storage hook. The best I can figure is that I should hook translate_name and this is the translation: /coolapp?params -- /coolapp?type=indexparams /coolapp/images?params -- /coolapp?type=imageparams Do I have the right idea? Sam Yes, it's the correct direction, but if you're just going to mangle the query string, you could just as easily do it with mod_rewrite. The only reason you'd need to code anything in your own module is if you want to, say, guarantee that params contains a valid image file before continuing the request chain; in such a scenario, you'd add a handler to map_to_storage which does at least a partial parsing of params and checks that the requested image exists, and if not aborts with a 404 error. Issac
Re: translate_name and/or map_to_storage hooks
Sam Carleton wrote: On 4/4/07, Sam Carleton [EMAIL PROTECTED] wrote: On 3/27/07, Sam Carleton [EMAIL PROTECTED] wrote: On 3/27/07, Issac Goldstand [EMAIL PROTECTED] wrote: More importantly, lets say my module is called mod_coolapp and when I have it installed, you get to it at /coolapp. I want /coolapp to be the equivalent to the index.php and then have say, /coolapp/images be the same as imageHandler.php. Is there any trick to knowing which page is being requested or is it simply a matter of doing a string compare to see if the first part of the string passed the actual URL (/coolapp/) is images? You're going to want to parse/compare the string. The Right Way(tm) to do this would probably be during the translate_name or possibly map_to_storage hooks to separate the URI mapping logic from the actual response processing logic. You totally lost me with the translate_name and map_to_storage, I will have to do some reading on it. Issac, I am not exactly sure how I would leverage either the translate_name hook or map_to_storage hook. The best I can figure is that I should hook translate_name and this is the translation: /coolapp?params -- /coolapp?type=indexparams /coolapp/images?params -- /coolapp?type=imageparams Do I have the right idea? I have been trying to move forward with the assumption that I am on the right track and continue to run unknowns. How do I identify coolapp as the location? In other words, I have this in my httpd.conf: Location /coolapp SetHandler my_cool_app /Location Inside of the translate_name hook, how do I go about determining that /coolapp is the location? Sam You can't via the normal methods. The Location is only mapped *after* translate_name (and map_to_storage, IIRC,) run. If you need to know this anyway, you'll need to do string comparisons on r-uri and friends Issac
Re: translate_name and/or map_to_storage hooks
On 4/6/07, Nick Kew [EMAIL PROTECTED] wrote: On Fri, 6 Apr 2007 00:51:52 -0400 Sam Carleton [EMAIL PROTECTED] wrote: (for now, assume that the whole application will be in the apache module.) That assumption seems fundamentally flawed. A substantial and complex application will be built from a number of modules, and is likely to mix preexisting components with new ones. If you're thinking of all your work being one module, then you need to take a step back and review it. A good startingpoint is one module per task. How many tasks does your application comprise? How many of those tasks can be accomplished using existing modules? It's also of course a valid approach to mix-and-match modules with other components such as scripts and backends. But I guess you see that as an intermediate stage in your work. Nick, I think I forgot to mention in the last post that what I am working on is a packaged solution with a GUI frontend. There are going to be two different distributions, the first will be installing apache and all the needed components with the GUI to run on one machine, the pro version will have the apache piece install on another machine, possibly a preexisting apache server. As I said before, I am completely, 100% open to how I should implement this whole application, I just don't want to get carried away using a million different technologies because it will make it that much harder to put together an install;) My goal is a one click install! I have been thinking of keeping the HTML piece in PHP. It sounds like you agree that is a logical approach, correct? Sam
Re: translate_name and/or map_to_storage hooks
On 05/04/07, Sam Carleton [EMAIL PROTECTED] wrote: On 4/5/07, Graham Dumpleton [EMAIL PROTECTED] wrote: On 05/04/07, Sam Carleton [EMAIL PROTECTED] wrote: I have one module that does a few different things. 1: create a index html document of images 2: create a page html document of one image (when user clicks on an image in the index) 3: Handle the image request that are in the HTML of #1 and #2 and send out all the images. Right now I have it all written in PHP, there is a index.php for #1 and #2 and an imageHandler.php for #3. I am trying to understand the best way to separate this logic within my one module. Someone else suggested I look at hooking translate_name. I found my answer to how to determine the location, so I have been playing with it since my post and when I set the r-filename = images; and return OK, I get a 403 Forbidden. Probably because you haven't allowed Apache access to the images directory. Ie., you still need to have something like: For starters, the objective is to do away with the PHP code altogether, I don't think I will do that in the first round, just replace the image handler, but I am thinking long term;) The way I have it configured is this: Location /coolapp SetHandler mod_my_cool_app Location I don't understand your comment about not allowing Apache access to the images directory, for starters, from the perspective of Apache, there isn't an images directory, it is elsewhere on the machine that Apache does not have and will not have access to, it is a security thing. But I don't think that is really relevant to the problem. When I type in /coolapp/images in a browser, my module does get called and the URI is /coolapp/images, why is it when I simply set the request's filename (r-filename) to images I get a 403? Apache did not have a problem with /coolapp/images, why would it have a problem with /coolapp/images/images? Or does filename mean something different? In a translate name handler, if you assign to r-filename then the map to storage phase will still kick in and ensure that Apache has access to whatever you set r-filename to. Thus, you still need a Directory directive corresponding to the physical location you set r-filename to that marks it as accessible. The translate name handler, unless you also override map to storage handler to work around it, is not really for setting the target to a virtual resource. I could try and suggest other approaches, but don't really grasp how you want all this to work so would just probably going around in circles. If in the first instance all you want to do is rewrite URLs to give a different view to the clients, I still suggest you at least first use mod_rewrite to produce what you want. I know you don't want to use mod_rewrite in the long run, but being able to see a set of mod_rewrite rules that demonstrate exactly what you want makes it easier for anyone to understand as it is clearer than some English description. Graham As I have told others on this wonderful mailing list, my 12+ years of software development have been in GUI development, not web. I have always played with web stuff, but this is my first serious web project and it is for my own new company! Ultimately I am trying to figure out, within the world of Apache modules, what is the best way to distinguish between the different general flow paths in my module. One being to generate HTML and the other to generate images. To the end user, I would like the URI for pages to simply be location/ and the URI for the images to be location/images. As it stands right now, I am thinking the easiest way is to simply check to see if the URI is location or location/images inside of the main handler. Someone else said that the right way to do it is to do this checking in the translate_name hook. Unless I am able to be enlightened, which is questionablegrin, I think I will do it the first way:( Sam
Re: translate_name and/or map_to_storage hooks
On 4/5/07, Graham Dumpleton [EMAIL PROTECTED] wrote: In a translate name handler, if you assign to r-filename then the map to storage phase will still kick in and ensure that Apache has access to whatever you set r-filename to. Thus, you still need a Directory directive corresponding to the physical location you set r-filename to that marks it as accessible. The translate name handler, unless you also override map to storage handler to work around it, is not really for setting the target to a virtual resource. Thank you, that does make sense. I could try and suggest other approaches, but don't really grasp how you want all this to work so would just probably going around in circles. If in the first instance all you want to do is rewrite URLs to give a different view to the clients, I still suggest you at least first use mod_rewrite to produce what you want. I know you don't want to use mod_rewrite in the long run, but being able to see a set of mod_rewrite rules that demonstrate exactly what you want makes it easier for anyone to understand as it is clearer than some English description. Graham, Here is my problem: I have been a C/C++ programmer for over 10 years and have been working in .Net for the last two, but it has ALL be on the desktop, I have very, very limited experience with web development. I am simply looking for the best, most flexible approach possible. In the short term, I am going to be keeping the HTML generation in PHP, depending on how hard it is to do this module (it is taking up a HUGE amount of time, though I am enjoying it) I would like to port the HTML generation to the module, also. With time the whole application will grow with complexity. From a HTML perspective, there is only two pages, one that displays indexes of images, the other that displays a larger view of one image. In time, there will be shopping charts, admin pages, extra. How do I want it all to tie together? I really don't know, I have never been able to find any good documentation on how to put together a complex web application and keep it manageable, thus this is ultimately the advise I am seeking. I am completely open to how it should all work. Any suggestions? (for now, assume that the whole application will be in the apache module.) Sam
Re: translate_name and/or map_to_storage hooks
On 05/04/07, Sam Carleton [EMAIL PROTECTED] wrote: On 4/4/07, Sam Carleton [EMAIL PROTECTED] wrote: On 3/27/07, Sam Carleton [EMAIL PROTECTED] wrote: On 3/27/07, Issac Goldstand [EMAIL PROTECTED] wrote: More importantly, lets say my module is called mod_coolapp and when I have it installed, you get to it at /coolapp. I want /coolapp to be the equivalent to the index.php and then have say, /coolapp/images be the same as imageHandler.php. Is there any trick to knowing which page is being requested or is it simply a matter of doing a string compare to see if the first part of the string passed the actual URL (/coolapp/) is images? You're going to want to parse/compare the string. The Right Way(tm) to do this would probably be during the translate_name or possibly map_to_storage hooks to separate the URI mapping logic from the actual response processing logic. You totally lost me with the translate_name and map_to_storage, I will have to do some reading on it. Issac, I am not exactly sure how I would leverage either the translate_name hook or map_to_storage hook. The best I can figure is that I should hook translate_name and this is the translation: /coolapp?params -- /coolapp?type=indexparams /coolapp/images?params -- /coolapp?type=imageparams Do I have the right idea? I have been trying to move forward with the assumption that I am on the right track and continue to run unknowns. How do I identify coolapp as the location? In other words, I have this in my httpd.conf: Location /coolapp SetHandler my_cool_app /Location Inside of the translate_name hook, how do I go about determining that /coolapp is the location? I missed out on the start of this conversion so really don't know what you are trying to do, but look at the source code for mod_alias in Apache as an example of how you can match a URI location to a specific resource in a translate name handler. In the case of mod_alias it matches it to a physical direction and applies different meanings to it depend on whether you are using Alias or ScriptAlias style directives. BTW, if all you are wanting to do is translate stuff like: /coolapp?params -- /coolapp?type=indexparams /coolapp/images?params -- /coolapp?type=imageparams why aren't you just using mod_rewrite? Graham
Re: translate_name and/or map_to_storage hooks
On 4/4/07, Graham Dumpleton [EMAIL PROTECTED] wrote: I missed out on the start of this conversion so really don't know what you are trying to do I have one module that does a few different things. 1: create a index html document of images 2: create a page html document of one image (when user clicks on an image in the index) 3: Handle the image request that are in the HTML of #1 and #2 and send out all the images. Right now I have it all written in PHP, there is a index.php for #1 and #2 and an imageHandler.php for #3. I am trying to understand the best way to separate this logic within my one module. Someone else suggested I look at hooking translate_name. I found my answer to how to determine the location, so I have been playing with it since my post and when I set the r-filename = images; and return OK, I get a 403 Forbidden. why aren't you just using mod_rewrite? This is going to be packaged software and I would, ideally, like to keep it all self contained so that end users that decide to start hacking things, cannot get too far.