Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

shared.c File Reference

#include <sys/utsname.h>
#include <libxml/xmlversion.h>
#include "gwlib/gwlib.h"
#include "shared.h"
#include <openssl/opensslv.h>
#include <mysql_version.h>
#include <mysql.h>
#include <sqlite3.h>

Include dependency graph for shared.c:

Include dependency graph

Go to the source code of this file.

Functions

void report_versions (const char *boxname)
Octstrversion_report_string (const char *boxname)
Connectionconnect_to_bearerbox_real (Octstr *host, int port, int ssl, Octstr *our_host)
void connect_to_bearerbox (Octstr *host, int port, int ssl, Octstr *our_host)
void close_connection_to_bearerbox_real (Connection *conn)
void close_connection_to_bearerbox (void)
void write_to_bearerbox_real (Connection *conn, Msg *pmsg)
void write_to_bearerbox (Msg *pmsg)
int deliver_to_bearerbox_real (Connection *conn, Msg *msg)
int deliver_to_bearerbox (Msg *msg)
int read_from_bearerbox_real (Connection *conn, Msg **msg, double seconds)
int read_from_bearerbox (Msg **msg, double seconds)
Octstrparse_date (Octstr *date)

Variables

Connectionbb_conn


Function Documentation

void close_connection_to_bearerbox void   ) 
 

Definition at line 213 of file shared.c.

References bb_conn, and close_connection_to_bearerbox_real().

Referenced by main(), and run_connects().

00214 {
00215     close_connection_to_bearerbox_real(bb_conn);
00216     bb_conn = NULL;
00217 }

Here is the call graph for this function:

void close_connection_to_bearerbox_real Connection conn  ) 
 

Definition at line 207 of file shared.c.

References conn_destroy().

Referenced by close_connection_to_bearerbox().

00208 {
00209     conn_destroy(conn);
00210 }

Here is the call graph for this function:

void connect_to_bearerbox Octstr host,
int  port,
int  ssl,
Octstr our_host
 

Definition at line 199 of file shared.c.

References bb_conn, connect_to_bearerbox_real(), panic, port, and ssl.

Referenced by main(), and run_connects().

00200 {
00201     bb_conn = connect_to_bearerbox_real(host, port, ssl, our_host);
00202     if (bb_conn == NULL)
00203         panic(0, "Couldn't connect to the bearerbox.");
00204 }

Here is the call graph for this function:

Connection* connect_to_bearerbox_real Octstr host,
int  port,
int  ssl,
Octstr our_host
 

Definition at line 174 of file shared.c.

References conn_open_ssl(), conn_open_tcp(), info(), octstr_get_cstr, and port.

Referenced by connect_to_bearerbox().

00175 {
00176     Connection *conn;
00177 
00178 #ifdef HAVE_LIBSSL
00179     if (ssl) 
00180         conn = conn_open_ssl(host, port, NULL, our_host);
00181         /* XXX add certkeyfile to be given to conn_open_ssl */
00182     else
00183 #endif /* HAVE_LIBSSL */
00184     conn = conn_open_tcp(host, port, our_host);
00185     if (conn == NULL)
00186         return NULL;
00187 
00188     if (ssl)
00189         info(0, "Connected to bearerbox at %s port %d using SSL.",
00190              octstr_get_cstr(host), port);
00191     else
00192         info(0, "Connected to bearerbox at %s port %d.",
00193              octstr_get_cstr(host), port);
00194 
00195     return conn;
00196 }

Here is the call graph for this function:

int deliver_to_bearerbox Msg msg  ) 
 

Definition at line 257 of file shared.c.

References bb_conn, and deliver_to_bearerbox_real().

Referenced by send_message().

00258 {
00259     return deliver_to_bearerbox_real(bb_conn, msg);
00260 }

Here is the call graph for this function:

int deliver_to_bearerbox_real Connection conn,
Msg msg
 

Definition at line 239 of file shared.c.

References conn_write_withlen(), error(), msg_destroy(), msg_pack(), and octstr_destroy().

Referenced by deliver_to_bearerbox().

00240 {
00241      
00242     Octstr *pack;
00243     
00244     pack = msg_pack(msg);
00245     if (conn_write_withlen(conn, pack) == -1) {
00246         error(0, "Couldn't deliver Msg to bearerbox.");
00247         octstr_destroy(pack);
00248         return -1;
00249     }
00250                                    
00251     octstr_destroy(pack);
00252     msg_destroy(msg);
00253     return 0;
00254 }

