pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
5+ messages / 4 participants
[nested] [flat]

* Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
@ 2001-04-15 21:27 Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-16 14:03 ` Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 1 reply; 5+ messages in thread

From: Lonnie Cumberland @ 2001-04-15 21:27 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-interfaces

Hello All,

That fixed the problem I think as I am no longer getting the loading errors and
the functions appear to be being called.

I now have a simple question about the use of these VARDATA() VARSIZE() and
VARHDRSZ() wrappers

I tried to make the modifications using the manual for reference, but there
seems to be little information related to these VAR???() wrappers and my simple
routine went off into never-never land.

I have a simple function that used to work with individual pointers.

My original simple routine:
------------------------------------------------------------------------------
void public_to_enc(char *public_userid, char *enc_userid )
{
    char ch[3];
    int i,j;
    char buff[5];
    int sp=0;
 
    // Clear out the public_userid place
    strcpy(enc_userid,"");
 
    while(*public_userid!='\0')
    {
        ch[0]=*public_userid;
        ch[1]=*(public_userid+1);
        i=atoi(ch);
        j=i;
        sp++;

        //      printf("48 sect --- i=%d\n",i);
        if((i>=1)&&(i<=10))
        {
                i+=47;
        }
        else
        //      printf("65 sect --- i=%d\n",i);
        if((i>=11)&&(i<=36))
        {
                i+=54;
        }
        else
        //      printf("97 sect --- i=%d\n",i);
        if((i>=37)&&(i<=62))
        {
                i+=60;
         }
         else
         printf("public_enc: ERROR !!!!\n\n");
 
        sprintf(buff,"%c",i);
 
        // Add the value to our string
        strcat(enc_userid,buff);
 
        public_userid+=2;
        }
}                                                                              

------------------------------------------------------------------------------

and my new modified routine of the above:
------------------------------------------------------------------------------
text *
encode(text *enc_userid)
{
    int32 new_text_size = VARSIZE(enc_userid) * 2 - VARHDRSZ;
    text *new_text = (text *) palloc(new_text_size);
 
    // Clear out the public_userid place
    memset((void *) new_text, 0, new_text_size);
 
    VARSIZE(new_text) = new_text_size;
 
    // range values
    //          (0 - 9)  ---- dec 48 - 57 ascii
    //          (A - Z)  ---- dec 65 - 90 ascii
    //          (a - z)  ---- dec 97 - 122 ascii
    char ch;
    int i,j;
    char buff[5];
    int sp=0;
 
    while(VARDATA(enc_userid)!='\0')
    {
        ch=VARDATA(enc_userid);
        i=ch;
        j=i;
        sp++;
        //      printf("48 sect --- i=%d\n",i);
        if((i>=48)&&(i<=57))
        {
                i-=47;
        }
        //      printf("65 sect --- i=%d\n",i);
        else
        if((i>=65)&&(i<=90))
        {
                i-=54;
        }
        else
        //      printf("97 sect --- i=%d\n",i);
        if((i>=97)&&(i<=122))
        {
                i-=60;
        }
        else
        printf("public encoder: ERROR !!!!\n\n");
 
        sprintf(buff,"%02d",i);
 
        // Add the value to our string
        strcat(VARDATA(new_text),VARDATA(buff));
 
        enc_userid++;
        }
    // Add the value to our string
    strcat(VARDATA(new_text),VARDATA("\0"));
 
    return (new_text);
}                                              
-------------------------------------------------------------------------------

The problem is that I do not think that I have converted the second version
over correctly and would like to know if someone could take a look to see what
might be wrong.

Also, I just wanted to say that I really appreciate all of the help that you
you have given me to get started using this interface with PostgreSQL.

Best Regards,
Lonnie



--- Peter Eisentraut <peter_e@gmx.net> wrote:
> Lonnie Cumberland writes:
> 
> > trdata=# select concat_text('a','d');
> > ERROR:  Load of file /test/trfuncs.so failed: /test/trfuncs.so: undefined
> > symbol: MemoryContextAlloc__FP17MemoryContextDataUi
> 
> Name mangling at its finest.  You need to put extern "C" around all
> #include's of PostgreSQL header files as well.
> 
> -- 
> Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter
> 


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
  2001-04-15 21:27 Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Lonnie Cumberland <lonnie_cumberland@yahoo.com>
@ 2001-04-16 14:03 ` Peter Eisentraut <peter_e@gmx.net>
  2001-04-20 11:11   ` Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Brendan Guenther <guenthe8@msu.edu>
  0 siblings, 1 reply; 5+ messages in thread

From: Peter Eisentraut @ 2001-04-16 14:03 UTC (permalink / raw)
  To: Lonnie Cumberland <lonnie_cumberland@yahoo.com>; +Cc: pgsql-interfaces

Lonnie Cumberland writes:

> I now have a simple question about the use of these VARDATA() VARSIZE() and
> VARHDRSZ() wrappers

VARDATA is a pointer (to char?) to where the actual data of the specific
value starts.  VARSIZE is the length of the specific value, plus the
header.  VARHRDZ is the size of the header, currently always 4.  For
example, if you have a text string 'abc' then the memory representation is

int	4	<-- text* points here
char	'a'	<-- VARDATA points here
char	'b'
char	'c'

VARHDRZ == 4, VARSIZE = 7

Note that the data is not null-terminated.

The best things might be not to mess with this but call textin() and
textout() to convert your data to C strings.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
  2001-04-15 21:27 Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-16 14:03 ` Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Peter Eisentraut <peter_e@gmx.net>
