[Courses] How to get line-information from buffer..
Conor Daly
conor.daly at oceanfree.net
Mon Sep 30 21:49:00 EST 2002
This might be better sent to the programming list...
On Mon, Sep 30, 2002 at 03:26:53AM -0700 or so it is rumoured hereabouts,
Abel Pires da Silva thought:
> Thank you for your help..
> I think I have to be more specific...
> I'm reading a socket descriptor and open a file
> containt with some addresses, and (here is the most
> important thing...) make comparation is there any
> "line" match between the two.
Just clear up something here:
A) Do you wish to match an _entire_ line?
B) Do you wish to match _part_ of a line?
C) Do you wish to match _any_ line in the buffer with _any_ line in the file?
D) Do you wish to match _part_ of _any_ line in the buffer with _part_ of
_any_ line in the file?
I think you mean D above...
> Here is the situation:
> I have buffer containt some thing like this:
>
> GET / HTTP/1.0
> Connection: Keep-Alive
> User-Agent: Mozilla/4.75 [en] (X11; U; Linux
> 2.2.17-21mdk i686)
> Host: localhost:8000
> Accept: image/gif, image/x-xbitmap, image/jpeg,
> image/pjpeg, image/png, */*
> Accept-Encoding: gzip
> Accept-Language: en
> Accept-Charset: iso-8859-1,*,utf-8
>
> In the other hand, I have a file containt some
> information (addresses, restricted words, or whatever)
> like this:
> yahoo.com
> hotmail.com
> cnn.com
> abc.com
> ..
> ..
>
> I'm at this stage:
> /* reading socket descriptor */
> read=(socket_desdriptor, buffer, sizeof (buffer));
>
> /* then open the file tabel.txt */
> PF=fopen ("tabel.txt", "r");
>
> /* getting the file content */
> while ((fgets (stream, 20, PF);
>
> last step is to make comparation between *stream* and
> *buffer*...is there any match between the two
> strings...
You need to do something like:
for each line in *buffer {
for each line in *file {
if ((strstr(buffer,file)) != NULL ) {
Do stuff for line match
}
}
}
> For the strings with only 'single' line in it, is not
> a problem...
> But for the strings with several even hundreds of
> line, I REALLY NEED YOUR HELP...
Since you will probably have a steady flow of *buffer for each connection,
you should think about loading all of *file into memory at the start of
the program instead of reading from disk each time. You will need to
think of dynamic allocation of memory to do this with a file that changes.
Look at malloc() and free() for this.
> I'm sorry for my english, becouse I'm from East
> TImor...
Good English. Good to hear of your country's independence also...
Conor
--
Conor Daly <conor.daly at oceanfree.net>
Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
9:38pm up 31 days, 2:05, 0 users, load average: 0.00, 0.00, 0.00
Hobbiton.cod.ie
9:32pm up 31 days, 1:41, 2 users, load average: 0.06, 0.09, 0.07
More information about the Courses
mailing list