Exemplo n.º 1
0
static
bool _StringHas(const String *self, const char *buf, String *res)
{
    String dummy;
    size_t len = 0;
    assert(self && buf);
    if (res == NULL) {
        res = &dummy;
    }
    len = string_size(buf);
    assert(len);
    StringInit(res, self->addr, self->size, self->len);
    while (true) {
        if (res->len < len) {
            StringInit(res, NULL, 0, 0);
            return false;
        }
        if (_StringStartsWith(res, buf)) {
            res->len = (uint32_t)len;
            res->size = len;
            return true;
        }
        res->size = res->len - 1;
        res->len = res->len - 1;
        ++res->addr;
    }
}
Exemplo n.º 2
0
static rc_t vds_print_diff( const char * buffer1, const char * buffer2, size_t len1, size_t len2 )
{
	rc_t rc;
	String S1, S2;
	
	StringInit( &S1, buffer1, len1, len1 );
	StringInit( &S2, buffer2, len2, len2 );
	rc = KOutMsg( "\n[A] %S\n", &S1 );
	if ( rc == 0 )
		rc = KOutMsg( "[B] %S\n", &S2 );
	return rc;
}
Exemplo n.º 3
0
CMyString::CMyString(const char *psz)
{
    //需先进行初始化
    StringInit();

    SetString(psz);
}
Exemplo n.º 4
0
static
void StringTrim ( String *trim, const String *source )
{
    uint32_t str_len = source -> len;
    const char *start = source -> addr;
    const char *end = start + source -> size;

    while ( start < end )
    {
        if ( ! isspace ( * start ) )
            break;

        ++ start;
        -- str_len;
    } 

    while ( end > start )
    {
        if ( ! isspace ( end [ - 1 ] ) )
            break;

        -- end;
        -- str_len;
    } 

    StringInit ( trim, start, end - start, str_len );
}
Exemplo n.º 5
0
/* Make
 *  make a column ref from an SColumn*
 */
rc_t VColumnRefMake ( VColumnRef **rp, const VSchema *schema, const SColumn *scol )
{
    char text [ 256 ];
    rc_t rc = VTypedeclToText ( & scol -> td, schema, text, sizeof text );
    if ( rc == 0 )
    {
        size_t tdsize = strlen ( text );
        const String *name = & scol -> name -> name;
        VColumnRef *cref = malloc ( sizeof * cref + name -> size + tdsize );
        if ( cref == NULL )
            rc = RC ( rcVDB, rcTable, rcListing, rcMemory, rcExhausted );
        else
        {
            strcpy ( cref -> typedecl, text );
            string_copy ( & cref -> typedecl [ tdsize + 1 ], name -> size + 1, name -> addr, name -> size );
            StringInit ( & cref -> name, & cref -> typedecl [ tdsize + 1 ], name -> size, name -> len );
            cref -> td = scol -> td;
            cref -> cid = scol -> cid;
            cref -> dflt = scol -> dflt;

            * rp = cref;
        }
    }

    return rc;
}
Exemplo n.º 6
0
/* ----------------------------------------------------------------------
 * KTocEntryNewSoft
 *
 * [RET] rc_t					0 for success; anything else for a failure
 *						see itf/klib/rc.h for general details
 * [OUT] KTocEntry **		new_entry	where to put a pointer to the new TOC Entry
 * [IN]  const char * 		name		name of the file (not path) (not assumed to be ASCIZ)
 * [IN]  size_t 		name_size	length of name
 * [IN]  uint32_t		access		unix/posix style permission flags
 * [IN]  const char * 		link		character array (string) holding the name of the
 *						links target (not assumed to be ASCIZ)
 * [IN]  size_t 		link_size	length of the target string
 * Link is run time resolved
 */
