New API call Xorriso_fetch_outlists()
This commit is contained in:
@ -23,6 +23,8 @@
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
/* for -charset */
|
||||
#include <iconv.h>
|
||||
@ -520,6 +522,68 @@ ex:;
|
||||
}
|
||||
|
||||
|
||||
static int Xorriso_lock_outlists(struct XorrisO *xorriso, int flag)
|
||||
{
|
||||
int ret;
|
||||
static int complaints= 0, complaint_limit= 5;
|
||||
|
||||
ret= pthread_mutex_lock(&(xorriso->result_msglists_lock));
|
||||
if(ret != 0) {
|
||||
/* Cannot report failure through the failing message output system */
|
||||
complaints++;
|
||||
if(complaints < complaint_limit)
|
||||
fprintf(stderr,
|
||||
"xorriso : pthread_mutex_lock() for outlists returns %d\n",
|
||||
ret);
|
||||
return(-1);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
static int Xorriso_unlock_outlists(struct XorrisO *xorriso, int flag)
|
||||
{
|
||||
int ret;
|
||||
static int complaints= 0, complaint_limit= 5;
|
||||
|
||||
ret= pthread_mutex_unlock(&(xorriso->result_msglists_lock));
|
||||
if(ret != 0) {
|
||||
/* Cannot report failure through the failing message output system */
|
||||
complaints++;
|
||||
if(complaints < complaint_limit)
|
||||
fprintf(stderr,
|
||||
"xorriso : pthread_mutex_unlock() for outlists returns %d\n",
|
||||
ret);
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
static int Xorriso_write_to_msglist(struct XorrisO *xorriso,
|
||||
struct Xorriso_lsT **xorriso_msglist,
|
||||
char *text, int flag)
|
||||
{
|
||||
int ret;
|
||||
struct Xorriso_lsT *msglist;
|
||||
|
||||
ret= Xorriso_lock_outlists(xorriso, 0);
|
||||
if(ret <= 0)
|
||||
return(-1);
|
||||
msglist= *xorriso_msglist;
|
||||
ret= Xorriso_lst_append_binary(&msglist, text, strlen(text) + 1, 0);
|
||||
if(ret <= 0) {
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
if(*xorriso_msglist == NULL)
|
||||
*xorriso_msglist= msglist;
|
||||
ret= 1;
|
||||
ex:;
|
||||
Xorriso_unlock_outlists(xorriso, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_write_to_channel(struct XorrisO *xorriso,
|
||||
char *in_text, int channel_no, int flag)
|
||||
/*
|
||||
@ -534,7 +598,6 @@ bit15= with bit1 to bit3: close depicted log file
|
||||
int ret= 1, info_redirected= 0, result_redirected= 0;
|
||||
char prefix[16];
|
||||
FILE *logfile_fp, *pktlog_fp;
|
||||
struct Xorriso_lsT *msglist;
|
||||
static int num_channels= 4;
|
||||
static char channel_prefixes[4][4]= {".","R","I","M"};
|
||||
|
||||
@ -610,22 +673,20 @@ bit15= with bit1 to bit3: close depicted log file
|
||||
}
|
||||
if(result_redirected) {
|
||||
if(channel_no==1 || channel_no==3) {
|
||||
msglist= xorriso->result_msglists[xorriso->msglist_stackfill - 1];
|
||||
ret= Xorriso_lst_append_binary(&msglist, text, strlen(text) + 1, 0);
|
||||
ret= Xorriso_write_to_msglist(xorriso,
|
||||
&(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
|
||||
text, 0);
|
||||
if(ret <= 0)
|
||||
{ret= -1; goto ex;}
|
||||
if(xorriso->result_msglists[xorriso->msglist_stackfill - 1] == NULL)
|
||||
xorriso->result_msglists[xorriso->msglist_stackfill - 1]= msglist;
|
||||
{ ret= -1; goto ex; }
|
||||
}
|
||||
}
|
||||
if(info_redirected) {
|
||||
if(channel_no==2 || channel_no==3) {
|
||||
msglist= xorriso->info_msglists[xorriso->msglist_stackfill - 1];
|
||||
ret= Xorriso_lst_append_binary(&msglist, text, strlen(text) + 1, 0);
|
||||
ret= Xorriso_write_to_msglist(xorriso,
|
||||
&(xorriso->info_msglists[xorriso->msglist_stackfill - 1]),
|
||||
text, 0);
|
||||
if(ret <= 0)
|
||||
{ret= -1; goto ex;}
|
||||
if(xorriso->info_msglists[xorriso->msglist_stackfill - 1] == NULL)
|
||||
xorriso->info_msglists[xorriso->msglist_stackfill - 1]= msglist;
|
||||
{ ret= -1; goto ex; }
|
||||
}
|
||||
}
|
||||
if((channel_no == 1 && result_redirected) ||
|
||||
@ -718,10 +779,17 @@ ex:
|
||||
int Xorriso_push_outlists(struct XorrisO *xorriso, int *stack_handle,
|
||||
int flag)
|
||||
{
|
||||
int ret, locked= 0;
|
||||
|
||||
ret= Xorriso_lock_outlists(xorriso, 0);
|
||||
if(ret != 0)
|
||||
{ret= -1; goto ex;}
|
||||
locked= 1;
|
||||
|
||||
if(xorriso->msglist_stackfill + 1 >= Xorriso_max_outlist_stacK) {
|
||||
Xorriso_msgs_submit(xorriso, 0,
|
||||
"Overflow of message output redirection stack", 0, "FATAL", 0);
|
||||
return(-1);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
if((flag & 3) == 0)
|
||||
flag|= 3;
|
||||
@ -730,21 +798,74 @@ int Xorriso_push_outlists(struct XorrisO *xorriso, int *stack_handle,
|
||||
xorriso->info_msglists[xorriso->msglist_stackfill - 1]= NULL;
|
||||
xorriso->msglist_flags[xorriso->msglist_stackfill - 1]= flag & 3;
|
||||
*stack_handle= xorriso->msglist_stackfill - 1;
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(locked)
|
||||
Xorriso_unlock_outlists(xorriso, 0);
|
||||
return(ret);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_fetch_outlists(struct XorrisO *xorriso, int stack_handle,
|
||||
struct Xorriso_lsT **result_list,
|
||||
struct Xorriso_lsT **info_list, int flag)
|
||||
{
|
||||
int ret, locked= 0;
|
||||
|
||||
ret= Xorriso_process_msg_queues(xorriso, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
if((flag & 3) == 0)
|
||||
flag|= 3;
|
||||
|
||||
ret= Xorriso_lock_outlists(xorriso, 0);
|
||||
if(ret != 0)
|
||||
{ret= -1; goto ex;}
|
||||
locked= 1;
|
||||
|
||||
if(stack_handle == -1)
|
||||
stack_handle= xorriso->msglist_stackfill - 1;
|
||||
if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) {
|
||||
Xorriso_msgs_submit(xorriso, 0,
|
||||
"Program error: Wrong message output redirection stack handle",
|
||||
0, "FATAL", 0);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
|
||||
if(flag & 1) {
|
||||
*result_list= xorriso->result_msglists[stack_handle];
|
||||
xorriso->result_msglists[stack_handle]= NULL;
|
||||
}
|
||||
if(flag & 2) {
|
||||
*info_list= xorriso->info_msglists[stack_handle];
|
||||
xorriso->info_msglists[stack_handle]= NULL;
|
||||
}
|
||||
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(locked)
|
||||
Xorriso_unlock_outlists(xorriso, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle,
|
||||
struct Xorriso_lsT **result_list,
|
||||
struct Xorriso_lsT **info_list, int flag)
|
||||
{
|
||||
int i;
|
||||
int i, ret, locked= 0;
|
||||
|
||||
ret= Xorriso_lock_outlists(xorriso, 0);
|
||||
if(ret != 0)
|
||||
{ret= -1; goto ex;}
|
||||
locked= 1;
|
||||
|
||||
if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) {
|
||||
Xorriso_msgs_submit(xorriso, 0,
|
||||
"Program error: Wrong message output redirection stack handle",
|
||||
0, "FATAL", 0);
|
||||
return(-1);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
*result_list= xorriso->result_msglists[stack_handle];
|
||||
*info_list= xorriso->info_msglists[stack_handle];
|
||||
@ -753,7 +874,11 @@ int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle,
|
||||
xorriso->info_msglists[i - 1]= xorriso->info_msglists[i];
|
||||
}
|
||||
xorriso->msglist_stackfill--;
|
||||
return(1);
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(locked)
|
||||
Xorriso_unlock_outlists(xorriso, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
@ -972,26 +1097,12 @@ int Xorriso_msgs_submit(struct XorrisO *xorriso,
|
||||
xorriso->info_text[li+lt]= '\n';
|
||||
xorriso->info_text[li+lt+1]= 0;
|
||||
|
||||
#ifdef NIX
|
||||
|
||||
/* <<< */
|
||||
Xorriso_info(xorriso,4|(flag&3));
|
||||
if(os_errno>0) {
|
||||
sprintf(xorriso->info_text, "%s%s : %s\n",
|
||||
pfx_list[(flag>>2)&15], sev_text, strerror(os_errno));
|
||||
Xorriso_info(xorriso,4|(flag&3));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if(os_errno>0) {
|
||||
sprintf(xorriso->info_text + strlen(xorriso->info_text) - 1,
|
||||
" : %s\n", strerror(os_errno));
|
||||
}
|
||||
Xorriso_info(xorriso,4|(flag&3));
|
||||
|
||||
#endif
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user