免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
打印 上一主题 下一主题

[C] 如何调试头文件? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-12-08 20:43 |只看该作者

回复 #1 你就依了我吧 的帖子

#ifdef
...
#endif

等都是为了跨平台的(核外代码),非常多,看别人代码的时候很头大。

一般看的时候可以想lS兄弟说的,通过#error hello 方式来判断是否在本系统内有定义。

如果没有定义的就砍掉,砍完之后,你再看代码,其实就那么点点,就很容易看了。


这种情况在看内核时也可采用同样的方法,如看linux内核,跟一个函数的时候,发现有一堆。直接把arm下自己不关注的体系结构sparc等直接删掉,文件系统目录树下那么多文件系统,不关注的直接删掉,这样就清楚多了。如果不看网络部分,直接删掉,不看驱动部分时直接删掉,呵呵

论坛徽章:
0
12 [报告]
发表于 2008-12-09 09:32 |只看该作者
#error 这种还从来没用过,  还不知道是咋用的。


在判断宏是否被定义的时候,相当好用的。

论坛徽章:
0
13 [报告]
发表于 2008-12-09 09:34 |只看该作者
#ifdef
...
#endif

等都是为了跨平台的(核外代码),非常多,看别人代码的时候很头大。

一般看的时候可以想lS兄弟说的,通过#error hello 方式来判断是否在本系统内有定义。

如果没有定义的就砍掉,砍完之后,你再看代码,其实就那么点点,就很容易看了。


这种情况在看内核时也可采用同样的方法,如看linux内核,跟一个函数的时候,发现有一堆。直接把arm下自己不关注的体系结构sparc等直接删掉,文件系统目录树下那么多文件系统,不关注的直接删掉,这样就清楚多了。如果不看网络部分,直接删掉,不看驱动部分时直接删掉,呵呵


也并非跨平台的时候才用,很多地方都可以用。 如是否支持IPV6,是否支持多线程,是否支持TLS,也可以用于调试代码等等,很多。
说到底也就是一个简单的判断。

论坛徽章:
0
14 [报告]
发表于 2008-12-09 11:35 |只看该作者
不清楚,看来是混的

论坛徽章:
0
15 [报告]
发表于 2008-12-09 11:51 |只看该作者
不清楚,看来是混的


确实是混的,这年头混口饭吃也不容易啊!


eXosip2的 src里面的文件, eXconf.c  里面有这些宏   OSIP_MT, IPV6_V6ONLY

http://www.koders.com/c/fid30E4A ... 4B3AF1ED.aspx?s=md5

这些地方都可以下载到