rc_t KTocEntryNewSoft ( KTocEntry ** new_entry,
					 const char * name,
					 size_t name_size,
					 KTime_t mtime,
					 uint32_t access,
					 const char * link,
					 size_t link_size )
{
    rc_t	rc;
    char *	linkp;

    rc = KTocEntryNew (new_entry, name, name_size, mtime, access, 
		       (sizeof(KTocEntry)
			- sizeof(union KTocEntryUnion))
		       + sizeof(struct KTocEntrySoftLink) + link_size + 1);
    if (rc != 0)
    {
	return rc;
    }
    (*new_entry)->type = ktocentrytype_softlink;
    linkp =(char*)(*new_entry) + sizeof(KTocEntry) - sizeof(union KTocEntryUnion)
	+ sizeof(struct KTocEntrySoftLink);
    string_copy (linkp, link_size+1, link, link_size);
    StringInit ( &((*new_entry)->u.symbolic_link.link_path), linkp, link_size, (uint32_t)link_size );
    return 0;
}
Exemplo n.º 7
0
/* ----------------------------------------------------------------------
 * KTocEntryNew
 *
 * [RET] rc_t					0 for success; anything else for a failure
 *						see itf/klib/rc.h for general details
 * [OUT] KTocEntry ** 	new_entry	where to put a pointer to the new TOC Entry
 * [IN]  const char * 		name		name of the entry (file, link, directory...)
 *						(not assumed to be ASCIZ)
 * [IN]  size_t			name_size	length of name
 * [IN]  uint32_t 		access		unix/posix style permission flags
 * [IN]  size_t 		entry_specific	specific initialyers by entry type
 */
