Solved

#ifdef HAVE_OPENSSL is failed

Posted on 2006-11-19
5
890 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

777 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