Exemple #1
0
  bool RosterManager::handleIq( Stanza *stanza )
  {
    if( stanza->subtype() == StanzaIqResult ) // initial roster
    {
      extractItems( stanza, false );

      if( m_rosterListener )
        m_rosterListener->handleRoster( m_roster );

      m_parent->rosterFilled();

      return true;
    }
    else if( stanza->subtype() == StanzaIqSet ) // roster item push
    {
      extractItems( stanza, true );

      Tag *iq = new Tag( "iq" );
      iq->addAttribute( "id", stanza->id() );
      iq->addAttribute( "type", "result" );
      m_parent->send( iq );

      return true;
    }
    else if( stanza->subtype() == StanzaIqError )
    {
      if( m_rosterListener )
        m_rosterListener->handleRosterError( stanza );
    }

    return false;
  }
Exemple #2
0
void
Package::extractItems(const char *filesPath, const Package &listPkg, char outType) {
    const Item *pItem;
    int32_t i;

    for(pItem=listPkg.items, i=0; i<listPkg.itemCount; ++pItem, ++i) {
        extractItems(filesPath, pItem->name, outType);
    }
}
Exemple #3
0
SPREADSHEET *SS_ReadCSV(char *fileName) {
    char line[MAXINPUTLINELEN];
    char *tempRow[MAXITEMSPERROW];
    SPREADSHEET *result;
    struct OneRow *lastRow = NULL;
    int i;

	result = malloc(sizeof(SPREADSHEET));
	CHECKMALLOC(result);
    result->fileName = mystrdup(fileName);
    result->firstRow = NULL;
    result->numRows = result->numCols = 0;

    FILE *f = fopen(fileName, "r");
    if (f == NULL) {
        fprintf(stderr, "Unable to read from file %s\n", fileName);
        perror(fileName);
        return NULL;
    }
    for( i = 0; ; i++) {
        if (fgets(line, MAXINPUTLINELEN, f) == NULL)
            break;
        int k = extractItems(line, tempRow);
        if (result->numCols == 0) {
            result->numCols = k;
        } else
        if (result->numCols != k) {
            fprintf(stderr, "Row %d has different number of columns from first row\n", i);
            continue;	// ignore this row
        }

        // instantiate the storage for the new row and copy k cells into it
        char **rc = calloc(k, sizeof(char *));
        CHECKMALLOC(rc);
        struct OneRow *newrow = malloc(sizeof(struct OneRow));
        CHECKMALLOC(newrow);
        newrow->row = rc;
        newrow->nextRow = NULL;
        int ix;
        for( ix = 0; ix < k; ix++ ) {
            rc[ix] = tempRow[ix];
        }
        
        // add the new row as the last row in the spreadsheet
        if (lastRow == NULL) {
            result->firstRow = newrow;
        } else {
            lastRow->nextRow = newrow;
        }
        lastRow = newrow;

    }
    result->numRows = i;
    fclose(f);
    return result;
}