static
rc_t		KTocEntryNew		(KTocEntry ** new_entry,
					 const char * name,
					 size_t name_size,
					 KTime_t mtime,
					 uint32_t access,
					 size_t entry_specific)
{
    KTocEntry * entry;
    size_t	  nsize;
    char *	  namep;

    nsize = entry_specific + name_size + 1; /* we want a NUL at end of name */

    entry = malloc (nsize);
    if (entry == NULL)
    {
	LOGMSG (klogErr,
		"Failed to allocate for a TOC File entry");
	return RC (rcFS, rcToc, rcAllocating, rcMemory, rcInsufficient);
    }

    /* entry->entry is fine left as undefined */
    namep =(char*)entry + entry_specific;
    string_copy (namep, name_size+1, name, name_size);
    StringInit (&(entry->name), namep, name_size, (uint32_t)name_size);

    entry->mtime = mtime;
    entry->access = access;

    *new_entry = entry;
    return 0;
}
Exemplo n.º 8
0
static rc_t KNSProxiesAddHttpProxyPath ( KNSProxies * self,
    const char * proxy, size_t proxy_size,
    uint16_t proxy_port )
{
    const String * proxy_host = NULL;

    rc_t rc = 0;

    HttpProxy * new_proxy = NULL;
    BSTItem * node = NULL;

    HttpProxy add = { proxy_host, proxy_port, 0 };

    assert ( self );

    if ( proxy == NULL )
        return 0;

    if ( rc == 0 ) {
        String tmp;
        StringInit ( & tmp, proxy, proxy_size,
                     string_len ( proxy, proxy_size ) );
        rc = StringCopy ( & proxy_host, & tmp );
        if ( rc == 0 )
            add . proxy_host = proxy_host;
        else
            return rc;
    }

    if ( BSTreeFind ( & self -> proxie_tree, & add, BSTItemCmp )
         != NULL )
    {
        DBGMSG ( DBG_KNS, DBG_FLAG ( DBG_KNS_PROXY ),
            ( "Ignored duplicate proxy '%S:%d'\n", proxy_host, proxy_port ) );
        free ( ( void * ) proxy_host );
        return 0;
    }

    new_proxy = calloc ( 1, sizeof * new_proxy );
    if ( new_proxy == NULL )
        return RC ( rcNS, rcMgr, rcAllocating, rcMemory, rcExhausted );
    new_proxy -> proxy_host = proxy_host;
    new_proxy -> proxy_port = proxy_port;
    node = calloc ( 1, sizeof * node );
    if ( node == NULL ) {
        free ( new_proxy );
        return RC ( rcNS, rcMgr, rcAllocating, rcMemory, rcExhausted );
    }
    node -> proxy = new_proxy;

    rc = BSTreeInsert ( & self -> proxie_tree, ( BSTNode * ) node, BSTreeSort );

    DBGMSG ( DBG_KNS, DBG_FLAG ( DBG_KNS_PROXY ),
        ( "Added proxy '%S:%d'\n", proxy_host, proxy_port ) );

    if ( ! self -> http_proxy_enabled )
        self -> http_proxy_enabled = ( proxy_host != NULL );

    return rc;
}
Exemplo n.º 9
0
LIB_EXPORT rc_t CC KNSManagerVSetHTTPProxyPath ( KNSManager * self, const char * fmt, va_list args )
{
    rc_t rc = 0;

    if ( self == NULL )
        rc = RC ( rcNS, rcMgr, rcUpdating, rcSelf, rcNull );
    else
    {
        uint16_t proxy_port = 0;
        const String * proxy = NULL;

        if ( fmt != NULL && fmt [ 0 ] != 0 )
        {
            size_t psize;
            char path [ 4096 ];
            rc = string_vprintf ( path, sizeof path, & psize, fmt, args );
            if ( rc == 0 && psize != 0 )
            {
                char * colon = string_rchr ( path, psize, ':' );
                if ( colon != NULL )
                {
                    char * end;
                    const char * port_spec = colon + 1;
                    /* it is true that some day we might read symbolic port names... */
                    long port_num = strtol ( port_spec, & end, 10 );
                    if ( port_num <= 0 || port_num >= 0x10000 || end [ 0 ] != 0 )
                        rc = RC ( rcNS, rcMgr, rcUpdating, rcPath, rcInvalid );
                    else
                    {
                        proxy_port = ( uint64_t ) port_num;
                        psize = colon - path;
                    }
                }

                if ( rc == 0 )
                {
                    String tmp;
                    StringInit ( & tmp, path, psize, string_len ( path, psize ) );
                    rc = StringCopy ( & proxy, & tmp );
                }
            }
        }

        if ( rc == 0 )
        {
            if ( self -> http_proxy != NULL )
            {
                StringWhack ( self -> http_proxy );
                self -> http_proxy_port = 0;
            }

            self -> http_proxy = proxy;
            self -> http_proxy_enabled = ( proxy != NULL );
            self -> http_proxy_port = proxy_port;
        }
    }

    return rc;
}
Exemplo n.º 10
0
rc_t KeyRingGetProject(KKeyRing* self, const String* name, String* download_ticket, String* encryption_key)
{   
    rc_t rc = 0;
    const Project* p;
    
    assert(self && name && download_ticket && encryption_key);
    
    p = KeyRingDataGetProject(self->data, name);
    if (p != NULL)
    {
        StringInit(download_ticket, p->download_ticket->addr, p->download_ticket->len, p->download_ticket->size);
        StringInit(encryption_key, p->encryption_key->addr, p->encryption_key->len, p->encryption_key->size);
    }
    else
        rc = RC(rcApp, rcDatabase, rcSearching, rcName, rcNotFound);
    return rc;
}
Exemplo n.º 11
0
String* StringNew(guint length)
{
	String* res;
	
	res = newvarobj(String, gchar, length);
	StringInit(res, length);
	
	return res;
}
Exemplo n.º 12
0
static
rc_t
FastqSequenceInit(FastqSequence* self)
{
    self->sequence_vt.v1 = & FastqSequence_vt;
    KRefcountInit ( & self -> refcount, 1, "FastqSequence", "FastqSequenceInit", "");

    StringInit(&self->spotname, 0, 0, 0);
    StringInit(&self->spotgroup, 0, 0, 0);
    self->readnumber = 0;
    StringInit(&self->read, 0, 0, 0);
    self->is_colorspace = false;
    StringInit(&self->quality, 0, 0, 0);
    self->qualityAsciiOffset = 0;
    self->lowQuality = false;

    return 0;
}
Exemplo n.º 13
0
CMyNumString::CMyNumString(const char *psz)
{
    StringInit();

    if (!CheckNum(psz))
    {
        return;
    }

    StringCopy(psz);
}
Exemplo n.º 14
0
CMyNumString::CMyNumString(const CMyNumString &str)
{
    StringInit();

    if (!CheckNum(str.m_psz))
    {
        return;
    }

    CMyString::CMyString(str);
}
Exemplo n.º 15
0
static
rc_t aws_extract_key_value_pair ( const String *source, String *key, String *val )
{
    String k, v;
    const char *start = source -> addr;
    const char *end = start + source -> size;

    char *eql = string_chr ( start, source -> size, '=' );
    if ( eql == NULL )
        return RC ( rcKFG, rcChar, rcSearching, rcFormat, rcInvalid );

    /* key */
    StringInit ( &k, start, eql - start, string_len ( start, eql - start ) );
    StringTrim ( key, &k );

    start = eql + 1;

    /* value */
    StringInit ( &v, start, end - start,  string_len ( start, end - start ) ); 
    StringTrim ( val, &v );
    return 0;
}
Exemplo n.º 16
0
rc_t KeyRingGetKey(KKeyRing* self, const struct String* object_name, struct String* encryption_key)
{
    rc_t rc = 0;
    const Object* obj;

    assert(self && object_name && encryption_key);
    
    obj = KeyRingDataGetObject(self->data, object_name);
    if (obj != NULL)
        StringInit(encryption_key, obj->encryption_key->addr, obj->encryption_key->len, obj->encryption_key->size);
    else
        rc = RC(rcApp, rcDatabase, rcSearching, rcName, rcNotFound);
    return rc;
}
Exemplo n.º 17
0
static spotgrp * make_spotgrp( const char *src, const size_t len )
{
    spotgrp * sg = calloc( 1, sizeof sg[ 0 ] );
    if ( sg != NULL )
    {
        String s;
        StringInit( &s, src, len, len );
        if ( StringCopy ( &sg->name, &s ) != 0 )
        {
            free( sg );
            sg = NULL;
        }
    }
    return sg;
}
Exemplo n.º 18
0
/* Make
 */
