~zorba-coders/zorba/1188033

« back to all changes in this revision

Viewing changes to src/archive_module.xq.src/archive_module.cpp

  • Committer: Luis Rodriguez Gonzalez
  • Date: 2013-07-25 21:36:20 UTC
  • Revision ID: kuraru@gmail.com-20130725213620-n7lcvt955jf1kqar
All comments fixed

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#define ERROR_CORRUPTED_ARCHIVE "CORRUPTED-ARCHIVE"
53
53
#define ERROR_DIFFERENT_COMPRESSIONS_NOT_SUPPORTED "DIFFERENT-COMPRESSIONS-NOT-SUPPORTED"
54
54
 
 
55
#define FORMAT_KEY_NAME "format"
 
56
#define COMPRESSION_KEY_NAME "compression"
 
57
#define NAME_KEY_NAME "name"
 
58
#define TYPE_KEY_NAME "type"
 
59
#define SIZE_KEY_NAME "size"
 
60
#define LAST_MODIFIED_KEY_NAME "last-modified"
 
61
#define ENCODING_KEY_NAME "encoding"
 
62
 
55
63
namespace zorba { namespace archive {
56
64
 
57
65
 
157
165
    }
158
166
  }
159
167
 
160
 
 
161
168
/*******************************************************************************
162
169
 ****************************** ArchiveFunction ********************************
163
170
 ******************************************************************************/
227
234
        Item lKeyValue;
228
235
        lKeyValue = aEntry.getObjectValue(lKey.getStringValue());
229
236
 
230
 
        if(lKey.getStringValue() == "name")
 
237
        if(lKey.getStringValue() == NAME_KEY_NAME)
231
238
        {
232
239
          theEntryPath = lKeyValue.getStringValue();
233
240
        }
234
 
        else if(lKey.getStringValue() == "type")
 
241
        else if(lKey.getStringValue() == TYPE_KEY_NAME)
235
242
        {
236
243
          String filetype = lKeyValue.getStringValue();
237
244
          if(filetype == "directory")
239
246
            theEntryType = directory;
240
247
          }
241
248
        }
242
 
        else if (lKey.getStringValue() == "last-modified")
 
249
        else if (lKey.getStringValue() == LAST_MODIFIED_KEY_NAME)
243
250
        {
244
251
          ArchiveModule::parseDateTimeItem(lKeyValue, theLastModified);
245
252
        }
246
 
        else if (lKey.getStringValue() == "encoding")
 
253
        else if (lKey.getStringValue() == ENCODING_KEY_NAME)
247
254
        {
248
255
          theEncoding = lKeyValue.getStringValue();
249
256
          std::transform(
257
264
            throwError(ERROR_INVALID_ENCODING, lMsg.str().c_str());
258
265
          }
259
266
        }
260
 
        else if (lKey.getStringValue() == "compression")
 
267
        else if (lKey.getStringValue() == COMPRESSION_KEY_NAME)
261
268
        {
262
269
          theCompression = lKeyValue.getStringValue();
263
270
          std::transform(
302
309
        Item lOptionValue;
303
310
        lOptionValue = aOptions.getObjectValue(lOptionKey.getStringValue());
304
311
 
305
 
        if (lOptionKey.getStringValue() == "compression")
 
312
        if (lOptionKey.getStringValue() == COMPRESSION_KEY_NAME)
306
313
        {
307
314
          theCompression = lOptionValue.getStringValue().c_str();
308
315
          std::transform(
310
317
              theCompression.end(),
311
318
              theCompression.begin(), ::toupper);
312
319
        }
313
 
        else if (lOptionKey.getStringValue() == "format")
 
320
        else if (lOptionKey.getStringValue() == FORMAT_KEY_NAME)
314
321
        {
315
322
          theFormat = lOptionValue.getStringValue().c_str();
316
323
          std::transform(
335
342
        }
336
343
      }
337
344
      if (theFormat == "TAR")
338
 
      {
339
 
        if (theCompression != "GZIP"
 
345
      {        if (theCompression != "GZIP"
340
346
#ifndef WIN32
341
347
            && theCompression != "BZIP2"
342
348
            && theCompression != "LZMA"
1050
1056
      zorba::Item& aArchive)
1051
1057
    : ArchiveIterator(aArchive)
1052
1058
  {
 
1059
      gNameKey = theFactory->createString(NAME_KEY_NAME);
 
1060
      gTypeKey = theFactory->createString(TYPE_KEY_NAME);
 
1061
      gSizeKey = theFactory->createString(SIZE_KEY_NAME);
 
1062
      gLastModifiedKey = theFactory->createString(LAST_MODIFIED_KEY_NAME);
1053
1063
  }
1054
1064
 
1055
1065
  bool
1069
1079
    std::vector<std::pair<zorba::Item, zorba::Item> > lObjectArray;
1070
1080
    std::pair<zorba::Item, zorba::Item> lElemPair;
1071
1081
 
1072
 
    //Item lMemberName;
1073
 
 
1074
1082
    // create text content (i.e. path name)
1075
1083
    String lName = archive_entry_pathname(lEntry);
1076
 
    //Item lNameItem = theFactory->createString(lName);
1077
 
    //lMemberName = theFactory->createString("name");
1078
 
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(theFactory->createString("name"),
 
1084
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(gNameKey,
1079
1085
                                                         theFactory->createString(lName));
1080
1086
    lObjectArray.push_back(lElemPair);
1081
1087
 
1083
1089
    if (archive_entry_size_is_set(lEntry))
1084
1090
    {
1085
1091
      long long lSize = archive_entry_size(lEntry);
1086
 
      //Item lSizeItem = theFactory->createInteger(lSize);
1087
 
      //lMemberName = theFactory->createString("size");
1088
 
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(theFactory->createString("size"),
 
1092
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(gSizeKey,
1089
1093
                                                           theFactory->createInteger(lSize));
1090
1094
      lObjectArray.push_back(lElemPair);
1091
1095
    }
1094
1098
    if (archive_entry_mtime_is_set(lEntry))
1095
1099
    {
1096
1100
      time_t lTime = archive_entry_mtime(lEntry);
1097
 
      //Item lModifiedItem = ArchiveModule::createDateTimeItem(lTime);
1098
 
      //lMemberName = theFactory->createString("last-modified");
1099
 
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(theFactory->createString("last-modified"),
 
1101
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(gLastModifiedKey,
1100
1102
                                                           ArchiveModule::createDateTimeItem(lTime));
1101
1103
      lObjectArray.push_back(lElemPair);
1102
1104
    }
1118
1120
    }
1119
1121
 
1120
1122
    //lMemberName = theFactory->createString("type");
1121
 
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(theFactory->createString("type"),
 
1123
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(gTypeKey,
1122
1124
                                                         theFactory->createString(lEntryType));
1123
1125
    lObjectArray.push_back(lElemPair);
1124
1126
 
1369
1371
    return ItemSequence_t(new OptionsItemSequence(lArchive));
1370
1372
  }
1371
1373
 
 
1374
  OptionsFunction::OptionsItemSequence::OptionsIterator::OptionsIterator(Item &aArchive)
 
1375
      :ArchiveIterator(aArchive)
 
1376
  {
 
1377
      gFormatKey = theFactory->createString(FORMAT_KEY_NAME);
 
1378
      gCompressionKey = theFactory->createString(COMPRESSION_KEY_NAME);
 
1379
  }
 
1380
 
1372
1381
  bool
1373
1382
  OptionsFunction::OptionsItemSequence::OptionsIterator::next(
1374
1383
      zorba::Item& aRes)
1400
1409
      lCompression = "DEFLATE";
1401
1410
    }
1402
1411
 
1403
 
    lElemt = std::make_pair<zorba::Item, zorba::Item>(theFactory->createString("format"),
 
1412
    lElemt = std::make_pair<zorba::Item, zorba::Item>(gFormatKey,
1404
1413
                                                      theFactory->createString(lFormat));
1405
1414
    lJSONObject.push_back(lElemt);
1406
1415
 
1407
 
    lElemt = std::make_pair<zorba::Item, zorba::Item>(theFactory->createString("compression"),
 
1416
    lElemt = std::make_pair<zorba::Item, zorba::Item>(gCompressionKey,
1408
1417
                                                      theFactory->createString(lCompression));
1409
1418
    lJSONObject.push_back(lElemt);
1410
1419
 
1638
1647
    }
1639
1648
    // else? if the entry represents a directory what are we
1640
1649
    // going to return??
 
1650
    // answer: nothing, the directory will have no contents at all
1641
1651
 
1642
1652
    return true;
1643
1653
  }