@ 2001-04-20 11:11   ` Brendan Guenther <guenthe8@msu.edu>
  2001-04-20 13:12     ` Re: Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-20 21:34     ` Re: Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 5+ messages in thread

From: Brendan Guenther @ 2001-04-20 11:11 UTC (permalink / raw)
  To: pgsql-interfaces



Peter Eisentraut wrote:

> The best things might be not to mess with this but call textin() and
> textout() to convert your data to C strings.

I can't seem to find documentation for textin() and textout() can somebody point
me in the right direction for this or provide an example.  I'm having similar
problems that Lonnie is having with VARDATA and I think this might help.  I'm
trying to link in a C function that makes use of OpenSSL's libcrypto functions.

Basically I just need to hash and verify passwords in the database, so as an
alternate question, if I'm missing something and there is a better way to do
password storage let me know.

Thanks,
--
Brendan Guenther
guenthe8@msu.edu




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
  2001-04-15 21:27 Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-16 14:03 ` Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Peter Eisentraut <peter_e@gmx.net>
  2001-04-20 11:11   ` Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Brendan Guenther <guenthe8@msu.edu>
@ 2001-04-20 13:12     ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Lonnie Cumberland @ 2001-04-20 13:12 UTC (permalink / raw)
  To: Brendan Guenther <guenthe8@msu.edu>; +Cc: pgsql-interfaces

Hello Brendan,

I too was having this problem, but now think that I am getting a very good
handle on these interfaces.

Being that you are trying to hash the standard unix crypt function to look over
the password file, I think that this solution might help you.

I have a simple an efficient C++ solution to this problem:

My "unixcrypt" functions now looks like this
                                         
---------------------------------------------------------------
text *unix_encrypt(text *inarg, text *inpass)
{
        char temp[25];
        int temp_len;
 
        // Take the "text" variables directly to the "strings"
        string instr(VARDATA(inarg),0,VARSIZE(inarg)-VARHDRSZ);
        string passPhrase(VARDATA(inpass),0,VARSIZE(inpass)-VARHDRSZ);
 
        strcpy(temp,crypt(instr.c_str(),passPhrase.c_str()));
        temp_len=strlen(temp);
 
        string outstr(temp,0,temp_len);
         
        // Set up the outgoing DB "text" variable
        int32      new_text_size = outstr.size()+4;
        text       *new_text = (text *) palloc(new_text_size);
        memset((void *) new_text, 0, new_text_size);
        VARATT_SIZEP(new_text) = new_text_size;
 
        // Move the variable over from the string
        strncpy(VARDATA(new_text),outstr.c_str(),outstr.size());
 
        return new_text;
}
----------------------------------------------------------------------------

Be sure to include the header:

#include <unistd.h>             // for unix crypt function  

---------------------------------------------------------------------------

hope that this helps,

Lonnie

--- Brendan Guenther <guenthe8@msu.edu> wrote:
> 
> 
> Peter Eisentraut wrote:
> 
> > The best things might be not to mess with this but call textin() and
> > textout() to convert your data to C strings.
> 
> I can't seem to find documentation for textin() and textout() can somebody
> point
> me in the right direction for this or provide an example.  I'm having similar
> problems that Lonnie is having with VARDATA and I think this might help.  I'm
> trying to link in a C function that makes use of OpenSSL's libcrypto
> functions.
> 
> Basically I just need to hash and verify passwords in the database, so as an
> alternate question, if I'm missing something and there is a better way to do
> password storage let me know.
> 
> Thanks,
> --
> Brendan Guenther
> guenthe8@msu.edu
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://www.postgresql.org/search.mpl


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
  2001-04-15 21:27 Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-16 14:03 ` Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Peter Eisentraut <peter_e@gmx.net>
  2001-04-20 11:11   ` Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Brendan Guenther <guenthe8@msu.edu>
@ 2001-04-20 21:34     ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 5+ messages in thread

From: Tom Lane @ 2001-04-20 21:34 UTC (permalink / raw)
  To: Brendan Guenther <guenthe8@msu.edu>; +Cc: pgsql-interfaces

>> The best things might be not to mess with this but call textin() and
>> textout() to convert your data to C strings.

textin() and textout() are notationally painful to call these days.
Personally I think it's just as easy to do your own manipulation of
text objects.  There are examples at

http://www.postgresql.org/users-lounge/docs/7.1/postgres/xfunc-c.html

--- see the copytext and concat_text() samples in particular.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2001-04-20 21:34 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-15 21:27 Now for the VARDATA, VARSIZE, and VARHDRSZ stuff Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-16 14:03 ` Peter Eisentraut <peter_e@gmx.net>
2001-04-20 11:11   ` Brendan Guenther <guenthe8@msu.edu>
2001-04-20 13:12     ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-20 21:34     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox