コード例 #1
0
ファイル: json.c プロジェクト: huangjingpei/asterisk
struct ast_json *ast_json_load_buf(const char *buffer, size_t buflen, struct ast_json_error *error)
{
	json_error_t jansson_error = {};
	struct ast_json *r = (struct ast_json *)json_loadb(buffer, buflen, 0, &jansson_error);
	copy_error(error, &jansson_error);
	return r;
}
コード例 #2
0
ファイル: json.c プロジェクト: huangjingpei/asterisk
struct ast_json *ast_json_load_new_file(const char *path, struct ast_json_error *error)
{
	json_error_t jansson_error = {};
	struct ast_json *r = (struct ast_json *)json_load_file(path, 0, &jansson_error);
	copy_error(error, &jansson_error);
	return r;
}
コード例 #3
0
AutoDescriptor receiveDescriptor(Descriptor streamPipe, char * errbuf, size_t bufsz)
{
	long desc;
	DWORD rc = -1;
	BOOL bSuccess = FALSE;

	if (streamPipe != BLOCXX_INVALID_HANDLE)
	{
		OVERLAPPED ovl;
		ZeroMemory(&ovl, sizeof(OVERLAPPED));

		bSuccess = ReadFile(streamPipe, &desc, sizeof(long), &rc, &ovl);

		if (!bSuccess)
		{
			DWORD lastError = GetLastError();

			if (lastError != ERROR_IO_INCOMPLETE && lastError != ERROR_IO_PENDING)
			{
				SetLastError(lastError);
				return copy_error(errbuf, bufsz, "ReadFile() failed");
			}
			else
			{
				DWORD waitFlag = WaitForSingleObject(streamPipe, INFINITE);

				if (waitFlag == WAIT_OBJECT_0)
				{
					GetOverlappedResult(streamPipe, &ovl, &rc, FALSE);
				}
				else
				{
					return copy_error(errbuf, bufsz, "WaitForSingleObject() failed");
				}
			}
		}

		return AutoDescriptor(reinterpret_cast<HANDLE>(desc));
	}

	return copy_error(errbuf, bufsz, "receiveDescriptor() error");
}
コード例 #4
0
ファイル: json.c プロジェクト: huangjingpei/asterisk
struct ast_json *ast_json_load_file(FILE *input, struct ast_json_error *error)
{
	json_error_t jansson_error = {};
	struct ast_json *r = NULL;
	if (input != NULL) {
		r = (struct ast_json *)json_loadf(input, 0, &jansson_error);
		copy_error(error, &jansson_error);
	} else {
		parse_error(error, "NULL input file", "<null>");
	}
	return r;
}
コード例 #5
0
ファイル: json.c プロジェクト: huangjingpei/asterisk
struct ast_json *ast_json_load_string(const char *input, struct ast_json_error *error)
{
	json_error_t jansson_error = {};
	struct ast_json *r = NULL;
	if (input != NULL) {
		r = (struct ast_json *)json_loads(input, 0, &jansson_error);
		copy_error(error, &jansson_error);
	} else {
		parse_error(error, "NULL input string", "<null>");
	}
	return r;
}
コード例 #6
0
db_error_dialog::db_error_dialog(const QString error) : m_error_text(error)
{
  setWindowTitle(tr("Database error"));
  QVBoxLayout* layout = new QVBoxLayout(this);

  setMinimumWidth(400);		// reasonable minimum

  QPlainTextEdit* label = new QPlainTextEdit;
  label->setPlainText(error);
  label->setReadOnly(true);
  label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
  label->setFrameShape(QFrame::Box);
  label->setFrameShadow(QFrame::Raised);
  layout->addWidget(label);

  m_btn_group = new QButtonGroup(this);
  QButtonGroup* g = m_btn_group;

  QRadioButton* btn1 = new QRadioButton(tr("Continue"));
  g->addButton(btn1, 1);
  btn1->setChecked(true);

  QRadioButton* btn2 = new QRadioButton(tr("Try to reconnect"));
  g->addButton(btn2, 2);

  QRadioButton* btn3 = new QRadioButton(tr("Quit application"));
  g->addButton(btn3, 3);

  layout->addWidget(btn1);
  layout->addWidget(btn2);
  layout->addWidget(btn3);

  QPushButton* btn_OK = new QPushButton(tr("OK"));
  btn_OK->setDefault(true);

  QPushButton* copy_btn = new QPushButton(tr("Copy"));

  QDialogButtonBox* buttonBox = new QDialogButtonBox(Qt::Horizontal);
  buttonBox->addButton(copy_btn, QDialogButtonBox::ActionRole);
  buttonBox->addButton(btn_OK, QDialogButtonBox::AcceptRole);
  layout->addWidget(buttonBox);
  connect(copy_btn, SIGNAL(clicked()), this, SLOT(copy_error()));
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  connect(this, SIGNAL(accepted()), this, SLOT(handle_error()));
}
コード例 #7
0
ファイル: PRINTER.C プロジェクト: daemqn/Atari_ST_Sources
void dir_print
(
	WINDOW *wd, 	/* to window structure */
	int n, 			/* number of items */
	int *list		/* to item list */
)
{
	boolean 
		noerror = TRUE;	/* true while no error */

	char 
		dline[134];		/* sufficiently long string for directory line */

	long 
		nfiles = 0,		/* file count */
	 	nfolders = 0,	/* folder count */
		nbytes = 0;		/* bytes sum */

	int
		error,			/* error id; =0 if  no errors */ 
		i,				/* item counter */
		button,			/* pressed button id. */
		type;			/* item type (file, folder...) */ 
	

	/* Count files, folders and bytes in this directory only (don't recurse) */

	for ( i = 0; i < n; i++ )
	{
		type = itm_type(wd, list[i]);
		if ( type == ITM_FILE || type == ITM_PROGRAM )
		{
			if ( (error = itm_attrib( wd, list[i], 0 ,&pattr) ) == 0 )
			{
				nbytes += pattr.size;
				nfiles++;
			}
			else
				error = copy_error(error, itm_name(wd, list[i]), 0); /* 0= any op but move or delete */
		}
		else if ( type == ITM_FOLDER )
			nfolders++;

		if ( error != 0 )
		{
			noerror = FALSE;
			break;
		}
	}

	if ( noerror )
	{
		/* Open confirmation dialog */

		cv_fntoform ( copyinfo + CPFOLDER, dir_path(wd) );
		*cpfile = 0;
		button = open_cfdialog( CF_PRINT, nfolders, nfiles, nbytes, CMD_PRINTDIR ); 

		/* If confirmed, print indeed */

		if ( button == COPYOK ) 
		{
			strcpy ( dline, get_freestring(TDIROF) ); 		/* Get "Directory of " string */
			get_dir_line( wd, &dline[strlen(dline)], -1 );	/* Append window title */

			if ( (noerror = !print_line(dline) ) == TRUE )
				noerror = !print_eol();

			i = 0;
			while ( (i < n) && noerror )
			{
				get_dir_line( wd, dline, list[i] );
				if ( dline[1] == (char)7 )
					dline[1] = '\\';	/* Mark folders with "\" */
				noerror = !print_line(dline);
				if ( escape_abort( cfdial_open ) )
					noerror = FALSE;
				i++;
			}
	
			if ( noerror )
			{
 				get_dir_line ( wd, dline, -2 );						/* get directory info line */
				if ( (noerror = !print_eol()) == TRUE )				/* print blank line */
					if ( ( noerror = !print_line(dline) ) == TRUE )	/* print directory total */
						noerror = !print_eol();						/* print blank line */
			}	/* noerror */
		}		/* button  */
		else
			noerror = FALSE;

	} /* if noerror */

	if ( button != 0 )
		close_cfdialog(button);
}
コード例 #8
0
ファイル: PRINTER.C プロジェクト: daemqn/Atari_ST_Sources
boolean item_print(WINDOW *wd, int n, int *list)
{
	int i = 0, button, result = 0;
	boolean noerror = TRUE;

	/* DjV 031 070203 ---vvv--- */
	/* XDINFO info; */
	long nfiles=0, nfolders=0, nbytes=0, error;
	const char *name;
	/* DjV 031 070203 ---^^^--- */

	if (check_print(wd, n, list) == FALSE)
		return FALSE;

	/* DjV 031 080203 ---vvv--- */

	/* rsc_ltoftext(print, NITEMS, n); */

	/* xd_open(print, &info); */
	if ( count_items(wd, n, list, &nfolders, &nfiles, &nbytes) )	/* HR 151102: always display. */
	{	/* DjV 031 140203 */

		cv_fntoform ( copyinfo + CPFOLDER, fn_get_name(dir_path(wd)) );	  	/* DjV 031 140203 */
		cv_fntoform ( copyinfo + CPFILE, itm_name(wd, list[0]) ); 			/* DjV 031 140203 */

		button = open_cfdialog( CF_PRINT, 0L, (long)n, nbytes, CMD_PRINT ); /* DJV 031 070203 */
	} /* DjV 031 140203 */
	else
		button = 0;

	/* if (button == PRINTOK) */ 
	if ( button == COPYOK ) 
	/* DjV 031 080203 ---^^^--- */
	{
		if ((i < n) && (result != XFATAL) && (result != XABORT))
		{
			/* DjV 031 080203 ---vvv--- */
			name = itm_name(wd, list[i]);
			upd_name( dir_path(wd), CPFOLDER );	
			upd_name ( name, CPFILE ); 
			/* DjV 031 080203 ---^^^--- */

			result = print_file(wd, list[i]);

			if (result == XFATAL)
				noerror = FALSE;

			/* DJV 031 070203 150203 ---vvv--- */
			/* 
			rsc_ltoftext(print, NITEMS, n - i - 1);
			xd_draw(&info, NITEMS, 1);
			*/
			if ((error = itm_attrib(wd, list[i], 0, &pattr)) == 0)
			{
				nbytes -= pattr.size;
				upd_copyinfo ( 0L, n - i - 1, nbytes ); 
			}
			else
				result = copy_error(error, name, 0); /* 0= any op but move or delete is "copy" */
			/* DjV 031 070203 150203 ---^^^--- */

			i++;
		}
	}
	else
		noerror = FALSE;

	/* DjV 031 070203 ---vvv--- */
	/*
	xd_change(&info, button, NORMAL, 0);
	xd_close(&info);
	*/
	if ( button != 0 )
		close_cfdialog( button );
	/* DjV 031 070203 ---^^^--- */

	return noerror;
}
コード例 #9
0
AutoDescriptor receiveDescriptor(Descriptor streamPipe, char * errbuf, size_t bufsz)
{
	struct msghdr msg;
	struct iovec iov[1];

	msg = msghdr(); // zero-init to make valgrind happy
#ifdef BLOCXX_HAVE_MSGHDR_MSG_CONTROL
	union {
		struct cmsghdr cm;
		char control[BLOCXX_MSGHDR_MSG_SIZE_INT];
	} control_un;

	msg.msg_control = control_un.control;
	msg.msg_controllen = sizeof(control_un.control);
#else
	int	newfd = -1;

#ifdef BLOCXX_NCR
	void *temp_cast = &newfd;
	msg.msg_accrights = static_cast<caddr_t>(temp_cast);
#else
	msg.msg_accrights = static_cast<caddr_t>(&newfd);
#endif

	msg.msg_accrightslen = sizeof(int);
#endif

	msg.msg_name = 0;
	msg.msg_namelen = 0;

	char dummy[1] = { '\x7F' };
	iov[0].iov_base = dummy;
	iov[0].iov_len = 1;
	msg.msg_iov = iov;
	msg.msg_iovlen = 1;

	ssize_t	n = ::recvmsg(streamPipe, &msg, 0);
	if (n == 0)
	{
		return copy_error(errbuf, bufsz,
			"unexpected end of input when receiving handle");
	}
	if (n < 0)
	{
		return copy_error(errbuf, bufsz, "recvmsg() failed");
	}
	if (n != 1)
	{
		return copy_error(errbuf, bufsz, "received more than 1 byte.");
	}
	if (dummy[0] != MAGIC_CHAR)
	{
		return copy_error(errbuf, bufsz, "bad magic char when receiving handle");
	}


#ifdef BLOCXX_HAVE_MSGHDR_MSG_CONTROL
	struct cmsghdr * cmptr = CMSG_FIRSTHDR(&msg);
	if (!cmptr)
	{
		return copy_error(errbuf, bufsz,
			"missing control message when receiving handle");
	}
	// as far as I can tell, HP-UX is just broken and sets cmptr->cmsg_len to 12. Things work anyway.
#if !defined (BLOCXX_HPUX)
	if (cmptr->cmsg_len != CMSG_LEN(sizeof(int)))
	{
		return copy_error(errbuf, bufsz,
			"cmptr->cmsg_len != CMSG_LEN(sizeof(int)) when receiving handle");
	}
#endif
	if (cmptr->cmsg_level != SOL_SOCKET)
	{
		return copy_error(errbuf, bufsz,
			"control level != SOL_SOCKET when receiving handle");
	}
	if (cmptr->cmsg_type != SCM_RIGHTS)
	{
		return copy_error(errbuf, bufsz,
			"control type != SCM_RIGHTS when receiving handle");
	}
	int* ptr = reinterpret_cast<int *>(CMSG_DATA(cmptr));
	return AutoDescriptor(*ptr);
#else
	if (msg.msg_accrightslen != sizeof(int))
	{
		return copy_error(errbuf, bufsz,
			"bad control message when receiving handle");
	}
	return AutoDescriptor(newfd);
#endif
}