RE: [dspam-users] Example.c File

From: . kibble . <jelly_bean_junky@hotmail.com>
Date: Sat Sep 10 2005 - 13:32:21 EDT

I believe that you could be right, but not directly because of an upgrade to
the DSpam API but an upgrade of my operating system [OpenBSD], maybe because
of both...

It could have been fluke as well [difficult to tell 100%] but the code I
originally written seemed to have worked on different O/S's [Linux RedHat &
Fedora] so it could primarily be down to the DSpam API.

There are some interesting points you have raised, and something I do intend
to look into once with a little more time, but as the saying goes, if it's
not broke, then don't try to fix it...
I think I may leave it for a while as I'm just happy that it is working now.

Regards, and all the best, kibble

>From: "Russ Fink" <russfink@hotmail.com>
>To: jelly_bean_junky@hotmail.com
>CC: dspam-users@lists.nuclearelephant.com
>Subject: RE: [dspam-users] Example.c File
>Date: Sat, 10 Sep 2005 10:51:04 -0400
>
>The fact that it worked before (with a different version of dspam) might
>have been a fluke. I've had many cases of pointer problems being masked
>for months if not years, and then a change to the "shape" of the memory has
>caused the problems to appear.
>
>By memory shape, I mean layout of structures in memory, alignment on or
>around memory page boundaries, size of call stacks which can be changed by
>use of new structures, changing definitions of existing structures, adding
>or subtracting variables, even adding or subtracting significant amounts of
>code.
>
>I suspect the simple act of upgrading the dspam api might have caused your
>memory shape to have changed, exposing an existing problem.
>
>You may want to run valgrind (free memory debugger for Linux) on your
>system, and watch particularly for uninitialized memory usage and
>misaligned memory access. Be sure to exercise as many paths of your code
>as possible. I have a theory that memory errors are most often accompanied
>by logic errors in nearby locations, such that running a memory debugger
>often leads to other problems being detected and fixed.
>
>>From: ". kibble ." <jelly_bean_junky@hotmail.com>
>>
>>Got it working, however not in a way that I totally think is right... I've
>>classified the message to generate the signature [&SIG] and then set it as
>>you pointed out was wrong in the last email.
>>
>>However I'm not entirely sure why it worked before and not now... Was
>>there some piece of code which worked out that CTX->signature was NULL and
>>then reclassified the message anyways?? If this has changed, I'm curious
>>to know why exactly, redundant code perhaps... Only the developers will
>>know. [Care to shed any light in this area]
>>
>>Anyway's, here what I did for future use and thank you for the help:
>>/** some function or another... */
>> int sflag = 0;
>> char * message = malloc(1);
>> DSPAM_CTX * CTX = NULL; /** DSPAM Context */
>> struct _ds_spam_signature SIG; /** Example signature */
>>
>> message = read_emailmem(message);
>>
>> switch (spamflag) {
>> case SPAMREPT: /** set up the context for error correction as spam */
>> /** log_write(0, LOG_MAIN, "LOG: SPAMREPT function reached"); */
>> CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS,
>>DSF_CHAINED);
>> CTX = attach_ctx_dbaccess(CTX);
>> if (CTX == NULL) {
>> log_write(0, LOG_MAIN, "ERROR: dspam_create failed!\n");
>> sflag = 1;
>> }
>> CTX->classification = DSR_ISSPAM;
>> CTX->source = DSS_ERROR;
>> CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
>> break;
>> case FALSEPOS: /** set up the context for error correction as innocent
>>*/
>> /** log_write(0, LOG_MAIN, "LOG: FALSEPOS function reached"); */
>> CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS,
>>DSF_SBPH | DSF_SIGNATURE | DSF_NOISE);
>> CTX = attach_ctx_dbaccess(CTX);
>> if (CTX == NULL) {
>> log_write(0, LOG_MAIN, "dspam_create failed!");
>> break;
>> }
>> CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
>> if (dspam_process(CTX, message) != 0) { /** Call DSPAM's processor with
>>the message text */
>> log_write(0, LOG_MAIN, "dspam_process failed!");
>> dspam_destroy(CTX);
>> break;
>> }
>> if (CTX->signature != NULL) {
>> SIG.data = malloc(CTX->signature->length);
>> if (SIG.data != NULL) {
>> memcpy(SIG.data, CTX->signature->data, CTX->signature->length);
>> }
>> }
>> SIG.length = CTX->signature->length;
>>
>> dspam_destroy(CTX); /** Destroy the context */
>> memset(&CTX, 0x0, sizeof(CTX));
>> free(CTX);
>>
>> CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS,
>>DSF_CHAINED | DSF_SIGNATURE);
>> CTX = attach_ctx_dbaccess(CTX);
>> if (CTX == NULL) {
>> log_write(0, LOG_MAIN, "ERROR: dspam_create failed!\n");
>> sflag = 1;
>> }
>> CTX->classification = DSR_ISINNOCENT;
>> CTX->source = DSS_ERROR;
>> CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
>> CTX->signature = &SIG; /** Attach the signature to the context */
>> break;
>> default: /** no reporting required, scan for spam perhaps ? */
>> log_write(0, LOG_MAIN, "report_spam -> no reporting required");
>> break;
>> }
>>
>> /** log_write(0, LOG_MAIN, "LOG: Processing spam..."); */
>> if (dspam_process(CTX, message) != 0) { /** Call DSPAM */
>> log_write(0, LOG_MAIN, "ERROR: dspam_process failed!");
>> sflag = 1;
>> }
>>
>>/** end of snippit */
>>
>>>From: ". kibble ." <jelly_bean_junky@hotmail.com>
>>>To: dspam-users@lists.nuclearelephant.com
>>>Subject: RE: [dspam-users] Example.c File
>>>Date: Wed, 07 Sep 2005 22:11:47 +0100
>>>
>>>
>>>Excellent, thanks for the pointer, I will do this over the next few days
>>>as I'm away but will take the laptop with me and a copy of dspam's source
>>>code to review...
>>>
>>>>From: "Russ Fink" <russfink@hotmail.com>
>>>>To: jelly_bean_junky@hotmail.com, dspam-users@lists.nuclearelephant.com
>>>>Subject: RE: [dspam-users] Example.c File
>>>>Date: Wed, 07 Sep 2005 11:21:22 -0400
>>>>
>>>>Sorry, I have been out for a few days.
>>>>
>>>>From your code snippet, I don't see where SIG is getting populated, just
>>>>declared. The code sets CTX->signature to &SIG, but SIG has nothing in
>>>>it - just an empty structure at this point. You need to populate it
>>>>using the driver of MySQL.
>>>>
>>>>My advice, what I would have to do, is look at how dspam.c does it.
>>>>Grep for "signature" and you should find the answer.
>>>>
>>>>In generic terms, the spam "signature" is really a unique identifier
>>>>assigned by the back-end database implementation. In the case of
>>>>sqlite3, it takes a hash of the system time and date and assigns that as
>>>>the signature of the message. Of course, this assumes only one message
>>>>is processed at a given time/date, and I believe this will be changed at
>>>>some point in the future. The "CTX->signature" is a pointer to the
>>>>signature structure, which is created from this hash by a call.
>>>>
>>>>If you're using pristine mode, no signature is needed, and no signature
>>>>is generated.
>>>>
>>>>Spend some time with dspam.c and it should help. I think that's kinda
>>>>what everyone else does that programs directly to the API.
>>>>
>>>>Russ
>>>>
>>>>>>>int report_spam(int spamflag) {
>>>>>>>
>>>>>>> int sflag = 0;
>>>>>>> char * message = malloc(1);
>>>>>>> DSPAM_CTX * CTX = NULL; /** DSPAM Context */
>>>>>>> struct _ds_spam_signature SIG; /** Example signature */
>>>>>>>
>>>>>>> message = read_emailmem(message);
>>>>>>>
>>>>>>> switch (spamflag) {
>>>>>>> case SPAMREPT: /** set up the context for error correction
>>>>>>>as spam */
>>>>>>> log_write(0, LOG_MAIN, "LOG: SPAMREPT function reached");
>>>>>>> CTX = dspam_create((char *)sender_address, NULL, NULL,
>>>>>>>DSM_PROCESS, DSF_CHAINED);
>>>>>>> CTX = attach_ctx_dbaccess(CTX);
>>>>>>> if (CTX == NULL) {
>>>>>>> log_write(0, LOG_MAIN, "ERROR: dspam_create
>>>>>>>failed!\n");
>>>>>>> sflag = 1;
>>>>>>> }
>>>>>>> CTX->classification = DSR_ISSPAM;
>>>>>>> CTX->source = DSS_ERROR;
>>>>>>> CTX->algorithms = DSA_GRAHAM | DSA_BURTON |
>>>>>>>DSP_GRAHAM;
>>>>>>> break;
>>>>>>> case FALSEPOS: /** set up the context for error correction
>>>>>>>as innocent */
>>>>>>> log_write(0, LOG_MAIN, "LOG: FALSEPOS function reached");
>>>>>>> CTX = dspam_create((char *)sender_address, NULL, NULL,
>>>>>>>DSM_PROCESS, DSF_CHAINED | DSF_SIGNATURE);
>>>>>>> CTX = attach_ctx_dbaccess(CTX);
>>>>>>> if (CTX == NULL) {
>>>>>>> log_write(0, LOG_MAIN, "ERROR: dspam_create
>>>>>>>failed!\n");
>>>>>>> sflag = 1;
>>>>>>> }
>>>>>>> CTX->classification = DSR_ISINNOCENT;
>>>>>>> CTX->source = DSS_ERROR;
>>>>>>> CTX->algorithms = DSA_GRAHAM | DSA_BURTON |
>>>>>>>DSP_GRAHAM;
>>>>>>> CTX->signature = &SIG; /** Attach the signature to
>>>>>>>the context */
>>>>>>> break;
>>>>>>> default: /** no reporting required, scan for spam perhaps
>>>>>>>? */
>>>>>>> log_write(0, LOG_MAIN, "report_spam -> no reporting
>>>>>>>required");
>>>>>>> break;
>>>>>>> }
>>>>>>>
>>>>>>> log_write(0, LOG_MAIN, "LOG: Processing spam...");
>>>>>>> if (dspam_process(CTX, message) != 0) { /** Call DSPAM */
>>>>>>> log_write(0, LOG_MAIN, "ERROR: dspam_process failed!");
>>>>>>> sflag = 1;
>>>>>>> }
>>>>>>>
>>>>>>> log_write(0, LOG_MAIN, "ERROR: report_spam: dspam_destroy
>>>>>>>beginning");
>>>>>>> dspam_destroy(CTX); /** Destroy the context */
>>>>>>>
>>>>>>> memset(message, 0x0, sizeof(message));
>>>>>>> free(message);
>>>>>>> memset(&CTX, 0x0, sizeof(CTX));
>>>>>>> free(CTX);
>>>>>>>
>>>>>>> if (sflag == 0) {
>>>>>>> log_write(0, LOG_MAIN, "<= %s [%s] P=%s A=%s:%s",
>>>>>>> (char *)sender_address, (char *)sender_host_address,
>>>>>>>(char *)received_protocol,
>>>>>>> (char *)sender_host_authenticated, (char
>>>>>>>*)sender_address);
>>>>>>> log_write(0, LOG_MAIN, "=> (null) <%s> R=system_localuser
>>>>>>>T=local_delivery",
>>>>>>> (char *)recipients_list[0].address);
>>>>>>> }
>>>>>>>
>>>>>>> /** if we are reporting, which is pretty much so if you reach
>>>>>>>here, we blackhole the email */
>>>>>>> recipients_count = 0;
>>>>>>>
>>>>>>> return(sflag);
>>>>>>>} /** report_spam */
>>>>
>>>>
>>>
>>>_________________________________________________________________
>>>Be the first to hear what's new at MSN - sign up to our free newsletters!
>>>http://www.msn.co.uk/newsletters
>>>
>>>
>>
>>_________________________________________________________________
>>MSN Messenger 7.5 is now out. Download it for FREE here.
>>http://messenger.msn.co.uk
>>
>>
>
>
>

_________________________________________________________________
The new MSN Search Toolbar now includes Desktop search!
http://toolbar.msn.co.uk/
Received on Sat Sep 10 13:33:30 2005

This archive was generated by hypermail 2.1.8 : Thu Sep 29 2005 - 13:51:29 EDT