Solved

#ifdef HAVE_OPENSSL is failed

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem in finding output of a program 11 106
Why is compiler in oracle server ? 9 75
Windows Server 2012  Backup - HyperV host 18 63
Fill Null values 5 28
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…
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…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

828 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