Here is the call graph for this function:

Octstr* parse_date Octstr date  ) 
 

Definition at line 323 of file shared.c.

References error(), octstr_get_char(), octstr_parse_long(), and warning().

00324 {
00325     long date_value;
00326 
00327     if (octstr_get_char(date, 4) != '-')
00328         goto error;
00329     if (octstr_get_char(date, 7) != '-')
00330         goto error;
00331     if (octstr_get_char(date, 10) != 'T')
00332         goto error;
00333     if (octstr_get_char(date, 13) != ':')
00334         goto error;
00335     if (octstr_get_char(date, 16) != ':')
00336         goto error;
00337     if (octstr_get_char(date, 19) != 'Z')
00338         goto error;
00339 
00340     if (octstr_parse_long(&date_value, date, 0, 10) < 0)
00341         goto error;
00342     if (octstr_parse_long(&date_value, date, 5, 10) < 0)
00343         goto error;
00344     if (date_value < 1 || date_value > 12)
00345         goto error;
00346     if (octstr_parse_long(&date_value, date, 8, 10) < 0)
00347         goto error;
00348     if (date_value < 1 || date_value > 31)
00349         goto error;
00350     if (octstr_parse_long(&date_value, date, 11, 10) < 0)
00351         goto error;
00352     if (date_value < 0 || date_value > 23)
00353         goto error;
00354     if (octstr_parse_long(&date_value, date, 14, 10) < 0)
00355         goto error;
00356     if (date_value < 0 || date_value > 59)
00357         goto error;
00358     if (date_value < 0 || date_value > 59)
00359         goto error;
00360     if (octstr_parse_long(&date_value, date, 17, 10) < 0)
00361         goto error;
00362 
00363     return date;
00364 
00365 error:
00366     warning(0, "parse_date: not an ISO date");
00367     return NULL;
00368 }

Here is the call graph for this function:

int read_from_bearerbox Msg **  msg,
double  seconds
 

Definition at line 311 of file shared.c.

References bb_conn, and read_from_bearerbox_real().

Referenced by main(), and read_messages_from_bearerbox().

00312 {
00313     return read_from_bearerbox_real(bb_conn, msg, seconds);
00314 }

Here is the call graph for this function:

int read_from_bearerbox_real Connection conn,
Msg **  msg,
double  seconds
 

Definition at line 263 of file shared.c.

References conn_eof(), conn_error(), conn_read_withlen(), conn_wait(), error(), msg_unpack, octstr_destroy(), and program_status.

Referenced by read_from_bearerbox().

00264 {
00265     int ret;
00266     Octstr *pack;
00267 
00268     pack = NULL;
00269     *msg = NULL;
00270     while (program_status != shutting_down) {
00271         pack = conn_read_withlen(conn);
00272         gw_claim_area(pack);
00273         if (pack != NULL)
00274             break;
00275 
00276         if (conn_error(conn)) {
00277             error(0, "Error reading from bearerbox, disconnecting.");
00278             return -1;
00279         }
00280         if (conn_eof(conn)) {
00281             error(0, "Connection closed by the bearerbox.");
00282             return -1;
00283         }
00284 
00285         ret = conn_wait(conn, seconds);
00286         if (ret < 0) {
00287             error(0, "Connection to bearerbox broke.");
00288             return -1;
00289         }
00290         else if (ret == 1) {
00291             /* debug("gwlib.gwlib", 0, "Connection to bearerbox timed out after %.2f seconds.", seconds); */
00292             return 1;
00293         }
00294     }
00295 
00296     if (pack == NULL)
00297         return -1;
00298 
00299     *msg = msg_unpack(pack);
00300     octstr_destroy(pack);
00301 
00302     if (*msg == NULL) {
00303         error(0, "Failed to unpack data!");
00304         return -1;
00305     }
00306 
00307     return 0;
00308 }

Here is the call graph for this function:

void report_versions const char *  boxname  ) 
 

Definition at line 90 of file shared.c.

References debug(), octstr_destroy(), octstr_get_cstr, and version_report_string().

Referenced by main().

