NCBI C++ ToolKit
ncbi_core_cxx.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_core_cxx.cpp 101842 2024-02-21 16:37:36Z lavr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Anton Lavrentiev
27  *
28  * File Description:
29  * C++->C conversion tools for basic CORE connect stuff:
30  * Registry
31  * Logging
32  * Locking
33  *
34  */
35 
36 #include <ncbi_pch.hpp>
37 #include "ncbi_ansi_ext.h"
38 #include "ncbi_socketp.h"
39 #include <corelib/ncbiapp.hpp>
40 #include <corelib/ncbidbg.hpp>
41 #include <corelib/ncbi_param.hpp>
42 #include <corelib/request_ctx.hpp>
43 #include <connect/error_codes.hpp>
45 #include <connect/ncbi_monkey.hpp>
46 #include <connect/ncbi_util.h>
47 #include <common/ncbi_sanitizers.h>
48 
49 #ifdef NCBI_POSIX_THREADS
50 #include <pthread.h>
51 #endif // NCBI_POSIX_THREADS
52 
53 #define NCBI_USE_ERRCODE_X Connect_Core
54 
55 
57 
58 
59 NCBI_PARAM_DECL (bool, CONN, TRACE_REG);
60 NCBI_PARAM_DEF_EX(bool, CONN, TRACE_REG,
61  false, eParam_Default, CONN_TRACE_REG);
62 static NCBI_PARAM_TYPE (CONN, TRACE_REG) s_TraceReg;
63 
64 NCBI_PARAM_DECL (bool, CONN, TRACE_LOG);
65 NCBI_PARAM_DEF_EX(bool, CONN, TRACE_LOG,
66  false, eParam_Default, CONN_TRACE_LOG);
67 static NCBI_PARAM_TYPE (CONN, TRACE_LOG) s_TraceLog;
68 
69 NCBI_PARAM_DECL (bool, CONN, TRACE_LOCK);
70 NCBI_PARAM_DEF_EX(bool, CONN, TRACE_LOCK,
71  false, eParam_Default, CONN_TRACE_LOCK);
72 static NCBI_PARAM_TYPE (CONN, TRACE_LOCK) s_TraceLock;
73 
74 
75 static TCORE_Set s_CORE_Set = 0;
76 
77 
78 /***********************************************************************
79  * Registry *
80  ***********************************************************************/
81 
82 
83 static string x_Reg(const char* section, const char* name,
84  const char* value = 0,
85  EREG_Storage storage = eREG_Transient)
86 {
87  string x_section;
88  if (section)
89  x_section = '[' + string(section) + ']';
90  else
91  x_section = "<NULL>";
92  string x_name;
93  if (name)
94  x_name = '"' + string(name) + '"';
95  else
96  x_name = "<NULL>";
97  string x_value;
98  if (value)
99  x_value = "=\"" + string(value) + '"';
100  string x_storage;
101  if (value) {
102  switch (int(storage)) {
103  case eREG_Transient:
104  x_storage = ", <Transient>";
105  break;
106  case eREG_Persistent:
107  x_storage = ", <Persistent>";
108  break;
109  default:
110  x_storage = ", <#" + NStr::IntToString(int(storage)) + '>';
111  break;
112  }
113  }
114  return x_section + x_name + x_value + x_storage;
115 }
116 
117 
118 extern "C" {
119 static int s_REG_Get(void* user_data,
120  const char* section, const char* name,
121  char* value, size_t value_size) THROWS_NONE
122 {
123  if (s_TraceReg.Get()) {
124  _TRACE("s_REG_Get(" + NStr::PtrToString(user_data) + ", "
125  + x_Reg(section, name) + ')');
126  }
127  int result = 0/*assume failure, including truncation*/;
128  try {
129  string item
130  = static_cast<const IRegistry*> (user_data)->Get(section, name);
131  if (!item.empty()) {
132  size_t len = item.size();
133  if (len >= value_size)
134  len = value_size - 1;
135  else
136  result = 1/*success*/;
137  strncpy0(value, item.data(), len);
138 
139  if (s_TraceReg.Get()) {
140  _TRACE("s_REG_Get(" + NStr::PtrToString(user_data) + ", "
141  + x_Reg(section, name) + ") = \"" + string(value)
142  + (result ? "\"" : "\" <Truncated>"));
143  }
144  } else
145  result = -1/*success,unmodified*/;
146  }
147  NCBI_CATCH_ALL_X(1, "s_REG_Get(" + NStr::PtrToString(user_data) + ", "
148  + x_Reg(section, name) + ") failed");
149  return result;
150 }
151 }
152 
153 
154 extern "C" {
155 static int s_REG_Set(void* user_data,
156  const char* section, const char* name,
157  const char* value, EREG_Storage storage) THROWS_NONE
158 {
159  if (s_TraceReg.Get()) {
160  _TRACE("s_REG_" + string(value ? "Set" : "Unset") + '('
161  + NStr::PtrToString(user_data) + ", "
162  + x_Reg(section, name, value ? value : "", storage) + ')');
163  }
164  int result = 0/*assume failure*/;
165  try {
166  IRWRegistry* reg = static_cast<IRWRegistry*> (user_data);
167  result = value
168  ? reg->Set (section, name, value,
169  (storage == eREG_Persistent
173  : reg->Unset(section, name,
174  (storage == eREG_Persistent
177  }
178  NCBI_CATCH_ALL_X(2, "s_REG_" + string(value ? "Set" : "Unset") + '('
179  + NStr::PtrToString(user_data) + ", "
180  + x_Reg(section, name, value ? value : "", storage)
181  + ") failed");
182  return result;
183 }
184 }
185 
186 
187 extern "C" {
188 static void s_REG_Cleanup(void* user_data) THROWS_NONE
189 {
190 
191  if (s_TraceReg.Get())
192  _TRACE("s_REG_Cleanup(" + NStr::PtrToString(user_data) + ')');
193  try {
194  static_cast<const IRegistry*> (user_data)->RemoveReference();
195  }
196  NCBI_CATCH_ALL_X(3, "s_REG_Cleanup("
197  + NStr::PtrToString(user_data) + ") failed");
198 }
199 }
200 
201 
202 extern REG REG_cxx2c(IRWRegistry* reg, bool pass_ownership)
203 {
204  if (s_TraceReg.Get())
205  _TRACE("REG_cxx2c(" + NStr::PtrToString(reg) + ')');
206  if (!reg)
207  return 0;
208  if (pass_ownership)
209  reg->AddReference();
210  return REG_Create(reg,
212  pass_ownership ? s_REG_Cleanup : 0, 0);
213 }
214 
215 
216 extern REG REG_cxx2c(const IRWRegistry* reg, bool pass_ownership)
217 {
218  if (s_TraceReg.Get())
219  _TRACE("REG_cxx2c(const " + NStr::PtrToString(reg) + ')');
220  if (!reg)
221  return 0;
222  if (pass_ownership)
223  reg->AddReference();
224  return REG_Create(const_cast<IRWRegistry*> (reg),
225  s_REG_Get, 0/*no setter*/,
226  pass_ownership ? s_REG_Cleanup : 0, 0);
227 }
228 
229 
230 /***********************************************************************
231  * Logger *
232  ***********************************************************************/
233 
234 
235 static string x_Log(ELOG_Level level)
236 {
237  string x_level;
238  switch (int(level)) {
239  case eLOG_Trace:
240  x_level = "Trace";
241  break;
242  case eLOG_Note:
243  x_level = "Note";
244  break;
245  case eLOG_Warning:
246  x_level = "Warning";
247  break;
248  case eLOG_Error:
249  x_level = "Error";
250  break;
251  case eLOG_Critical:
252  x_level = "Critical";
253  break;
254  case eLOG_Fatal:
255  x_level = "Fatal";
256  break;
257  default:
258  x_level = '#' + NStr::IntToString(int(level));
259  break;
260  }
261  return x_level;
262 }
263 
264 
265 extern "C" {
266 static void s_LOG_Handler(void* /*data*/,
267  const SLOG_Message* mess) THROWS_NONE
268 {
269  if (s_TraceLog.Get())
270  _TRACE("s_LOG_Handler(" + x_Log(mess->level) + ')');
271  try {
272  EDiagSev level;
273  switch (int(mess->level)) {
274  case eLOG_Trace:
275  level = eDiag_Trace;
276  break;
277  case eLOG_Note:
278  level = eDiag_Info;
279  break;
280  case eLOG_Warning:
281  level = eDiag_Warning;
282  break;
283  case eLOG_Error:
284  level = eDiag_Error;
285  break;
286  case eLOG_Critical:
287  level = eDiag_Critical;
288  break;
289  case eLOG_Fatal:
290  /*FALLTHRU*/
291  default:
292  level = eDiag_Fatal;
293  break;
294  }
295  if (level != eDiag_Fatal && !IsVisibleDiagPostLevel(level))
296  return;
297 
298  CDiagCompileInfo info(mess->file,
299  mess->line,
300  mess->func,
301  mess->module);
302  CNcbiDiag diag(info, level);
303  diag.SetErrorCode(mess->err_code, mess->err_subcode);
304  diag << mess->message;
305  if (mess->raw_size) {
309  if (mess->raw_data) {
310  buf.reset(new char[UTIL_PrintableStringSize
311  ((const char*)
312  mess->raw_data,
313  mess->raw_size)]);
314  char* end = UTIL_PrintableStringEx((const char*)
315  mess->raw_data,
316  mess->raw_size,
317  buf.get(), 0/*flags*/,
319  data.assign(buf.get(), (size_t)(end - buf.get()));
320  }
321  diag << "\n#################### [BEGIN] Raw Data ("
322  << mess->raw_size
323  << " byte" << &"s"[!(mess->raw_size != 1)] << "):"
324  << CTempString(data.empty() ? " <NULL>" : "\n") << data
325  << "\n#################### [_END_] Raw Data";
326  }
327  diag << Endm;
328  if (level == eDiag_Fatal)
329  Abort();
330  }
331  NCBI_CATCH_ALL_X(4, "s_LOG_Handler(" + x_Log(mess->level) + ") failed");
332 }
333 }
334 
335 
336 extern LOG LOG_cxx2c(void)
337 {
338  if (s_TraceLog.Get())
339  _TRACE("LOG_cxx2c()");
340  return LOG_Create(0, s_LOG_Handler, 0, 0);
341 }
342 
343 
344 /***********************************************************************
345  * MT-Lock *
346  ***********************************************************************/
347 
348 
349 static string x_Lock(EMT_Lock how)
350 {
351  string x_how;
352  switch (int(how)) {
353  case eMT_Lock:
354  x_how = "Lock";
355  break;
356  case eMT_LockRead:
357  x_how = "ReadLock";
358  break;
359  case eMT_Unlock:
360  x_how = "Unlock";
361  break;
362  case eMT_TryLock:
363  x_how = "TryLock";
364  break;
365  case eMT_TryLockRead:
366  x_how = "TryLockRead";
367  break;
368  default:
369  x_how = '#' + NStr::IntToString(int(how));
370  break;
371  }
372  return x_how;
373 }
374 
375 
376 extern "C" {
377 static int/*bool*/ s_LOCK_Handler(void* user_data, EMT_Lock how) THROWS_NONE
378 {
379  if (s_TraceLock.Get()) {
380  _TRACE("s_LOCK_Handler(" + NStr::PtrToString(user_data) + ", "
381  + x_Lock(how) + ')');
382  }
383  try {
384  CRWLock* lock = static_cast<CRWLock*> (user_data);
385  switch (int(how)) {
386  case eMT_Lock:
387  lock->WriteLock();
388  return 1/*success*/;
389  case eMT_LockRead:
390  lock->ReadLock();
391  return 1/*success*/;
392  case eMT_Unlock:
393  lock->Unlock();
394  return 1/*success*/;
395  case eMT_TryLock:
396  if (lock->TryWriteLock())
397  return 1/*success*/;
398  break;
399  case eMT_TryLockRead:
400  if (lock->TryReadLock())
401  return 1/*success*/;
402  break;
403  default:
404  NCBI_THROW(CCoreException, eCore, "Lock used with unknown op #"
405  + NStr::IntToString(int(how)));
406  }
407  }
408  NCBI_CATCH_ALL_X(5, "s_LOCK_Handler(" + NStr::PtrToString(user_data) + ", "
409  + x_Lock(how) + ") failed");
410  return 0/*failure*/;
411 }
412 }
413 
414 
415 extern "C" {
416 static void s_LOCK_Cleanup(void* user_data) THROWS_NONE
417 {
418  if (s_TraceLock.Get())
419  _TRACE("s_LOCK_Cleanup(" + NStr::PtrToString(user_data) + ')');
420  try {
421  delete static_cast<CRWLock*> (user_data);
422  }
423  NCBI_CATCH_ALL_X(6, "s_LOCK_Cleanup("
424  + NStr::PtrToString(user_data) + ") failed");
425 }
426 }
427 
428 
429 extern MT_LOCK MT_LOCK_cxx2c(CRWLock* lock, bool pass_ownership)
430 {
431  if (s_TraceLock.Get())
432  _TRACE("MT_LOCK_cxx2c(" + NStr::PtrToString(lock) + ')');
433  return MT_LOCK_Create(static_cast<void*> (lock ? lock : new CRWLock),
435  !lock || pass_ownership ? s_LOCK_Cleanup : 0);
436 }
437 
438 
439 /***********************************************************************
440  * App Name *
441  ***********************************************************************/
442 
443 
444 extern "C" {
445 static const char* s_GetAppName(void)
446 {
448  return app ? app->GetProgramDisplayName().c_str() : 0;
449 }
450 }
451 
452 
453 /***********************************************************************
454  * Referer *
455  ***********************************************************************/
456 
457 
458 extern "C" {
459 static const char* s_GetReferer(void)
460 {
461  const string& referer
463  return referer.empty() ? 0 : strdup(referer.c_str());
464 }
465 }
466 
467 
468 /***********************************************************************
469  * NCBI Request ID *
470  ***********************************************************************/
471 
472 
473 extern "C" {
474 static char* s_GetRequestID(ENcbiRequestID reqid)
475 {
476  string id;
477  switch (reqid) {
478  case eNcbiRequestID_SID:
479  if (!CDiagContext::GetRequestContext().IsSetSessionID())
482  break;
485  break;
486  default:
487  return 0;
488  }
489  return id.empty() ? 0 : strdup(id.c_str());
490 }
491 }
492 
493 
494 /***********************************************************************
495  * NCBI Request DTab *
496  ***********************************************************************/
497 
498 
499 extern "C" {
500 static const char* s_GetRequestDTab(void)
501 {
502  if (!CDiagContext::GetRequestContext().IsSetDtab())
504  return CDiagContext::GetRequestContext().GetDtab().c_str();
505 }
506 }
507 
508 
509 /***********************************************************************
510  * CRAZY MONKEY CALLS *
511  ***********************************************************************/
512 
513 
514 #ifdef NCBI_MONKEY
515 extern "C" {
516  static MONKEY_RETTYPE
517  MONKEY_STDCALL s_MonkeySend(MONKEY_SOCKTYPE sock,
518  const MONKEY_DATATYPE data,
519  MONKEY_LENTYPE size,
520  int flags,
521  void* /* SOCK* */ sock_ptr)
522  {
523  return CMonkey::Instance()->Send(sock, data, size, flags,
524  (SOCK*)sock_ptr);
525  }
526 
527  static MONKEY_RETTYPE
528  MONKEY_STDCALL s_MonkeyRecv(MONKEY_SOCKTYPE sock,
529  MONKEY_DATATYPE buf,
530  MONKEY_LENTYPE size,
531  int flags,
532  void* /* SOCK* */ sock_ptr)
533  {
534  return CMonkey::Instance()->Recv(sock, buf, size, flags,
535  (SOCK*) sock_ptr);
536  }
537 
538 
539  static int MONKEY_STDCALL s_MonkeyConnect(MONKEY_SOCKTYPE sock,
540  const struct sockaddr* name,
541  MONKEY_SOCKLENTYPE namelen)
542  {
543  return CMonkey::Instance()->Connect(sock, name, namelen);
544  }
545 
546 
547  static int /*bool*/ s_MonkeyPoll(size_t* n,
548  void* /* SSOCK_Poll** */ polls,
549  EIO_Status* return_status)
550  {
551  return CMonkey::Instance()->
552  Poll(n, (SSOCK_Poll**) polls, return_status) ? 1 : 0;
553  }
554 
555 
556  static void s_MonkeyClose(SOCKET sock)
557  {
558  CMonkey::Instance()->Close(sock);
559  }
560 
561 
562  static void s_MonkeySockHasSocket(void* /* SOCK* */ sock,
563  MONKEY_SOCKTYPE socket)
564  {
565  CMonkey::Instance()->SockHasSocket((SOCK)sock, socket);
566  }
567 }
568 
569 
570 static int s_MONKEY_Poll_dummy(size_t* n,
571  void* polls,
572  EIO_Status* return_status)
573 {
574  return 0; /* call was not intercepted by Monkey*/
575 }
576 
577 
578 static void s_MONKEY_Close_dummy(SOCKET sock)
579 {
580  return; /* call was not intercepted by Monkey*/
581 }
582 
583 
584 /* Chaos Monkey hooks for Connect library*/
585 static void s_SetMonkeyHooks(EMonkeyHookSwitch hook_switch)
586 {
587  switch (hook_switch)
588  {
589  case eMonkeyHookSwitch_Disabled:
590  g_MONKEY_Send = 0;
591  g_MONKEY_Recv = 0;
592  g_MONKEY_Connect = 0;
593  g_MONKEY_Poll = 0;
594  g_MONKEY_Close = 0;
595  g_MONKEY_SockHasSocket = 0;
596  break;
597  case eMonkeyHookSwitch_Enabled:
598  g_MONKEY_Send = s_MonkeySend;
599  g_MONKEY_Recv = s_MonkeyRecv;
600  g_MONKEY_Connect = s_MonkeyConnect;
601  g_MONKEY_Poll = s_MonkeyPoll;
602  g_MONKEY_Close = s_MonkeyClose;
603  g_MONKEY_SockHasSocket = s_MonkeySockHasSocket;
604  break;
605  default:
606  _TROUBLE;
607  break;
608  }
609 }
610 #endif //NCBI_MONKEY
611 
612 
613 #ifdef NCBI_POSIX_THREADS
614 extern "C" {
615 static void x_PreFork(void)
616 {
618 }
619 
620 static void x_PostFork(void)
621 {
622  CORE_UNLOCK;
623 }
624 } // extern "C"
625 #endif // NCBI_POSIX_THREADS
626 
627 
629  eConnectInit_Weak = -1, ///< CConn_Initer
630  eConnectInit_Intact = 0, ///< Not yet visited
631  eConnectInit_Strong = 1, ///< User init detected
632  eConnectInit_Explicit = 2 ///< CONNECT_Init() called
633 };
634 
635 static atomic<EConnectInit> s_ConnectInit = eConnectInit_Intact;
636 
637 
638 /***********************************************************************
639  * Fini *
640  ***********************************************************************/
641 
642 
643 extern "C" {
644 static void s_Fini(void) THROWS_NONE
645 {
646  _TRACE("CONNECT::s_Fini()");
648  if (s_CORE_Set & eCORE_SetSSL)
649  SOCK_SetupSSL(0);
650  if (s_CORE_Set & eCORE_SetREG)
651  CORE_SetREG(0);
652  if (s_CORE_Set & eCORE_SetLOG)
653  CORE_SetLOG(0);
655  CORE_SetLOCK(0);
657  s_CORE_Set = 0;
658 }
659 }
660 
661 
662 /***********************************************************************
663  * Init *
664  ***********************************************************************/
665 
666 
667 DEFINE_STATIC_FAST_MUTEX(s_ConnectInitMutex);
668 
669 /* NB: gets called under a lock */
670 static void s_Init(const IRWRegistry* reg = 0,
671  FSSLSetup ssl = 0,
672  CRWLock* lock = 0,
673  TConnectInitFlags flag = 0,
675 {
676  _TRACE("CONNECT::s_Init(reg="
677  + NStr::PtrToString(reg) + ", ssl="
678  + NStr::PtrToString((void*) ssl) + "(), lock="
679  + NStr::PtrToString(lock) + ", flag=0x"
680  + NStr::UIntToString((unsigned int) flag, 0, 16) + ", how="
681  + NStr::IntToString(int(how)) + ')');
683 
684  auto connect_init = s_ConnectInit.load(memory_order_acquire);
685  if (connect_init == how && how == eConnectInit_Explicit)
686  ERR_POST_X(11, "CONNECT_Init() called more than once");
687 
688  TCORE_Set x_set = 0;
689  if (!(g_CORE_Set & eCORE_SetLOCK)) {
692  x_set |= eCORE_SetLOCK;
693  }
694  if (!(g_CORE_Set & eCORE_SetLOG)) {
696  x_set |= eCORE_SetLOG;
697  }
698  if (!(g_CORE_Set & eCORE_SetREG)) {
700  x_set |= eCORE_SetREG;
701  }
702  if (!(g_CORE_Set & eCORE_SetSSL)) {
703  EIO_Status status = SOCK_SetupSSLInternalEx(ssl, 1/*init*/);
704  if (status != eIO_Success) {
705  ERR_POST_X(10, Critical << "Failed to initialize SSL: "
706  << IO_StatusStr(status));
707  }
708  if (ssl)
709  x_set |= eCORE_SetSSL;
710  }
711  g_CORE_Set &= ~x_set;
712  s_CORE_Set |= x_set;
713 
714  if (connect_init == eConnectInit_Intact) {
715  int err = 0;
717  = (unsigned int) time(0) ^ NCBI_CONNECT_SRAND_ADDEND;
719  if (x_set && atexit(s_Fini) != 0)
720  err |= 1;
721 #ifdef NCBI_POSIX_THREADS
722  if (pthread_atfork(x_PreFork, x_PostFork, x_PostFork) != 0)
723  err |= 2;
724 #endif // NCBI_POSIX_THREADS
725  if (err) {
726  static const char* what[] = {0, "exit", "fork", "exit/fork"};
728  << "Failed to register "
729  << what[err] << " handler" << &"s"[!(err == 3)]);
730  }
731  }
732 
737 
738 #ifdef NCBI_MONKEY
739  /* Allow CMonkey to switch hooks to Connect library */
740  CMonkey::MonkeyHookSwitchSet(s_SetMonkeyHooks);
741  /* Create CMonkey instance. It loads config and sets hooks */
742  CMonkey::Instance();
743 #endif //NCBI_MONKEY
744 
745  if (how < eConnectInit_Strong && g_CORE_Set)
746  how = eConnectInit_Strong;
747  if (connect_init < how || connect_init == eConnectInit_Intact)
748  s_ConnectInit.store(how, memory_order_release);
749 }
750 
751 
752 /* PUBLIC */
753 extern void CONNECT_Init(const IRWRegistry* reg,
754  CRWLock* lock,
755  TConnectInitFlags flag,
756  FSSLSetup ssl)
757 {
758  CFastMutexGuard guard(s_ConnectInitMutex);
759  _TRACE("CONNECT_Init(reg="
760  + NStr::PtrToString(reg) + ", lock="
761  + NStr::PtrToString(lock) + ", flag=0x"
762  + NStr::UIntToString((unsigned int) flag, 0, 16) + ", ssl="
763  + NStr::PtrToString((void*) ssl) + "())");
764  try {
765  g_CORE_Set = 0;
766  s_Init(reg, flag & eConnectInit_NoSSL ? 0 :
767  ssl ? ssl : NcbiSetupTls,
768  lock, flag, eConnectInit_Explicit);
769  }
770  NCBI_CATCH_ALL_X(8, "CONNECT_Init() failed");
771 }
772 
773 
775 {
776  auto connect_init = s_ConnectInit.load(memory_order_relaxed);
777  if (connect_init != eConnectInit_Intact)
778  return;
779  CFastMutexGuard guard(s_ConnectInitMutex);
780  try {
781  connect_init = s_ConnectInit.load(memory_order_acquire);
782  if (connect_init == eConnectInit_Intact) {
784  s_Init(app ? &app->GetConfig() : 0, NcbiSetupTls,
786  }
787  }
788  NCBI_CATCH_ALL_X(7, "CConn_Initer::CConn_Initer() failed");
789 }
790 
791 
AutoPtr –.
Definition: ncbimisc.hpp:401
CCoreException –.
Definition: ncbiexpt.hpp:1476
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
Definition: ncbidiag.hpp:65
CNcbiDiag –.
Definition: ncbidiag.hpp:924
CRWLock –.
Definition: ncbimtx.hpp:953
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
IRWRegistry –.
Definition: ncbireg.hpp:407
IRegistry –.
Definition: ncbireg.hpp:73
static uch flags
char data[12]
Definition: iconv.c:80
static CNcbiApplicationGuard InstanceGuard(void)
Singleton method.
Definition: ncbiapp.cpp:133
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
const string & GetProgramDisplayName(void) const
Get the application's "display" name.
string
Definition: cgiapp.hpp:687
#define _TRACE(message)
Definition: ncbidbg.hpp:122
string GetSessionID(void) const
Session ID.
void SetSessionID(const string &session)
const string & GetProperty(const string &name) const
Get property value or empty string.
const CNcbiDiag & SetErrorCode(int code=0, int subcode=0) const
Set error code and subcode numbers.
const string & GetNextSubHitID(CTempString prefix=CTempString())
Get current hit id appended with auto-incremented sub-hit id.
void SetDtab(const string &dtab)
bool IsVisibleDiagPostLevel(EDiagSev sev)
Check if the specified severity is higher or equal to the currently selected post level and will be p...
Definition: ncbidiag.cpp:6166
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
Definition: ncbidiag.cpp:1901
NCBI_XNCBI_EXPORT void Abort(void)
Smart abort function.
Definition: ncbidiag.cpp:8147
const string & GetDtab(void) const
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDiag_Trace
Trace message.
Definition: ncbidiag.hpp:657
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
@ eDiag_Warning
Warning message.
Definition: ncbidiag.hpp:652
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
@ eDiag_Critical
Critical error message.
Definition: ncbidiag.hpp:654
void Critical(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1203
#define NCBI_CATCH_ALL_X(err_subcode, message)
Definition: ncbiexpt.hpp:619
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define THROWS_NONE
Do not use 'throw' dynamic exception specification for C++11 compilers.
Definition: ncbiexpt.hpp:74
void AddReference(void) const
Add reference to object.
Definition: ncbiobj.hpp:489
@ eParam_Default
Default flags.
Definition: ncbi_param.hpp:416
bool Unset(const string &section, const string &name, TFlags flags=0)
Fully unset the configuration parameter value, so that HasEntry returns false.
Definition: ncbireg.cpp:867
bool Set(const string &section, const string &name, const string &value, TFlags flags=0, const string &comment=kEmptyStr)
Set the configuration parameter value.
Definition: ncbireg.cpp:826
@ fTruncate
Leading, trailing blanks can be truncated.
Definition: ncbireg.hpp:87
@ fPersistent
Persistent – saved when file is written.
Definition: ncbireg.hpp:84
@ fTransient
Transient – not saved by default.
Definition: ncbireg.hpp:83
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
SOCKSSL NcbiSetupTls(void)
Setup a TLS (Transport Layer Security) provider library to support SSL in ncbi_socket....
Definition: ncbi_tls.c:113
void SOCK_SetupSSL(FSSLSetup setup)
Store SSL setup callback until actual initialization.
Definition: ncbi_socket.c:8998
SOCKSSL(* FSSLSetup)(void)
SSL setup callback.
Definition: ncbi_socket.h:2312
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static void PtrToString(string &out_str, const void *ptr)
Convert pointer to string.
Definition: ncbistr.cpp:2771
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
Definition: ncbistr.hpp:5109
void ReadLock(void)
Read lock.
Definition: ncbimtx.cpp:863
bool TryReadLock(void)
Try read lock.
Definition: ncbimtx.cpp:976
bool TryWriteLock(void)
Try write lock.
Definition: ncbimtx.cpp:1320
void WriteLock(void)
Write lock.
Definition: ncbimtx.cpp:1201
void Unlock(void)
Release the RW-lock.
Definition: ncbimtx.cpp:1558
LOG LOG_cxx2c(void)
Create LOG on top of C++ Toolkit CNcbiDiag.
#define UTIL_PRINTABLE_WIDTH
Definition: ncbi_util.h:722
ELOG_Level
Log severity level.
Definition: ncbi_core.h:292
char * UTIL_PrintableStringEx(const char *data, size_t size, char *buf, TUTIL_PrintableFlags flags, int width)
Create a printable representation of a block of data of the specified size (or, if size is 0,...
Definition: ncbi_util.c:219
void CORE_SetREG(REG rg)
Set the registry (no registry if "rg" is passed zero) – to be used by the core internals.
Definition: ncbi_util.c:692
REG REG_cxx2c(IRWRegistry *reg, bool pass_ownership)
Convert a C++ Toolkit registry object to a REG registry.
EMT_Lock
Set the lock/unlock callback function and its data for MT critical section.
Definition: ncbi_core.h:180
void CONNECT_Init(const IRWRegistry *reg, CRWLock *lock, TConnectInitFlags flag, FSSLSetup ssl)
Init [X]CONNECT library with the specified "reg" and "lock" (ownership for either or both can be deta...
EREG_Storage
Transient/Persistent storage.
Definition: ncbi_core.h:528
REG REG_Create(void *data, FREG_Get get, FREG_Set set, FREG_Cleanup cleanup, MT_LOCK lock)
Create a new registry (with an internal reference count set to 1).
Definition: ncbi_core.c:484
void CORE_SetLOCK(MT_LOCK lk)
Set the MT critical section lock/unlock handler – to be used by the core internals for protection of ...
Definition: ncbi_util.c:100
MT_LOCK MT_LOCK_cxx2c(CRWLock *lock, bool pass_ownership)
Convert a C++ Toolkit lock object to an MT_LOCK lock.
EIO_Status
I/O status.
Definition: ncbi_core.h:132
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
Definition: ncbi_core.c:56
LOG LOG_Create(void *data, FLOG_Handler handler, FLOG_Cleanup cleanup, MT_LOCK lock)
Create a new LOG (with an internal reference count set to 1).
Definition: ncbi_core.c:313
unsigned int TConnectInitFlags
Bitwise OR of EConnectInitFlag.
size_t UTIL_PrintableStringSize(const char *data, size_t size)
Calculate size of buffer needed to store printable representation of the block of data of the specifi...
Definition: ncbi_util.c:198
MT_LOCK MT_LOCK_Create(void *data, FMT_LOCK_Handler handler, FMT_LOCK_Cleanup cleanup)
Create a new MT lock (with an internal reference count set to 1).
Definition: ncbi_core.c:199
void CORE_SetLOG(LOG lg)
Set the log handle (no logging if "lg" is passed zero) – to be used by the core internals (CORE LOG).
Definition: ncbi_util.c:123
ENcbiRequestID
NCBI request ID enumerator.
Definition: ncbi_util.h:432
@ eConnectInit_OwnLock
Lock ownership gets passed.
@ eConnectInit_NoSSL
Do NOT init secure socket layer (SSL)
@ eConnectInit_OwnRegistry
Registry ownership gets passed.
@ eLOG_Critical
Definition: ncbi_core.h:298
@ eLOG_Error
Definition: ncbi_core.h:297
@ eLOG_Note
Definition: ncbi_core.h:294
@ eLOG_Warning
Definition: ncbi_core.h:296
@ eLOG_Trace
Definition: ncbi_core.h:293
@ eLOG_Fatal
Definition: ncbi_core.h:299
@ eMT_Unlock
unlock critical section
Definition: ncbi_core.h:183
@ eMT_Lock
lock critical section
Definition: ncbi_core.h:181
@ eMT_LockRead
lock critical section for reading
Definition: ncbi_core.h:182
@ eMT_TryLock
try to lock, return immediately
Definition: ncbi_core.h:184
@ eMT_TryLockRead
try to lock for reading, return immediately
Definition: ncbi_core.h:185
@ eREG_Transient
only in-memory storage while program runs
Definition: ncbi_core.h:529
@ eREG_Persistent
hard-copy storage across program runs
Definition: ncbi_core.h:530
@ eIO_Success
everything is fine, no error occurred
Definition: ncbi_core.h:133
@ eNcbiRequestID_SID
NCBI Session ID.
Definition: ncbi_util.h:435
@ eNcbiRequestID_HitID
NCBI Hit ID.
Definition: ncbi_util.h:434
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
Definition of all error codes used in connect library (xconnect.lib, xconnext.lib etc).
char * buf
yy_size_t n
int len
static MDB_envinfo info
Definition: mdb_load.c:37
const TYPE & Get(const CNamedParameterList *param)
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
char * strncpy0(char *s1, const char *s2, size_t n)
Copy not more than "n" characters from string "s2" into "s1", and return the result,...
#define strdup
Definition: ncbi_ansi_ext.h:70
AutoPtr< char, CDeleter< char > > TTempCharPtr
NCBI_PARAM_DEF_EX(bool, CONN, TRACE_REG, false, eParam_Default, CONN_TRACE_REG)
static atomic< EConnectInit > s_ConnectInit
static char * s_GetRequestID(ENcbiRequestID reqid)
static void s_REG_Cleanup(void *user_data) THROWS_NONE
DEFINE_STATIC_FAST_MUTEX(s_ConnectInitMutex)
static TCORE_Set s_CORE_Set
static void x_PostFork(void)
static const char * s_GetAppName(void)
static void s_Fini(void) THROWS_NONE
static int s_REG_Get(void *user_data, const char *section, const char *name, char *value, size_t value_size) THROWS_NONE
static int s_LOCK_Handler(void *user_data, EMT_Lock how) THROWS_NONE
static int s_REG_Set(void *user_data, const char *section, const char *name, const char *value, EREG_Storage storage) THROWS_NONE
static void x_PreFork(void)
static void s_Init(const IRWRegistry *reg=0, FSSLSetup ssl=0, CRWLock *lock=0, TConnectInitFlags flag=0, EConnectInit how=eConnectInit_Weak)
static const char * s_GetReferer(void)
static string x_Log(ELOG_Level level)
static void s_LOG_Handler(void *, const SLOG_Message *mess) THROWS_NONE
static string x_Lock(EMT_Lock how)
NCBI_PARAM_DECL(bool, CONN, TRACE_REG)
static string x_Reg(const char *section, const char *name, const char *value=0, EREG_Storage storage=eREG_Transient)
static void s_LOCK_Cleanup(void *user_data) THROWS_NONE
static const char * s_GetRequestDTab(void)
EConnectInit
@ eConnectInit_Strong
User init detected.
@ eConnectInit_Weak
CConn_Initer.
@ eConnectInit_Intact
Not yet visited.
@ eConnectInit_Explicit
CONNECT_Init() called.
static NCBI_PARAM_TYPE(CONN, TRACE_REG) s_TraceReg
unsigned int g_NCBI_ConnectRandomSeed
Definition: ncbi_priv.c:51
FNcbiGetRequestDtab g_CORE_GetRequestDtab
Definition: ncbi_priv.c:55
TCORE_Set g_CORE_Set
Definition: ncbi_priv.c:47
FNcbiGetRequestID g_CORE_GetRequestID
Definition: ncbi_priv.c:54
FNcbiGetAppName g_CORE_GetAppName
Definition: ncbi_priv.c:52
FNcbiGetReferer g_CORE_GetReferer
Definition: ncbi_priv.c:53
@ eCORE_SetLOCK
Definition: ncbi_priv.h:329
@ eCORE_SetLOG
Definition: ncbi_priv.h:328
@ eCORE_SetSSL
Definition: ncbi_priv.h:326
@ eCORE_SetREG
Definition: ncbi_priv.h:327
#define CORE_LOCK_WRITE
Definition: ncbi_priv.h:269
#define NCBI_CONNECT_SRAND_ADDEND
Definition: ncbi_priv.h:343
#define CORE_UNLOCK
Definition: ncbi_priv.h:273
unsigned int TCORE_Set
Definition: ncbi_priv.h:331
Common macro to detect used sanitizers and suppress memory leaks if run under LeakSanitizer.
#define NCBI_LSAN_DISABLE_GUARD
EIO_Status SOCK_SetupSSLInternalEx(FSSLSetup setup, int init)
Definition: ncbi_socket.c:9004
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
NCBI C++ auxiliary debug macros.
#define SOCKET
Definition: net_sockets.c:81
Defines CRequestContext class for NCBI C++ diagnostic API.
Message and miscellaneous data to pass to log post callback FLOG_Handler.
Definition: ncbi_core.h:338
I/O polling structure.
Definition: ncbi_socket.h:966
#define _TROUBLE
#define _ASSERT
else result
Definition: token2.c:20
Modified on Sun Apr 21 03:39:13 2024 by modify_doxy.py rev. 669887