Solved

#ifdef HAVE_OPENSSL is failed

Posted on 2006-11-19
5
886 Views
Last Modified: 2008-02-01
Hi Experts,
I am trying to connect MySQL through C code on SSL. I have written like:

==========================================
MYSQL *mysql_conn(connection_info *conn_info)
{
    MYSQL *connect;
    connect=mysql_init(NULL);
   if(connect==NULL)
   {
       printf("FAILED\n[-] init mysql failed:%s\n",mysql_error(connect));
       return NULL;
   }
 
  #ifdef HAVE_OPENSSL                                                                       // IFDEF CONDITION
   int in = mysql_ssl_set(connect,"certs/client-key.pem",
    "certs/client-cert.pem",
    "certs/ca-cert.pem", 0, 0);
     // printf("%d\n", in);
   #endif

   /* Connect to database */
   if(mysql_real_connect(connect,conn_info->server,conn_info->user,conn_info->password,conn_info->database,conn_info->port,NULL,0)==NULL)
   {
          printf("FAILED\n[-] Error: %s\n",mysql_error(connect));
          return NULL;
    }
    return connect;
}
================================================

It's giving error on "IFDEF CONDITION". When I remove this condition, code is working fine. However, it has suggested in tutorial that I should use that IFDEF CONDITION.
What is the problem with that condition, which approach would be better for me, I don't have have idea about that.
Please provide some solution for this problem.
0
Comment
Question by:rrahulgupta
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 17976772
Since you're trying to keep your actual problem a secret (it is always nice to know what is going wrong, error message, compiler/linker/runtime error etc.), i can just guess that your compiler is very strict about C and does not like the declaration of 'in' at that place. Try

MYSQL *mysql_conn(connection_info *conn_info)
{
  #ifdef HAVE_OPENSSL                                                                      
    int in;
  #endif

    MYSQL *connect;
    connect=mysql_init(NULL);
   if(connect==NULL)
   {
       printf("FAILED\n[-] init mysql failed:%s\n",mysql_error(connect));
       return NULL;
   }
 
  #ifdef HAVE_OPENSSL                                                                       // IFDEF CONDITION
   in = mysql_ssl_set(connect,"certs/client-key.pem",
    "certs/client-cert.pem",
    "certs/ca-cert.pem", 0, 0);
     // printf("%d\n", in);
   #endif

   /* Connect to database */
   if(mysql_real_connect(connect,conn_info->server,conn_info->user,conn_info->password,conn_info->database,conn_info->port,NULL,0)==NULL)
   {
          printf("FAILED\n[-] Error: %s\n",mysql_error(connect));
          return NULL;
    }
    return connect;
}
0
 
LVL 1

Assisted Solution

by:i_mahesh
i_mahesh earned 50 total points
ID: 17978045
as jkr as suggested
one of the causes could be the due to the place where the declaration of the int variable is happening.

but it would be helpful to give out the error information you are getting (Like the error string and error code)
0
 

Author Comment

by:rrahulgupta
ID: 17979759
when i set
#define HAVE_OPENSSL 1
then it's working fine.
Does MySQL Client API not defined this macro?
0
 
LVL 86

Expert Comment

by:jkr
ID: 17980376
Yes.
0
 

Author Comment

by:rrahulgupta
ID: 17982114
thanks :)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now