samirpatry has asked for the wisdom of the Perl Monks concerning the following question:


Hi Monks

I have a perl program which first authenticate the user name and password .So i have to use the MD5 to check the authenticate.I know there is a module Digest::MD5 will easy this process .but i want to implement this using inline::c.My probelm is that in C MD5 there is a main program and which use diffrent header file.When i open it in VC++ it will create a workspace.So is there any way to add the workspace to my perl program using Inline::c.so that i will pass the required data by argument and return the value.

Any hint/ref will help me a lot
  • Comment on How to Add MD5 C program using Inline::C to a perl program???

Replies are listed 'Best First'.
Re: How to Add MD5 C program using Inline::C to a perl program???
by Velaki (Chaplain) on Oct 19, 2006 at 13:23 UTC

    If your C code can be compiled to a library, then you can specify that lib to be linked in the use Inline portion of your code, as per Inline::C.

    Depending upon the complexity of your c code, and the kind of perl interface you want, you might want to build an XS module for your project.

    As for adding a VC++ workspace, I'm not sure about that.

    Hope this helped,
    -v.

    "Perl. There is no substitute."
Re: How to Add MD5 C program using Inline::C to a perl program???
by syphilis (Archbishop) on Oct 19, 2006 at 13:49 UTC
    My probelm is that in C MD5 there is a main program and which use diffrent header file

    That shouldn't be a problem. If the C program contains:
    #include <some_header.h>
    then you just need to start the Inline::C section of your script with:
    use Inline C => <<'EOC'; #include <some_header.h> . .
    or perhaps:
    use Inline C => <<'EOC'; #include "full/path/to/some_header.h" . .
    Other than that, you just need to rewrite your main() program as a C function that returns the string you're after.

    Cheers,
    Rob

      I agree with your point and already worked on that .But the MD5 is a written in C and it has a workspace which i want to add in to my perl program.so that i just pass the argument like pszAlg, pszUser, pszRealm, pszPass, pszNonce,pszCNonce, HA1 from my perl program and obtain the value return from the C MD5.
        I agree with your point and already worked on that .But the MD5 is a written in C and it has a workspace which i want to add in to my perl program.

        I apologize since I've not touched C in quite a lot of years, but sincerely I can't remember "workspaces" in C. So, what is a workspace? What is the corresponding Perl structure/concept/whatever it should be translated into?

        so that i just pass the argument like pszAlg, pszUser, pszRealm, pszPass, pszNonce,pszCNonce, HA1 from my perl program and obtain the value return from the C MD5.

        I'm not really sure if I understand what you mean:

        pszAlg, pszUser, pszRealm, pszPass, pszNonce,pszCNonce, HA1

        these are not valid Perl identifiers or values, unless you mean them to be subs, so I don't see how you can pass them "from your perl program", and if they are subs, then what's the problem with

        my $md5=MD5_XS_sub(pszAlg, pszUser, pszRealm, pszPass, pszNonce,pszCNo +nce, HA1); # ?!?
Re: How to Add MD5 C program using Inline::C to a perl program???
by cdarke (Prior) on Oct 19, 2006 at 14:18 UTC
    A VC++ workspace contains projects, which contain configurations. Workspaces (now called 'Solutions' in VC .Net) are specific to that IDE, and I can't see how you (could)/(would want to) add it to Inline.c.
    You might be better creating an XS DLL workspace/project with your C MD5 program as part of it (assuming there is no 'main').
Re: How to Add MD5 C program using Inline::C to a perl program???
by syphilis (Archbishop) on Oct 19, 2006 at 14:06 UTC
    you might want to build an XS module for your project

    I've often wondered whether there is something that can be handled by XS and that cannot be handled by Inline::C. When I look at the XS file that Inline::C generates, I find that it invariably contains "PROTOTYPES: DISABLE" - which leads me to believe that there may well be instances where Inline::C fails but XS succeeds (eg those instances where one needs to specify "PROTOTYPES: ENABLE" ... if such instances exist). Does anyone have a simple example of something that can be done using XS, but cannot be done using Inline::C ?

    Sorry, Velaki, this question is not addressed specifically to you. It should probably be raised as a separate thread ... which is something I may yet do.

    Cheers,
    Rob
      I don't think you'll find such an example. XS compiles down to C code just like Inline::C does, so anything you can do in XS you can probably do in Inline::C too, if only by copying the generated XS C code! The critical difference is which one will be easier - XS makes some things easy (mapping complex C types into Perl and back) and Inline::C makes other things easy (writing new code in C).

      -sam