http://download.savannah.gnu.org/releases/exosip/


  1. /*
  2.   eXosip - This is the eXtended osip library.
  3.   Copyright (C) 2002,2003,2004,2005,2006,2007  Aymeric MOIZARD  - [email]jack@atosc.org[/email]
  4.   
  5.   eXosip is free software; you can redistribute it and/or modify
  6.   it under the terms of the GNU General Public License as published by
  7.   the Free Software Foundation; either version 2 of the License, or
  8.   (at your option) any later version.
  9.   
  10.   eXosip is distributed in the hope that it will be useful,
  11.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.   GNU General Public License for more details.
  14.   
  15.   You should have received a copy of the GNU General Public License
  16.   along with this program; if not, write to the Free Software
  17.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */

  19. #ifdef ENABLE_MPATROL
  20. #include <mpatrol.h>
  21. #endif

  22. #include "eXosip2.h"
  23. #include <eXosip2/eXosip.h>

  24. #include <osip2/osip_mt.h>
  25. #include <osip2/osip_condv.h>

  26. extern eXosip_t eXosip;

  27. int ipv6_enable = 0;

  28. #ifdef OSIP_MT
  29. static void *_eXosip_thread (void *arg);
  30. #endif
  31. static void _eXosip_keep_alive (void);

  32. #ifndef MINISIZE

  33. void
  34. eXosip_enable_ipv6 (int _ipv6_enable)
  35. {
  36.   ipv6_enable = _ipv6_enable;
  37. }

  38. #endif

  39. const char *
  40. eXosip_get_version(void)
  41. {
  42.   return EXOSIP_VERSION;
  43. }

  44. void
  45. eXosip_masquerade_contact (const char *public_address, int port)
  46. {
  47.   eXtl_udp.tl_masquerade_contact(public_address, port);
  48.   eXtl_tcp.tl_masquerade_contact(public_address, port);
  49. #ifdef HAVE_OPENSSL_SSL_H
  50.   eXtl_tls.tl_masquerade_contact(public_address, port);
  51.   eXtl_dtls.tl_masquerade_contact(public_address, port);
  52. #endif
  53.   return;
  54. }

  55. int
  56. eXosip_guess_localip (int family, char *address, int size)
  57. {
  58.   return eXosip_guess_ip_for_via (family, address, size);
  59. }

  60. int
  61. eXosip_is_public_address (const char *c_address)
  62. {
  63.   return (0 != strncmp (c_address, "192.168", 7)
  64.           && 0 != strncmp (c_address, "10.", 3)
  65.           && 0 != strncmp (c_address, "172.16.", 7)
  66.           && 0 != strncmp (c_address, "172.17.", 7)
  67.           && 0 != strncmp (c_address, "172.18.", 7)
  68.           && 0 != strncmp (c_address, "172.19.", 7)
  69.           && 0 != strncmp (c_address, "172.20.", 7)
  70.           && 0 != strncmp (c_address, "172.21.", 7)
  71.           && 0 != strncmp (c_address, "172.22.", 7)
  72.           && 0 != strncmp (c_address, "172.23.", 7)
  73.           && 0 != strncmp (c_address, "172.24.", 7)
  74.           && 0 != strncmp (c_address, "172.25.", 7)
  75.           && 0 != strncmp (c_address, "172.26.", 7)
  76.           && 0 != strncmp (c_address, "172.27.", 7)
  77.           && 0 != strncmp (c_address, "172.28.", 7)
  78.           && 0 != strncmp (c_address, "172.29.", 7)
  79.           && 0 != strncmp (c_address, "172.30.", 7)
  80.           && 0 != strncmp (c_address, "172.31.", 7)
  81.           && 0 != strncmp (c_address, "169.254", 7));
  82. }

  83. void
  84. eXosip_set_user_agent (const char *user_agent)
  85. {
  86.   osip_free (eXosip.user_agent);
  87.   eXosip.user_agent = osip_strdup (user_agent);
  88. }

  89. void
  90. eXosip_kill_transaction (osip_list_t * transactions)
  91. {
  92.   osip_transaction_t *transaction;

  93.   if (!osip_list_eol (transactions, 0))
  94.     {
  95.       /* some transaction are still used by osip,
  96.          transaction should be released by modules! */
  97.       OSIP_TRACE (osip_trace
  98.                   (__FILE__, __LINE__, OSIP_ERROR, NULL,
  99.                    "module sfp: _osip_kill_transaction transaction should be released by modules!\n"));
  100.     }

  101.   while (!osip_list_eol (transactions, 0))
  102.     {
  103.       transaction = osip_list_get (transactions, 0);

  104.       __eXosip_delete_jinfo (transaction);
  105.       osip_transaction_free (transaction);
  106.     }
  107. }

  108. void
  109. eXosip_quit (void)
  110. {
  111.   jauthinfo_t *jauthinfo;
  112.   eXosip_call_t *jc;
  113.   eXosip_reg_t *jreg;
  114. #ifndef MINISIZE
  115.   eXosip_notify_t *jn;
  116.   eXosip_subscribe_t *js;
  117.   eXosip_pub_t *jpub;
  118. #endif
  119. #ifdef OSIP_MT
  120.   int i;
  121. #endif

  122.   if (eXosip.j_stop_ua==-1)
  123.   {
  124.                 OSIP_TRACE (osip_trace
  125.                                         (__FILE__, __LINE__, OSIP_WARNING, NULL,
  126.                                         "eXosip: already stopped!\n"));
  127.           return;
  128.   }

  129.   eXosip.j_stop_ua = 1;         /* ask to quit the application */
  130.   __eXosip_wakeup ();
  131.   __eXosip_wakeup_event ();

  132. #ifdef OSIP_MT
  133.   if (eXosip.j_thread!=NULL)
  134.   {
  135.     i = osip_thread_join ((struct osip_thread *) eXosip.j_thread);
  136.     if (i != 0)
  137.         {
  138.         OSIP_TRACE (osip_trace
  139.                     (__FILE__, __LINE__, OSIP_ERROR, NULL,
  140.                     "eXosip: can't terminate thread!\n"));
  141.         }
  142.     osip_free ((struct osip_thread *) eXosip.j_thread);
  143.   }

  144.   jpipe_close (eXosip.j_socketctl);
  145.   jpipe_close (eXosip.j_socketctl_event);
  146. #endif

  147.   osip_free (eXosip.user_agent);

  148.   for (jc = eXosip.j_calls; jc != NULL; jc = eXosip.j_calls)
  149.     {
  150.       REMOVE_ELEMENT (eXosip.j_calls, jc);
  151.       eXosip_call_free (jc);
  152.     }

  153. #ifndef MINISIZE
  154.   for (js = eXosip.j_subscribes; js != NULL; js = eXosip.j_subscribes)
  155.     {
  156.       REMOVE_ELEMENT (eXosip.j_subscribes, js);
  157.       eXosip_subscribe_free (js);
  158.     }

  159.   for (jn = eXosip.j_notifies; jn != NULL; jn = eXosip.j_notifies)
  160.     {
  161.       REMOVE_ELEMENT (eXosip.j_notifies, jn);
  162.       eXosip_notify_free (jn);
  163.     }
  164. #endif

  165. #ifdef OSIP_MT
  166.   osip_mutex_destroy ((struct osip_mutex *) eXosip.j_mutexlock);
  167. #if !defined (_WIN32_WCE)
  168.   osip_cond_destroy ((struct osip_cond *) eXosip.j_cond);
  169. #endif
  170. #endif

  171.   for (jreg = eXosip.j_reg; jreg != NULL; jreg = eXosip.j_reg)
  172.     {
  173.       REMOVE_ELEMENT (eXosip.j_reg, jreg);
  174.       eXosip_reg_free (jreg);
  175.     }

  176. #ifndef MINISIZE
  177.   for (jpub = eXosip.j_pub; jpub != NULL; jpub = eXosip.j_pub)
  178.     {
  179.       REMOVE_ELEMENT (eXosip.j_pub, jpub);
  180.       _eXosip_pub_free (jpub);
  181.     }
  182. #endif

  183.   while (!osip_list_eol (eXosip.j_transactions, 0))
  184.     {
  185.       osip_transaction_t *tr =
  186.         (osip_transaction_t *) osip_list_get (eXosip.j_transactions, 0);
  187.       if (tr->state == IST_TERMINATED || tr->state == ICT_TERMINATED
  188.           || tr->state == NICT_TERMINATED || tr->state == NIST_TERMINATED)
  189.         {
  190.           OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL,
  191.                                   "Release a terminated transaction\n"));
  192.           osip_list_remove (eXosip.j_transactions, 0);
  193.           __eXosip_delete_jinfo (tr);
  194.           osip_transaction_free (tr);
  195.       } else
  196.         {
  197.           osip_list_remove (eXosip.j_transactions, 0);
  198.           __eXosip_delete_jinfo (tr);
  199.           osip_transaction_free (tr);
  200.         }
  201.     }

  202.   osip_free (eXosip.j_transactions);

  203.   eXosip_kill_transaction (&eXosip.j_osip->osip_ict_transactions);
  204.   eXosip_kill_transaction (&eXosip.j_osip->osip_nict_transactions);
  205.   eXosip_kill_transaction (&eXosip.j_osip->osip_ist_transactions);
  206.   eXosip_kill_transaction (&eXosip.j_osip->osip_nist_transactions);
  207.   osip_release (eXosip.j_osip);

  208.   {
  209.     eXosip_event_t *ev;

  210.     for (ev = osip_fifo_tryget (eXosip.j_events); ev != NULL;
  211.          ev = osip_fifo_tryget (eXosip.j_events))
  212.       eXosip_event_free (ev);
  213.   }

  214.   osip_fifo_free (eXosip.j_events);

  215.   for (jauthinfo = eXosip.authinfos; jauthinfo != NULL;
  216.        jauthinfo = eXosip.authinfos)
  217.     {
  218.       REMOVE_ELEMENT (eXosip.authinfos, jauthinfo);
  219.       osip_free (jauthinfo);
  220.     }

  221.   eXtl_udp.tl_free();
  222.   eXtl_tcp.tl_free();
  223. #ifdef HAVE_OPENSSL_SSL_H
  224.   eXtl_dtls.tl_free();
  225.   eXtl_tls.tl_free();
  226. #endif

  227.   memset (&eXosip, 0, sizeof (eXosip));
  228.   eXosip.j_stop_ua = -1;
  229.   return;
  230. }

  231. int
  232. eXosip_set_socket (int transport, int socket, int port)
  233. {
  234.   eXosip.eXtl = NULL;
  235.   if (transport==IPPROTO_UDP)
  236.     {
  237.       eXtl_udp.proto_port = port;
  238.       eXtl_udp.tl_set_socket(socket);
  239.       eXosip.eXtl = &eXtl_udp;
  240.       snprintf(eXosip.transport, sizeof(eXosip.transport), "%s", "UDP");
  241.     }
  242.   else if (transport==IPPROTO_UDP)
  243.     {
  244.       eXtl_tcp.proto_port = port;
  245.       eXtl_tcp.tl_set_socket(socket);
  246.       eXosip.eXtl = &eXtl_tcp;
  247.       snprintf(eXosip.transport, sizeof(eXosip.transport), "%s", "TCP");
  248.    }
  249.   else
  250.     return -1;

  251. #ifdef OSIP_MT
  252.   eXosip.j_thread = (void *) osip_thread_create (20000, _eXosip_thread, NULL);
  253.   if (eXosip.j_thread == NULL)
  254.     {
  255.       OSIP_TRACE (osip_trace
  256.                   (__FILE__, __LINE__, OSIP_ERROR, NULL,
  257.                    "eXosip: Cannot start thread!\n"));
  258.       return -1;
  259.     }
  260. #endif
  261.   return 0;
  262. }

  263. #ifdef IPV6_V6ONLY
  264. int
  265. setsockopt_ipv6only (int sock)
  266. {
  267.   int on = 1;

  268.   return setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on, sizeof (on));
  269. }
  270. #endif /* IPV6_V6ONLY */