static
rc_t KDylibMake ( KDylib **libp, const String *path )
{
    KDylib *lib = malloc ( sizeof * lib + path -> size + 1 );
    if ( lib == NULL )
        return RC ( rcFS, rcDylib, rcConstructing, rcMemory, rcExhausted );

    lib -> handle = NULL;
    string_copy ( ( char* ) ( lib + 1 ), path -> size + 1, path -> addr, path -> size );
    StringInit ( & lib -> path, ( char* ) ( lib + 1 ), path -> size, path -> len );
    KRefcountInit ( & lib -> refcount, 1, "KDylib", "make", lib -> path . addr );

    * libp = lib;
    return 0;
}
Exemplo n.º 19
0
CMyString::~CMyString()
{
#ifdef REFCOUNT
    Release();
#else

    if (m_psz)
    {
        delete[] m_psz;
    }

#endif

    StringInit();
}
Exemplo n.º 20
0
CMyString::CMyString(const CMyString &str)
{
    StringInit();

#ifdef REFCOUNT
    //进行浅拷贝
    m_nlen   = str.m_nlen;
    m_nspace = str.m_nspace;
    m_psz    = str.m_psz;

    m_prefcount = str.m_prefcount;
    AddRef();

#else
    SetString(str);
#endif

}
Exemplo n.º 21
0
static rc_t init_ictx( struct ictx * ictx, const dump_context * ctx, const Args * args )
{
    rc_t rc = KFileMakeStdIn ( &( ictx->std_in ) );
    DISP_RC( rc, "KFileMakeStdIn() failed" );
    if ( rc == 0 )
    {
        ictx->ctx = ctx;
        ictx->args = args;
        VectorInit( &ictx->history, 0, 10 );
        ictx->interactive = ( KFileType ( ictx->std_in ) == kfdCharDev );
        ictx->done = false;
        
        CONST_STRING( &(ictx->PROMPT), "\nvdb $" );
        StringInit( &(ictx->SInputLine), &( ictx->inputline[0] ), sizeof( ictx->inputline ), 0 );
        
        rc = vdp_init_ctx( &ictx->vsctx, args );
    }
    return rc;
}
Exemplo n.º 22
0
static rc_t cg_dump_row( cg_dump_opts * opts, cg_dump_ctx * cg_ctx, uint64_t row_id )
{
    uint32_t elem_bits, boff, sg_len;
    const char * sg;
    rc_t rc = VCursorCellDataDirect( cg_ctx->seq_cur, row_id, cg_ctx->seq_sg_idx, &elem_bits, (const void**)&sg, &boff, &sg_len );
    if ( rc != 0 )
    {
        (void)PLOGERR( klogErr, ( klogErr, rc, "cannot read spot-group in row #$(row_id)", "row_id=%lu", row_id ) );
    }
    else
    {
        String spot_group;
        lane * sg_lane;

        StringInit( &spot_group, sg, sg_len, sg_len );
        sg_lane = ( lane * )BSTreeFind ( &cg_ctx->lanes, &spot_group, String_lane_cmp );
        if ( sg_lane == NULL )
        {
            /* KOutMsg( "row %lu (%S) not found, create it\n", row_id, &spot_group ); */
            rc = make_lane( opts, cg_ctx->lookup, cg_ctx->out_dir, &spot_group, &sg_lane );
            if ( rc == 0 )
            {
                rc = BSTreeInsert ( &cg_ctx->lanes, ( BSTNode * )sg_lane, lane_lane_cmp );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot insert new lane" );
                    whack_lane( sg_lane );
                }
            }
        }
        else
        {
            /* KOutMsg( "row %lu (%S) found, use it\n", row_id, &spot_group ); */
        }
        if ( rc == 0 )
        {
            cg_dump_write_spot( opts, cg_ctx, row_id, sg_lane ); /* <================== */
        }
    }
    return rc;
}
Exemplo n.º 23
0
/* Make
 */
static
KThreadEvent * KThreadEventMake ( ctx_t ctx,
    uint32_t lineno, xc_sev_t severity, xc_org_t origin,
    xc_t xc, const char * msg, va_list args )
{
    KThreadEvent * evt;
    KTime_t ts = KTimeStamp ();

    char * c;
    size_t num_writ;
    char msg_buffer [ 4096 ];
    rc_t rc = string_vprintf ( msg_buffer, sizeof msg_buffer, & num_writ, msg, args );
    if ( rc != 0 || num_writ >= sizeof msg_buffer )
        string_printf ( msg_buffer, sizeof msg_buffer, & num_writ, "** BAD MESSAGE STRING **" );

    if ( num_writ > 0 && msg_buffer [ num_writ - 1 ] == '.' )
        msg_buffer [ -- num_writ ] = 0;

    evt = malloc ( sizeof * evt + num_writ + 1 );
    if ( evt == NULL )
    {
        /* ATTEMPT TO DUMP TO LOG */
        KThreadEventDump ( ctx, ts, ctx -> loc, lineno, severity, origin, xc, msg_buffer, NULL );
        exit ( -1 );
    }

    evt -> node = NULL;
    evt -> next = NULL;

    evt -> xc = ( const XCErr * ) xc;
    evt -> timestamp = ts;
    evt -> severity = severity;
    evt -> origin = origin;
    evt -> lineno = lineno;

    c = ( char* ) ( evt + 1 );
    memmove ( c, msg_buffer, num_writ + 1 );
    StringInit ( & evt -> message, c, num_writ, string_len ( c, num_writ ) );

    return evt;
}
Exemplo n.º 24
0
void Init(char *langs, char *dialects, int anamorph)
{
  Starting = 1;
  GenOnAssert = 1;
  LexEntryOff = 0;
  SaveTime = 1;
    /* SaveTime = 1: no spell correction hashing or phrase derivation,
     *               saves memory.
     * SaveTime = 0: uses more time and memory.
     */
  qallocInit();
  DbgInit();
  DbgSet(DBGALL, DBGBAD);
  DbgSetStdoutLevel(DBGOK);
  NoticePrint(stderr);
  NoticePrint(Log);
  EnvInit();
  StringInit();
  RandomInit();
  GridInit();
  ObjInit();
  ObjListInit();
  DbInit();
  ContextInit();
  TsInit();
  TsRangeInit();
  LexEntryInit();
  Lex_WordForm2Init();
  MorphInit(anamorph);
  WordFormInit();
  InferenceInit();
  ReportInit();
  CommentaryInit();
  TranslateInit();
  LearnInit();
  StopAtInit();
  TT_HTML_Init();
  StdDiscourse = DiscourseCreate(langs, dialects);
  DiscourseSetLang(StdDiscourse, F_ENGLISH);
  Starting = 0;
}
Exemplo n.º 25
0
static spotgrp * make_spotgrp( const char *src, const size_t len )
{
    spotgrp * sg = calloc( 1, sizeof sg[ 0 ] );
    if ( sg != NULL )
    {
        String s;
        StringInit( &s, src, len, len );
        if ( StringCopy ( &sg->name, &s ) != 0 )
        {
            free( sg );
            sg = NULL;
        }
#ifdef USE_JUDY
        else
        {
            KVectorMake ( &sg->v );
        }
#endif
    }
    return sg;
}
Exemplo n.º 26
0
static spotgrp * find_spotgroup( statistic *self, const char *src, const size_t len )
{
    String s;
    BSTNode *node;

    StringInit( &s, src, len, len );
    if ( self->last_used_spotgroup != NULL )
    {
        spotgrp * sg = ( spotgrp* )self->last_used_spotgroup;
        if ( StringCompare ( &s, sg->name ) == 0 )
            return sg;
    }

    node = BSTreeFind ( &self->spotgroups, &s, spotgroup_find );
    if ( node == NULL )
        return NULL;
    else
    {
        self->last_used_spotgroup = node;
        return ( spotgrp *) node;
    }
}
Exemplo n.º 27
0
static
bool VTableNameAvail ( const KSymTable *tbl, const char *name )
{
    String str;

    /* build a physical name from simple name */
    char pname [ 256 ];
    int len = snprintf ( pname, sizeof pname, ".%s", name );
    if ( len < 0 || len >= sizeof pname )
        return false;

    /* test for defined physical name */
    StringInit ( & str, pname, len, len );
    if ( KSymTableFind ( tbl, & str ) != NULL )
        return false;

    /* test for defined simple name */
    StringSubstr ( & str, & str, 1, 0 );
    if ( KSymTableFind ( tbl, & str ) != NULL )
        return false;

    /* name is available */
    return true;
}
Exemplo n.º 28
0
int main(void) {
  MainInit();
  I2C1init();
  RtcInit();
  LcdInit();
  DataLogInit();
  StringInit();
  Mct485Init();
  FieldInit();
  Ads1115Init();
  Ads1244Init();
  USBInit();
  RtuInit();
  AdcInit();
  TC74Init();

  // enable multi-vector interrupts
  INTEnableSystemMultiVectoredInt();

  MainDelay(50);
  DataLogDateTime(DLOG_SFC_POWERUP);

  // init param after interrupts are enabled 
  ParamInit();
  // wait to init desiccant until after ParamInit
  DesiccantInit();

  string[0].mct[0].chan[4] = 0x7FFF;



	// 
	// Begin Main Loop
	//
  for (;;) {
    if (test == 1) {
      test = 0;
      FieldNewState((FIELD_STATE_m)t1);
    }
    
    USBUpdate(); // called as often as possible
    
    //sysTickEvent every ms
    if (sysTickEvent) {
      sysTickEvent = 0;
      sysTicks++;

      UsbTimeoutUpdate();

      LcdUpdate();
      
      // fill time before dropping LCD_E
      if (sysTicks >= 1000) {
        sysSec++;
        sysTicks = 0;
        
        mPORTDToggleBits(PD_LED_HEARTBEAT);
        
        // These Updates are 
        // called once a second
        //TODO if any of these are long, we could split them on separate milliseconds.
        DesiccantUpdate();
        AdcUpdate();
        TC74Update();
        
      }// end 1 Hz
      
      else if (sysTicks == 250) {
        mPORTDToggleBits(PD_LED_HEARTBEAT);
      }
      else if (sysTicks == 500) {
        mPORTDToggleBits(PD_LED_HEARTBEAT);
      }
      else if (sysTicks == 750) {
        mPORTDToggleBits(PD_LED_HEARTBEAT);
      }
      // Complete LcdUpdate() by dropping LCD_E)
      PORTClearBits(IOPORT_G, PG_LCD_E);

      // These Updates called once each millisecond
      RtcUpdate();
      I2C1update();
      StringUpdate();
      Mct485Update();
      FieldUpdate();
      RtuUpdate();
      DessicantFanPWMupdate();
      
    } // if (sysTickEvent)
  } // for (;;)
} // main()
Exemplo n.º 29
0
static
void aws_parse_file ( const KFile *self, KConfigNode *aws_node, 
                      char *buffer, size_t buf_size, bool isCredentialsFile )
{
    char *sep;
    const char *start = buffer;
    const char *end = start + buf_size;

    for ( ; start < end; start = sep + 1 )
    {
        rc_t rc;
        String string, trim;
        String key, value;
        
        sep = string_chr ( start, end - start, '\n' );
        if ( sep == NULL )
            sep = ( char * ) end;

        StringInit ( &string, start, sep - start, string_len ( start, sep - start ) );
        
        StringTrim ( &trim, &string );

        /* check for comment line and skip */
        if ( StringLength ( & trim ) != 0 && trim . addr [ 0 ] == '#' )
            continue;

        /* check for key/value pairs and skip if none found */
        rc = aws_extract_key_value_pair ( &trim, &key, &value );
        if ( rc != 0 )
            continue;

        /* now check keys we are looking for and populate the node*/
        if ( isCredentialsFile )
        {
            String access_key_id, secret_access_key;
            CONST_STRING ( &access_key_id, "aws_access_key_id" );
            CONST_STRING ( &secret_access_key, "aws_secret_access_key" );

            if ( StringCaseEqual ( &key, &access_key_id ) )
            {
                rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value );
                if ( rc != 0 )
                    return;
            }
            if ( StringCaseEqual ( &key, &secret_access_key  ) )
            {
                rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value );
                if ( rc != 0 )
                    return;
            }
        }
        else
        {
            String region, output;
            CONST_STRING ( &region, "region" );
            CONST_STRING ( &output, "output" );

            if ( StringCaseEqual ( &key, &region ) )
            {
                rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value );
                if ( rc != 0 )
                    return;
            }
            if ( StringCaseEqual ( &key, &output  ) )
            {
                rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value );
                if ( rc != 0 )
                    return;
            }
        }
    }
}
Exemplo n.º 30
0
rc_t ascpParse(const char *buf, size_t len, const char *filename,
    EAscpState *state, String *line)
{
    bool failure = false;
    const char *p = buf;
    int64_t l = len;
    assert(buf && len && filename && state && line);
    StringInit(line, NULL, 0, 0);
    while (true) {
        const char *n = string_chr(p, l, '\n');
        const char *r = string_chr(p, l, '\r');
        if (n == NULL) {
            if (r != NULL) {
                n = r;
            }
        }
        else {
            if (r != NULL) {
                if (r < n) {
                    n = r;
                }
            }
        }
        if (n != NULL) {
            StringInit(line, p, n - p, (uint32_t)(n - p));
            l -= n - p + 1;
        }
        else {
            StringInit(line, p, l, (uint32_t)l);
        }
        if (line->addr && line->len && line->addr[line->len - 1] == '\r') {
            line->size = line->len - 1;
            line->len = line->len - 1;
        }
        if (line->addr && line->len && line->addr[0] == '\r') {
            ++line->addr;
            line->size = line->len - 1;
            line->len = line->len - 1;
        }
        if (line->len != 0) {
            SAscpState full;
            rc_t rc = parseAscpLine(line, &full, filename);
            if (rc != 0) {
                return rc;
            }
            switch (full.s) {
                case eChild:
                    break;
                case eUnknown:
                    switch (*state) {
                        case eKeyStart:
                        case eKeyMayBeIn:
                        case eKeyIn:
                            *state = eKeyMayBeIn;
                            break;
                        case eCompleted:
                        case eFailed:
                        case eWriteFailed:
                            *state = eEnd;
                            /* report to user */
                            break;
                        case eProgress:
                            if (sStatus) {
                                OUTMSG(("\n"));
                            }
/*                          no break; */
                        default:
                            *state = eUnknown;
                            /* report to user */
                            break;
                    }
                    break;
                case eFailed:
                    if (*state == eProgress) {
                        if (sStatus) {
                            OUTMSG(("\n"));
                        }
                    }
                    failure = true;
                    *state = full.s;
                    if (sStatus) {
                        OUTMSG(("%s\n", full.msg));
                    }
/*                  no break; */
                    break;
                case eWriteFailed:
                    if (*state == eProgress) {
                        if (sStatus) {
                            OUTMSG(("\n"));
                        }
                    }
                    failure = true;
                    *state = full.s;
                    if (sStatus) {
                        OUTMSG(("%s\n", full.msg));
                    }
/*                  no break; */
                    break;
                case eCompleted:
                    if (*state == eProgress) {
                        if (sStatus) {
                            OUTMSG(("\n"));
                        }
                    }
                    failure = false;
                    *state = full.s;
                    if (sStatus) {
                        OUTMSG(("%s\n", full.msg));
                    }
/*                  no break; */
                    break;
                case eProgress:
                    if (*state == eProgress) {
                        if (sStatus) {
                            OUTMSG(("\r"));
                        }
                    }
                    *state = full.s;
                    if (sStatus) {
                        OUTMSG(("%s", full.msg));
                    }
                    break;
                case eEnd:
                    if (*state == eProgress) {
                        if (sStatus) {
                            OUTMSG(("\n"));
                        }
                    }
                    *state = full.s;
                    if (sStatus) {
                        OUTMSG(("%s\n", full.msg));
                    }
                    /* report to user */
                    break;
                default:
                    *state = full.s;
                    break;
            }
            SAscpStateFini(&full);
        }
        if (n == NULL || l <= 0) {
            break;
        }
        if (*state == eKeyEnd) {
            String end;
            if (_StringHas(line, "Store key in cache? (y/n) ", &end)) {
                if (n > end.addr + end.len) {
                    l += n - end.addr + end.len;
                    n = end.addr + end.len - 1;
                }
            }
        }
        p = n + 1;
        if (p >= buf + len) {
            break;
        }
    }
    if (sStatus) {
        STSMSG(STS_FIN, ("%.*s", len, buf));
    }
    if (failure) {
        /* ignore it */
    }
    return 0;
}