00091 {
00092     Octstr *os;
00093     
00094     os = version_report_string(boxname);
00095     debug("gwlib.gwlib", 0, "%s", octstr_get_cstr(os));
00096     octstr_destroy(os);
00097 }

Here is the call graph for this function:

Octstr* version_report_string const char *  boxname  ) 
 

Definition at line 100 of file shared.c.

References get_official_ip(), get_official_name(), GW_NAME, GW_VERSION, HAVE_LIBSSL, HAVE_MYSQL, HAVE_SQLITE3, octstr_format(), and octstr_get_cstr.

Referenced by bb_print_status(), and report_versions().

00101 {
00102     struct utsname u;
00103 
00104     uname(&u);
00105     return octstr_format(GW_NAME " %s version `%s'.\nBuild `%s', compiler `%s'.\n"
00106                          "System %s, release %s, version %s, machine %s.\n"
00107              "Hostname %s, IP %s.\n"
00108              "Libxml version %s.\n"
00109 #ifdef HAVE_LIBSSL
00110              "Using "
00111 #ifdef HAVE_WTLS_OPENSSL
00112              "WTLS library "
00113 #endif
00114              "%s.\n"
00115 #endif
00116 #ifdef HAVE_MYSQL
00117              "Compiled with MySQL %s, using MySQL %s.\n"
00118 #endif
00119 #ifdef HAVE_SDB
00120              "Using LibSDB %s.\n"
00121 #endif
00122 #if defined(HAVE_SQLITE) || defined(HAVE_SQLITE3)
00123              "Using SQLite %s.\n"
00124 #endif
00125 #ifdef HAVE_ORACLE
00126 #if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION)
00127              "Using Oracle OCI %d.%d.\n"
00128 #else
00129              "Using Oracle OCI.\n"
00130 #endif
00131 #endif
00132              "Using %s malloc.\n",
00133              boxname, GW_VERSION,
00134 #ifdef __GNUC__ 
00135              (__DATE__ " " __TIME__) ,
00136              __VERSION__,
00137 #else 
00138              "unknown" , "unknown",
00139 #endif 
00140              u.sysname, u.release, u.version, u.machine,
00141              octstr_get_cstr(get_official_name()),
00142              octstr_get_cstr(get_official_ip()),
00143              LIBXML_DOTTED_VERSION,
00144 #ifdef HAVE_LIBSSL
00145              OPENSSL_VERSION_TEXT,
00146 #endif
00147 #ifdef HAVE_MYSQL
00148              MYSQL_SERVER_VERSION, mysql_get_client_info(),
00149 #endif
00150 #ifdef HAVE_SDB
00151              LIBSDB_VERSION,
00152 #endif
00153 #if defined(HAVE_SQLITE) || defined(HAVE_SQLITE3)
00154              SQLITE_VERSION,
00155 #endif
00156 #ifdef HAVE_ORACLE
00157 #if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION)
00158              OCI_MAJOR_VERSION, OCI_MINOR_VERSION,
00159 #endif
00160 #endif
00161              octstr_get_cstr(gwmem_type()));
00162 }

Here is the call graph for this function:

void write_to_bearerbox Msg pmsg  ) 
 

Definition at line 233 of file shared.c.

References bb_conn, and write_to_bearerbox_real().

Referenced by dispatch_datagram(), identify_to_bearerbox(), main(), obey_request_thread(), run_connects(), and send_message().

00234 {
00235     write_to_bearerbox_real(bb_conn, pmsg);
00236 }

Here is the call graph for this function:

void write_to_bearerbox_real Connection conn,
Msg pmsg
 

Definition at line 220 of file shared.c.

References conn_write_withlen(), error(), msg_destroy(), msg_pack(), and octstr_destroy().

Referenced by write_to_bearerbox().

00221 {
00222     Octstr *pack;
00223 
00224     pack = msg_pack(pmsg);
00225     if (conn_write_withlen(conn, pack) == -1)
00226         error(0, "Couldn't write Msg to bearerbox.");
00227 
00228     msg_destroy(pmsg);
00229     octstr_destroy(pack);
00230 }

Here is the call graph for this function:


Variable Documentation

Connection* bb_conn [static]
 

Definition at line 171 of file shared.c.

Referenced by close_connection_to_bearerbox(), connect_to_bearerbox(), deliver_to_bearerbox(), read_from_bearerbox(), and write_to_bearerbox().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.