复制代码

论坛徽章:
0
16 [报告]
发表于 2008-12-09 12:08 |只看该作者
来,我们再来看一个 判断是否支持ssl的宏。
还是看那个eXosip2的项目吧,不换了。
里面有个eXtl_tls.c的文件,就有关于open_ssl支持的宏, HAVE_OPENSSL_SSL_H

多的就不看了,看前面200行吧

  1. [jimmy@local src]$ sed -n '1,200p' eXtl_tls.c
  2. /*
  3.   eXosip - This is the eXtended osip library.
  4.   Copyright (C) 2002,2003,2004,2005,2006,2007  Aymeric MOIZARD  - [email]jack@atosc.org[/email]

  5.   eXosip is free software; you can redistribute it and/or modify
  6.   it under the terms of the GNU General Public License as published by
  7.   the Free Software Foundation; either version 2 of the License, or
  8.   (at your option) any later version.

  9.   eXosip is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.   GNU General Public License for more details.

  13.   You should have received a copy of the GNU General Public License
  14.   along with this program; if not, write to the Free Software
  15.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  16. */


  17. #ifdef ENABLE_MPATROL
  18. #include <mpatrol.h>
  19. #endif

  20. #include "eXosip2.h"
  21. #include "eXtransport.h"

  22. #ifdef HAVE_OPENSSL_SSL_H

  23. #include <openssl/ssl.h>
  24. #define SPROTO_TLS 500
  25. #define SPROTO_DTLS 501
  26. #include <openssl/ssl.h>
  27. #include <openssl/err.h>
  28. #include <openssl/pem.h>
  29. #include <openssl/x509.h>
  30. #include <openssl/rand.h>

  31. #define SSLDEBUG 1

  32. #define PASSWORD "password"
  33. #define CLIENT_KEYFILE "ckey.pem"
  34. #define CLIENT_CERTFILE "c.pem"
  35. #define SERVER_KEYFILE "skey.pem"
  36. #define SERVER_CERTFILE "s.pem"
  37. #define CA_LIST "cacert.pem"
  38. #define RANDOM  "random.pem"
  39. #define DHFILE "dh1024.pem"

  40. #if defined(_WIN32_WCE)
  41. #define strerror(X) "-1"
  42. #endif

  43. SSL_CTX *
  44. initialize_client_ctx (const char *keyfile, const char *certfile,
  45.                        const char *password, int transport);

  46. SSL_CTX *
  47. initialize_server_ctx (const char *keyfile, const char *certfile,
  48.                        const char *password, int transport);

  49. static int tls_socket;
  50. static struct sockaddr_storage ai_addr;

  51. static char tls_firewall_ip[64];
  52. static char tls_firewall_port[10];

  53. static SSL_CTX *ssl_ctx;
  54. static SSL_CTX *client_ctx;

  55. /* persistent connection */
  56. struct socket_tab
  57. {
  58.   int socket;
  59.   char remote_ip[65];
  60.   int remote_port;
  61.   SSL *ssl_conn;
  62.   SSL_CTX *ssl_ctx;
  63.   int ssl_state;

  64. };

  65. #ifndef EXOSIP_MAX_SOCKETS
  66. #define EXOSIP_MAX_SOCKETS
  67. #endif

  68. static struct socket_tab tls_socket_tab[EXOSIP_MAX_SOCKETS];

  69. static int
  70. tls_tl_init(void)
  71. {
  72.   tls_socket=0;
  73.   ssl_ctx=NULL;
  74.   client_ctx=NULL;
  75.   memset(&ai_addr, 0, sizeof(struct sockaddr_storage));
  76.   memset(&tls_socket_tab, 0, sizeof(struct socket_tab)*EXOSIP_MAX_SOCKETS);
  77.   memset(tls_firewall_ip, 0, sizeof(tls_firewall_ip));
  78.   memset(tls_firewall_port, 0, sizeof(tls_firewall_port));
  79.   return 0;
  80. }

  81. static int
  82. tls_tl_free(void)
  83. {
  84.   int pos;
  85.   if (ssl_ctx != NULL)
  86.     SSL_CTX_free (ssl_ctx);

  87.   if (client_ctx != NULL)
  88.     SSL_CTX_free (client_ctx);

  89.   for (pos = 0; pos < EXOSIP_MAX_SOCKETS; pos++)
  90.     {
  91.       if (tls_socket_tab[pos].socket > 0)
  92.         {
  93.           if (tls_socket_tab[pos].ssl_conn != NULL)
  94.             {
  95.               SSL_shutdown (tls_socket_tab[pos].ssl_conn);
  96.               SSL_shutdown (tls_socket_tab[pos].ssl_conn);
  97.               SSL_free (tls_socket_tab[pos].ssl_conn);
  98.               SSL_CTX_free (tls_socket_tab[pos].ssl_ctx);
  99.             }
  100.           close(tls_socket_tab[pos].socket);
  101.         }
  102.     }
  103.   memset(&tls_socket_tab, 0, sizeof(struct socket_tab)*EXOSIP_MAX_SOCKETS);

  104.   memset(tls_firewall_ip, 0, sizeof(tls_firewall_ip));
  105.   memset(tls_firewall_port, 0, sizeof(tls_firewall_port));
  106.   memset(&ai_addr, 0, sizeof(struct sockaddr_storage));
  107.   if (tls_socket>0)
  108.     close(tls_socket);

  109.   return 0;
  110. }

  111. static int
  112. password_cb (char *buf, int num, int rwflag, void *userdata)
  113. {
  114.   if (userdata == NULL)
  115.     {
  116.       return 0;
  117.     }
  118.   strncpy (buf, (char *) userdata, num);
  119.   buf[num - 1] = '\0';
  120.   return strlen (buf);
  121. }

  122. static void
  123. load_dh_params (SSL_CTX * ctx, char *file)
  124. {
  125.   DH *ret = 0;
  126.   BIO *bio;

  127.   if ((bio = BIO_new_file (file, "r")) == NULL)
  128.     {
  129.       OSIP_TRACE (osip_trace
  130.                   (__FILE__, __LINE__, OSIP_ERROR, NULL,
  131.                    "eXosip: Couldn't open DH file!\n"));
  132.     }
  133.   else
  134.     {
  135.       ret = PEM_read_bio_DHparams (bio, NULL, NULL, NULL);
  136.       BIO_free (bio);
  137.       if (SSL_CTX_set_tmp_dh (ctx, ret) < 0)
  138.         OSIP_TRACE (osip_trace
  139.                     (__FILE__, __LINE__, OSIP_ERROR, NULL,
  140.                      "eXosip: Couldn't set DH param!\n"));
  141.     }
  142. }

  143. static void
  144. generate_eph_rsa_key (SSL_CTX * ctx)
  145. {
  146.   RSA *rsa;

  147.   rsa = RSA_generate_key (512, RSA_F4, NULL, NULL);

  148.   if (rsa != NULL)
  149.     {
  150.       if (!SSL_CTX_set_tmp_rsa (ctx, rsa))
  151.         OSIP_TRACE (osip_trace
  152.                     (__FILE__, __LINE__, OSIP_ERROR, NULL,
  153.                      "eXosip: Couldn't set RSA key!\n"));

  154.       RSA_free (rsa);
  155.     }
  156. }

  157. SSL_CTX *
  158. initialize_client_ctx (const char *keyfile, const char *certfile,
  159.                        const char *password, int transport)
  160. {
  161.   SSL_METHOD *meth;
  162.   SSL_CTX *ctx;
  163.   char *passwd;

  164.   if (transport == IPPROTO_UDP)
  165.     {
  166.       meth = DTLSv1_client_method ();
复制代码


我想应该可以说明问题了。

论坛徽章:
0
17 [报告]
发表于 2008-12-09 16:47 |只看该作者
原帖由 futuregod 于 2008-12-8 17:43 发表
我猜测楼主的意思是想知道哪个宏定义了,哪个宏没有定义。
头文件里面没有代码可以执行,说不上调试。

但愿我说对了。
楼主说个话呀。呵呵

是这样的.......
这个很头痛,记性一定要好

论坛徽章:
0
18 [报告]
发表于 2008-12-09 16:57 |只看该作者
楼主最终出现啊。 : )

论坛徽章:
0
19 [报告]
发表于 2008-12-09 20:50 |只看该作者
我在公司用eclipse的时候,里面有一个选项叫: run compiler preprocessor
能够干这件事
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP