void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
  CRYPTO_THREADID current_thread;
  char buf[ERR_ERROR_STRING_BUF_LEN];
  char buf2[1024];
  unsigned long thread_hash;
  const char *file;
  char *data;
  int line, flags;
  uint32_t packed_error;

  CRYPTO_THREADID_current(&current_thread);
  thread_hash = CRYPTO_THREADID_hash(&current_thread);

  for (;;) {
    packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
    if (packed_error == 0) {
      break;
    }

    ERR_error_string_n(packed_error, buf, sizeof(buf));
    BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf,
                 file, line, (flags & ERR_FLAG_STRING) ? data : "");
    if (callback(buf2, strlen(buf2), ctx) <= 0) {
      break;
    }
    if (flags & ERR_FLAG_MALLOCED) {
      OPENSSL_free(data);
    }
  }
}
int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
	     int line)
	{
	int ret = 0;

	if (add_lock_callback != NULL)
		{
#ifdef LOCK_DEBUG
		int before= *pointer;
#endif

		ret=add_lock_callback(pointer,amount,type,file,line);
#ifdef LOCK_DEBUG
		{
		CRYPTO_THREADID id;
		CRYPTO_THREADID_current(&id);
		TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
			CRYPTO_THREADID_hash(&id), before,amount,ret,
			CRYPTO_get_lock_name(type),
			file,line);
		}
#endif
		}
	else
		{
		CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);

		ret= *pointer+amount;
#ifdef LOCK_DEBUG
		{
		CRYPTO_THREADID id;
		CRYPTO_THREADID_current(&id);
		TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
			CRYPTO_THREADID_hash(&id),
			*pointer,amount,ret,
			CRYPTO_get_lock_name(type),
			file,line);
		}
#endif
		*pointer=ret;
		CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
		}
	return(ret);
	}
void CRYPTO_lock(int mode, int type, const char *file, int line)
	{
#ifdef LOCK_DEBUG
		{
		CRYPTO_THREADID id;
		char *rw_text,*operation_text;

		if (mode & CRYPTO_LOCK)
			operation_text="lock  ";
		else if (mode & CRYPTO_UNLOCK)
			operation_text="unlock";
		else
			operation_text="ERROR ";

		if (mode & CRYPTO_READ)
			rw_text="r";
		else if (mode & CRYPTO_WRITE)
			rw_text="w";
		else
			rw_text="ERROR";

		CRYPTO_THREADID_current(&id);
		TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"lock:%08lx:(%s)%s %-18s %s:%d\n",
			CRYPTO_THREADID_hash(&id), rw_text, operation_text,
			CRYPTO_get_lock_name(type), file, line);
		}
#endif
	if (type < 0)
		{
		if (dynlock_lock_callback != NULL)
			{
			struct CRYPTO_dynlock_value *pointer
				= CRYPTO_get_dynlock_value(type);

			OPENSSL_assert(pointer != NULL);

			dynlock_lock_callback(mode, pointer, file, line);

			CRYPTO_destroy_dynlockid(type);
			}
		}
	else
		if (locking_callback != NULL)
			locking_callback(mode,type,file,line);
	}
Example #4
0
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
                         void *u)
{
    unsigned long l;
    char buf[256];
    char buf2[4096];
    const char *file, *data;
    int line, flags;
    unsigned long es;
    CRYPTO_THREADID cur;

    CRYPTO_THREADID_current(&cur);
    es = CRYPTO_THREADID_hash(&cur);
    while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
        ERR_error_string_n(l, buf, sizeof buf);
        BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf,
                     file, line, (flags & ERR_TXT_STRING) ? data : "");
        if (cb(buf2, strlen(buf2), u) <= 0)
            break;              /* abort outputting the error report */
    }
}
Example #5
0
extern "C" void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
			 void *u)
	{
	unsigned long l;
	char buf[256];
	char buf2[4096];
	const char *file,*data;
	int line,flags;
	unsigned long es;
	CRYPTO_THREADID cur;

	CRYPTO_THREADID_current(&cur);
	es=CRYPTO_THREADID_hash(&cur);
	while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
		{
		ERR_error_string_n(l, buf, sizeof buf);
		BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf,
			file, line, (flags & ERR_TXT_STRING) ? data : "");
		cb(buf2, TINYCLR_SSL_STRLEN(buf2), u);
		}
	}
Example #6
0
static unsigned long err_state_hash(const ERR_STATE *a)
{
    return CRYPTO_THREADID_hash(&a->tid) * 13;
}