📄 cl_msg.c
字号:
return(wirefmt2msg_ll(s, length, 1));}voidcl_log_message (int log_level, const struct ha_msg *m){ int j; if(m == NULL) { cl_log(log_level, "MSG: No message to dump"); return; } AUDITMSG(m); cl_log(log_level, "MSG: Dumping message with %d fields", m->nfields); for (j=0; j < m->nfields; ++j) { if(m->types[j] < DIMOF(fieldtypefuncs)){ fieldtypefuncs[m->types[j]].display(log_level, j, m->names[j], m->values[j]); } }}#ifdef TESTMAIN_MSGSintmain(int argc, char ** argv){ struct ha_msg* m; while (!feof(stdin)) { if ((m=controlfifo2msg(stdin)) != NULL) { fprintf(stderr, "Got message!\n"); if (msg2stream(m, stdout) == HA_OK) { fprintf(stderr, "Message output OK!\n"); }else{ fprintf(stderr, "Could not output Message!\n"); } }else{ fprintf(stderr, "Could not get message!\n"); } } return(0);}#endif/* * $Log: cl_msg.c,v $ * Revision 1.55 2005/02/17 21:45:35 gshi * use DIMOF to calculate dimention of an array * * Revision 1.54 2005/02/17 18:14:22 gshi * BEAM fix: * add surrounding {} for some if statements * * Revision 1.53 2005/02/17 15:49:50 alan * Fixed a few BEAM complaints (but not all of them yet) * * Revision 1.52 2005/02/16 20:38:29 alan * tried to move around a BEAM comment so it makes it shut up at the right time. * * Revision 1.51 2005/02/16 19:14:35 gshi * Don't check a message's stringlen/netstringlen until it is time to encode the message to string or netstring * * Revision 1.50 2005/02/16 06:54:51 zhenh * add cl_malloc_forced_for_glib() to lrmd. * * Revision 1.49 2005/02/14 21:16:20 gshi * fix a warning in IA64 machine * * Revision 1.48 2005/02/14 21:06:11 gshi * BEAM fix: * * replacing the binary usage in core code with uuid function * * Revision 1.47 2005/02/09 18:57:12 gshi * In case of one field printing to string failure, we should discard the entire message * * Revision 1.46 2005/02/09 01:45:05 gshi * 1.add a magic number in strut SOCKET_MSG_HEAD. On IPC receive side, it checks that magic * number and abort if not correct * * 2. fixed a bug in IPC: there must be one pool per channel, not one pool per program * * Revision 1.45 2005/02/08 08:10:27 gshi * change the way stringlen and netstringlen is computed. * * Now it is computed resursively in child messages in get_stringlen() and get_netstringlen() * so it allows changing child messages dynamically. * * Revision 1.44 2005/02/07 21:32:38 gshi * move the free from the calling function in wirefmt2ipcmsg() to the caller * * Revision 1.43 2005/02/07 18:04:37 gshi * Serious bug fix. * * p should not be assigned to msg_body since msg_body is already assigned * and p is freed. * * Revision 1.42 2005/02/07 13:56:15 andrew * Back out some test code * * Revision 1.41 2005/02/07 11:46:42 andrew * Implement some needed variations of cl_msg_remove() * * Revision 1.40 2005/02/06 05:54:42 alan * Miscellaneous BEAM fixes. * Memory leaks, use of NULL pointers, etc. * Two errors are just pointed out and not fixed. One is serious. * * Revision 1.39 2005/01/28 09:09:51 gshi * add function to remove a field * * Revision 1.38 2005/01/26 13:57:07 andrew * Make value a const argument for consistency * * Revision 1.37 2005/01/18 20:33:04 andrew * Appologies for the top-level commit, one change necessitated another which * exposed some bugs... etc etc * * Remove redundant usage of XML in the CRM * - switch to "struct ha_msg" aka. HA_Message for everything except data * Make sure the expected type of all FSA input data is verified before processing * Fix a number of bugs including * - looking in the wrong place for the API result data in the CIB API * (hideous that this actually worked). * - not overwriting error codes when sending the result to the client in the CIB API * (this lead to some error cases being treated as successes later in the code) * Add PID to log messages sent to files (not to syslog) * Add a log level to calls for cl_log_message() * - convert existing calls, sorry if I got the level wrong * Add some checks in cl_msg.c code to prevent NULL pointer exceptions * - usually when NULL is passed to strlen() or similar * * Revision 1.36 2004/12/05 19:20:56 andrew * ha_msg_value_int() calls cl_get_value() which takes a const msg and ha_msg_value_int() * doesnt modify anything so I think this is correct. Its also helpful since * llc_msg_callback_t must take a const msg. * * Revision 1.35 2004/12/05 04:32:50 gshi * Moved some message-related functions from lrm_msg.c to cl_msg.c * These functions are general and shall be available to other subsystems * * Revision 1.34 2004/11/22 20:06:42 gshi * new IPC message should be memset-ed to 0 * to avoid errors caused by adding a new field (void*) msg_buf * * Revision 1.33 2004/11/18 00:34:37 gshi * 1. use one system call send() instead of two for each message in IPC. * 2. fixed a bug: heartbeat could crash if IPC pipe beween heartbeat and a client * is full. * * Revision 1.32 2004/11/17 22:03:43 lars * Fix another type error. * * Revision 1.31 2004/11/04 23:53:30 gshi * when adding a binary field, even it's length is zero, * I still allocate 1-byte length memory for it and store '\0' in it * there no field will have a NULL value * * Revision 1.30 2004/11/04 22:56:11 gshi * fixed a bug in 0-length binary field * * Revision 1.29 2004/11/04 21:19:29 gshi * added zero length binary field support * * Revision 1.28 2004/10/18 21:13:25 alan * Added functions to get/put/modify uuid fileds in our msgs... * * Revision 1.27 2004/10/03 07:25:44 gshi * BEAM fix: * fixed some memory leak problems * * Revision 1.26 2004/09/30 06:02:23 gshi * modulize the message for types * all type-related functions are moved the new file cl_msg_types.c * * This make code cleaner to read * and make adding a new type to ha_msg field easier: simly implement the given struct * * Revision 1.25 2004/09/27 08:47:13 zhenh * getting a non-existing field should not get a warning * * Revision 1.24 2004/09/23 03:46:43 gshi * fixed a sprintf format warning * fixed some comments * * Revision 1.23 2004/09/22 22:41:10 gshi * add list support for ha_msg * it supports list of strings only * * Revision 1.22 2004/09/22 17:03:23 gshi * brought STABLE change back to HEAD branch * * Revision 1.21 2004/09/09 20:34:49 gshi * fixed a bug * the third argument of strncmp should not be netstring_startlen * instread of (netstring_startlen == 0) * * Revision 1.20 2004/08/31 18:42:51 alan * Put in the code to suppress warnings about bad packets... * * Revision 1.19 2004/08/29 04:05:23 msoffen * Fixed end comment in previous log. * * Revision 1.18 2004/08/29 04:04:10 msoffen * Fixed end comment in previous log. * * Revision 1.17 2004/08/29 03:01:13 msoffen * Replaced all // COMMENTs with / * COMMENT * / * * Revision 1.16 2004/08/03 06:01:19 zhenh * fix a memory leak * * Revision 1.15 2004/07/15 09:17:38 zhenh * increase the size of ha_msg autmatically * * Revision 1.14 2004/07/07 19:07:15 gshi * implemented uuid as nodeid * * Revision 1.13 2004/06/24 20:54:35 gshi * add version 1.11 log that I overwritten in the last commit * * Revision 1.12 2004/06/24 20:49:49 gshi * remove commented code * Revision 1.11 2004/06/24 20:44:29 gshi * added cl_msg_modstring() cl_msg_modstruct() cl_msg_modbin() * they call call cl_msg_mod() * * * fixed a bug in cl_msg_addstruct() that will cause memory getting freed twice * if a parent and its child message is deleted. * Revision 1.10 2004/06/18 03:04:33 alan * Changed a few checks for non-existent fields to return NULL * silently. This is the right behavior (really!). * * Revision 1.9 2004/04/29 01:22:30 alan * Undid a broken fix to the %zd format string problem. * It was replaced with %xd which prints in hex instead of decimal, and also * inserts a d in the output string. * * Revision 1.8 2004/04/28 17:27:13 gshi * Fix potential (though probably unlikely) memory leak * similar to the one found in cl_netstring.c by kevin * * Revision 1.7 2004/04/21 14:33:56 msoffen * %z is not a standard formatting character. Changed to a %x * * Revision 1.6 2004/04/17 13:45:13 alan * More FreeBSD/64-bit problems fixed. Problems found by ward.viaene@student.khleuven.be. * * Revision 1.5 2004/04/17 07:54:50 alan * Fixed a number of 64-bit portability issues discovered by Ward Viaene in FreeBSD. * * Revision 1.4 2004/04/02 12:06:39 andrew * Link the size of the receive buffer/limit to that of the send buffer/limit * * Revision 1.3 2004/03/31 23:34:44 alan * Fixed a bug I introduced into the netstrings stuff - when I moved things * from the heartbeat directory to the lib directory * * Revision 1.2 2004/03/25 08:05:23 alan * Moved libraries from heartbeat to lib directory * also fixed numerous signed/unsigned problems... * * Revision 1.1 2004/03/24 17:04:08 alan * Moved ha_msg.c and netstring.c to the lib/clplumbing directory. * * Revision 1.52 2004/03/10 22:52:46 andrew * Allow people to distinguish between this error and one further up. * * Revision 1.51 2004/03/05 17:25:18 alan * cleanup of netstring patch. * Hopefully it also cleaned up the size_t vs int problems in the code. * * Revision 1.50 2004/03/03 05:31:50 alan * Put in Gochun Shi's new netstrings on-the-wire data format code. * this allows sending binary data, among many other things! * * Revision 1.49 2004/02/17 22:11:57 lars * Pet peeve removal: _Id et al now gone, replaced with consistent Id header. * * Revision 1.48 2004/01/21 11:34:14 horms * - Replaced numerous malloc + strcpy/strncpy invocations with strdup * * This usually makes the code a bit cleaner * * Also is easier not to make code with potential buffer over-runs * - Added STRDUP to pils modules * - Removed some spurious MALLOC and FREE redefinitions * _that could never be used_ * - Make sure the return value of strdup is honoured in error conditions * * Revision 1.47 2003/11/10 08:55:20 lars * Bugfixes by Deng, Pan: * * - While receiving a ha_msg, the default number of fields is MINFIELDS, * which is 20. After the reception, if more than 20 fields needed to be * added, it will fail. I changed the MINFIELDS to 30. It is not a * graceful fix, but it can work for checkpoint service. I think the max * fields should not be fixed. * * - The message create routine ha_msg_new() in ha_msg.c. It takes a * parameter nfields, but the function does not use it at all. If nfields * > MINFIELDS, the allocated fields should be nfields. * * Revision 1.46 2003/10/29 04:05:00 alan * Changed things so that the API uses IPC instead of FIFOs. * This isn't 100% done - python API code needs updating, and need to check authorization * for the ability to "sniff" other people's packets. * * Revision 1.45 2003/07/14 04:30:49 alan * This patch from Kurosawa-san (by way of Horms): * Heartbeat uses poll() in order to check messages in API FIFO and * stdio functions to read messages. stdio functions (fgets() in * msgfromstream() in this case) uses a internal buffer. When an application * sends 2 messages at a time to API FIFO, heartbeat's fgets() in * msgfromstream() may read 2 messages to the internal buffer at a time. * But heartbeat processes only one message and leaves the latter * message, because there is no poll() event for the file descriptor. * * Revision 1.44 2003/06/24 06:36:51 alan * Fixed an unsafe sprintf which occurred only when high levels of debug * were turned on. * * Revision 1.43 2003/05/09 15:15:37 alan * Turned off the most expensive and onerous debugging code. * * Revision 1.42 2003/04/18 06:33:54 alan * Changed the audit code for messages to tolerate NULL message pointers. * * Revision 1.41 2003/04/18 06:09:46 alan * Fixed an off-by-one error in writing messages to the FIFO. * Also got rid of some now-unused functions, and fixed a minor glitch in BasicSanitCheck. * * Revision 1.40 2003/04/15 23:05:01 alan * Added new message copying function, and code * to check the integrity of messages. Too slow now, will turn it down later. * * Revision 1.39 2003/03/27 07:04:26 alan * 1st step in heartbeat process restructuring. * Create fifo_child() processes to read the FIFO written by the shell scripts. * * Revision 1.38 2003/02/07 08:37:16 horms * Removed inclusion of portability.h from .h files * so that it does not need to be installed. * * Revision 1.37 2003/02/05 09:06:33 horms * Lars put a lot of work into making sure that portability.h * is included first, everywhere. However this broke a few * things when building against heartbeat headers that * have been installed (usually somewhere under /usr/include or * /usr/local/include). * * This patch should resolve this problem without undoing all of * Lars's hard work. * * As an asside: I think that portability.h is a virus that has * infected all of heartbeat's code and now must also infect all * code that builds against heartbeat. I wish that it didn't need * to be included all over the place. Especially in headers to * be installed on the system. However, I respect Lars's opinion * that this is the best way to resolve some weird build problems * in the current tree. * * Revision 1.36 2002/11/22 07:04:39 horms * make lots of symbols static * * Revision 1.35 2002/10/30 17:17:40 alan * Added some debugging, and changed one message from an ERROR to a WARNING. * * Revision 1.34 2002/10/22 17:41:58 alan * Added some documentation about deadtime, etc. * Switched one of the sets of FIFOs to IPC channels. * Added msg_from_IPC to ha_msg.c make that easier. * Fixed a few compile errors that were introduced earlier. * Moved hb_api_core.h out of the global include directory, * and back into a local directory. I also make sure it doesn't get * installed. This *shouldn't* cause problems. * Added a ipc_waitin() function to the IPC code to allow you to wait for * input synchronously if you really want to. * Changes the STONITH test to default to enabled. * * Revision 1.33 2002/10/21 10:17:18 horms * hb api clients may now be built outside of the heartbeat tree * * Revision 1.32 2002/10/18 07:16:08 alan * Put in Horms big patch plus a patch for the apcmastersnmp code where * a macro named MIN returned the MAX instead. The code actually wanted * the MAX, so when the #define for MIN was surrounded by a #ifndef, then * it no longer worked... This fix courtesy of Martin Bene. * There was also a missing #include needed on older Linux systems. * * Revision 1.31 2002/10/08 14:33:18 msoffen * Changed cl_log_message to be NULL safe. * * Revision 1.30 2002/10/02 13:36:42 alan * Put in a fix from Nathan Wallwork for a potential security vulnerability. * * Revision 1.29 2002/09/26 06:09:38 horms * log a debug message if it looks like an feild in a heartbeat message has been truncated * * Revision 1.28 2002/09/20 02:09:50 alan * Switched heartbeat to do everything with longclock_t instead of clock_t. * Switched heartbeat to be configured fundamentally from millisecond times. * Changed heartbeat to not use alarms for much of anything. * These are relatively major changes, but the seem to work fine. * * Revision 1.27 2002/09/17 20:48:06 alan * Put in a check for NULL in ha_msg_mod(). * * Revision 1.26 2002/08/10 02:13:32 alan * Better error logging when ha_msg functions are given bad name/value pairs. * * Revision 1.25 2002/07/08 04:14:12 alan * Updated comments in the front of various files. * Removed Matt's Solaris fix (which seems to be illegal on Linux). * * Revision 1.24 2002/04/13 22:35:08 alan * Changed ha_msg_add_nv to take an end pointer to make it safer. * Added a length parameter to string2msg so it would be safer. * Changed the various networking plugins to use the new string2msg(). * * Revision 1.23 2002/04/11 05:57:44 alan * Made some of the debugging output clearer. * * Revision 1.22 2002/02/21 21:43:33 alan * Put in a few fixes to make the client API work more reliably. * Put in a few changes to the process exit handling code which * also cause heartbeat to (attempt to) restart when it finds one of it's * own processes dies. Restarting was already broken :-( * * Revision 1.21 2002/02/14 14:09:29 alan * Put in a change requested by Ram Pai to allow message values to be * empty strings. * * Revision 1.20 2001/10/24 20:46:28 alan * A large number of patches. They are in these categories: * Fixes from Matt Soffen * Fixes to test environment things - including changing some ERRORs to * WARNings and vice versa. * etc. * * Revision 1.19 2001/08/21 15:37:13 alan * Put in code to make sure the calls in msg2stream get checked for errors... * * Revision 1.18 2001/06/19 13:56:28 alan * FreeBSD portability patch from Matt Soffen. * Mainly added #include "portability.h" to lots of files. * Also added a library to Makefile.am * * Revision 1.17 2001/06/12 17:05:47 alan * Fixed bug reported by Emily Ratliff <ratliff@austin.ibm.com> * In ha_msg_mod() the code fails to update the stringlen value for * fields modified by the input parameters. * This could potentially cause a crash. * Thanks to Emily for reporting this bug! * * Revision 1.16 2001/05/11 14:55:06 alan * Followed David Lee's suggestion about splitting out all the heartbeat process * management stuff into a separate header file... * Also changed to using PATH_MAX for maximum pathname length. * * Revision 1.15 2000/07/26 05:17:19 alan * Added GPL license statements to all the code. * * Revision 1.14 2000/07/19 23:03:53 alan * Working version of most of the API code. It still has the security bug... * * Revision 1.13 2000/07/11 14:42:42 alan * More progress on API code. * * Revision 1.12 2000/07/11 00:25:52 alan * Added a little more API code. It looks like the rudiments are now working. * * Revision 1.11 2000/05/11 22:47:50 alan * Minor changes, plus code to put in hooks for the new API. * * Revision 1.10 2000/04/12 23:03:49 marcelo * Added per-link status instead per-host status. Now we will able * to develop link<->service dependacy scheme. * * Revision 1.9 1999/11/22 20:28:23 alan * First pass of putting real packet retransmission. * Still need to request missing packets from time to time * in case retransmit requests get lost. * * Revision 1.8 1999/10/25 15:35:03 alan * Added code to move a little ways along the path to having error recovery * in the heartbeat protocol. * Changed the code for serial.c and ppp-udp.c so that they reauthenticate * packets they change the ttl on (before forwarding them). * * Revision 1.7 1999/10/10 20:11:56 alanr * New malloc/free (untested) * * Revision 1.6 1999/10/05 06:00:55 alanr * Added RPM Cflags to Makefiles * * Revision 1.5 1999/10/03 03:13:43 alanr * Moved resource acquisition to 'heartbeat', also no longer attempt to make the FIFO, it's now done in heartbeat. It should now be possible to start it up more readily... * * Revision 1.4 1999/09/29 03:22:05 alanr * Added the ability to reread auth config file on SIGHUP * * Revision 1.3 1999/09/26 21:59:58 alanr * Allow multiple auth strings in auth file... (I hope?) * * Revision 1.2 1999/09/26 14:01:01 alanr * Added Mijta's code for authentication and Guenther Thomsen's code for serial locking and syslog reform * * Revision 1.9 1999/09/16 05:50:20 alanr * Getting ready for 0.4.3... * * Revision 1.8 1999/08/25 06:34:26 alanr * Added code to log outgoing messages in a FIFO... * * Revision 1.7 1999/08/18 04:28:48 alanr * added function to dump a message to the log... * * Revision 1.6 1999/08/17 03:46:48 alanr * added log entry... * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -