summaryrefslogtreecommitdiff
path: root/camlibs/lumix/lumix.c
blob: e8591715d650cd56aa3acaeacbf9c1492f9dd48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
/** \file lumix.c
 *
 * \author Copyright 2019 Robert Hasson <robert_hasson@yahoo.com>
 * \author Copyright 2019 Marcus Meissner <marcus@jet.franken.de>
 *
 * \par
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * \par
 * This library is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details. 
 *
 * \par
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 *
 */
#include "config.h"

#include <string.h>
#include <errno.h>
#include <curl/curl.h>
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/xmlreader.h>


#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>


#include <gphoto2/gphoto2-library.h>
#include <gphoto2/gphoto2-result.h>


#define GP_MODULE "lumix"

#define CHECK(result)                                   \
{                                                       \
	int res = (result);                             \
	\
	if (res < 0) {                                  \
		gp_log (GP_LOG_DEBUG, "lumix", "Operation failed in %s (%i)!", __FUNCTION__, res);     \
		return (res); 	\
	}                      	\
}


#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
/**
* This define is the string translation macro used in
* libgphoto2. It will resolve to a dcgettext() function call and
* does both the translation itself and also marks up the string
* for the collector (xgettext).
*/
#  define _(String) dgettext (GETTEXT_PACKAGE, String)
#  ifdef gettext_noop
/**
* This is the noop translation macro, which does not translate the
* string, but marks it up for the extraction of translatable strings.
*/
#    define N_(String) gettext_noop (String)
#  else
#    define N_(String) (String)
#  endif
#else
#  define _(String) (String)
#  define N_(String) (String)
#endif

char* SHUTTERSTART  = "cam.cgi?mode=camcmd&value=capture";
char* SHUTTERSTOP = "cam.cgi?mode=camcmd&value=capture_cancel";
char* CDS_Control  = ":60606/Server0/CDS_control";
int ReadoutMode = 2; // this should be picked up from the settings.... 0-> JPG; 1->RAW; 2 -> Thumbnails
char* cameraShutterSpeed = "B"; // //placeholder to store the value of the shutterspeed set in camera; "B" is for bulb.
int captureDuration = 10; //placeholder to store the value of the bulb shot this should be taken as input. note that my primary goal is in fact to perform bulb captures. but this should be extended for sure to take Shutter Speed capture as set in camera 

static int NumberPix(Camera *camera);
static char* loadCmd (Camera *camera,char* cmd);
static char* switchToRecMode(Camera *camera);
static char* switchToPlayMode(Camera *camera);

typedef struct {
	char   *data;
	size_t 	size;
} LumixMemoryBuffer;

typedef struct {
	char	*id;
	char	*url_raw;
	char	*url_movie;
	char	*url_large;
	char	*url_medium;
	char	*url_thumb;
} LumixPicture;

struct _CameraPrivateLibrary {
	/* all private data */

	int		numpics;
	LumixPicture	*pics;

	int		liveview;
	int		udpsocket;
};


static int
camera_exit (Camera *camera, GPContext *context) 
{
	if (camera->pl->udpsocket > 0) {
		close (camera->pl->udpsocket);
		camera->pl->udpsocket = 0;
	}
	return GP_OK;
}

static int
camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
{
	int			valread;
	struct sockaddr_in	serv_addr;
	unsigned char		buffer[65536];
	GPPortInfo      	info;
	char			*xpath;
	int			i, start, end, tries;

	switchToRecMode (camera);

	if (!camera->pl->liveview) {
		loadCmd(camera,"cam.cgi?mode=startstream&value=49199");
		camera->pl->liveview = 1;
		if (camera->pl->udpsocket <= 0) {
			if ((camera->pl->udpsocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
				GP_LOG_E("\n Socket creation error \n");
				return GP_ERROR;
			}

			gp_port_get_info (camera->port, &info);
			gp_port_info_get_path (info, &xpath); /* xpath now contains tcp:192.168.1.1 */

			memset(&serv_addr, 0, sizeof(serv_addr));

			serv_addr.sin_family = AF_INET;
			serv_addr.sin_port = htons(49199);
			serv_addr.sin_addr.s_addr = 0;

			if (bind(camera->pl->udpsocket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
				GP_LOG_E("bind Failed: %d", errno);
				return GP_ERROR;
			}
		}
	} else {
		/* this reminds the camera we are still doing it */
		loadCmd(camera,"cam.cgi?mode=getstate");
	}
	tries = 3;
	while (tries--) {
		valread = recv ( camera->pl->udpsocket, buffer, sizeof(buffer), 0);
		if (valread == -1) {
			GP_LOG_E("recv failed: %d", errno);
			return GP_ERROR;
		}

		GP_LOG_DATA((char*)buffer,valread,"read from udp port");

		if (valread == 0)
			continue;

		start = end = -1;
		for (i = 0; i<valread-1; i++) {
			if ((buffer[i] == 0xff) && (buffer[i+1] == 0xd8)) {
				start = i;
			}
			if ((buffer[i] == 0xff) && (buffer[i+1] == 0xd9)) {
				end = i+2;
			}
		}
		//GP_LOG_DATA(buffer+start,end-start,"read from udp port");
		gp_file_set_mime_type (file, GP_MIME_JPEG);
		return gp_file_append (file, (char*)buffer+start, end-start);
	}
	return GP_ERROR;
}

static int camera_about (Camera *camera, CameraText *about, GPContext *context);


/**
 * Put a file onto the camera.
 *
 * This function is a CameraFilesystem method.
 */
int
put_file_func (CameraFilesystem *fs, const char *folder, const char *name,
	       CameraFileType type, CameraFile *file, void *data, GPContext *context);
int
put_file_func (CameraFilesystem *fs, const char *folder, const char *name,
	       CameraFileType type, CameraFile *file, void *data, GPContext *context)
{
	/*Camera *camera = data;*/

	/*
	 * Upload the file to the camera. Use gp_file_get_data_and_size, etc
	 */

	return GP_OK;
}


/**
 * Delete a file from the camera.
 *
 * This function is a CameraFilesystem method.
 */
int
delete_file_func (CameraFilesystem *fs, const char *folder,
		  const char *filename, void *data, GPContext *context);
int
delete_file_func (CameraFilesystem *fs, const char *folder,
		  const char *filename, void *data, GPContext *context)
{
	/*Camera *camera = data;*/

	/* Delete the file from the camera. */

	return GP_OK;
}


/**
 * Delete all files from the camera.
 *
 * This function is a CameraFilesystem method.
 */
int
delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
		 GPContext *context);
int
delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
		 GPContext *context)
{
	/*Camera *camera = data;*/

	/*
	 * Delete all files in the given folder. If your camera doesn't have
	 * such a functionality, just don't implement this function.
	 */

	return GP_OK;
}


/**
 * Get the file info here and write it to space provided by caller.
 * 
 * \param info Space provided by caller in which file info is written.
 *
 * This function is a CameraFilesystem method.
 */
int
get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
	       CameraFileInfo *info, void *data, GPContext *context);
int
get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
	       CameraFileInfo *info, void *data, GPContext *context)
{
	/*Camera *camera = data;*/

	return GP_OK;
}


static int
set_info_func (CameraFilesystem *fs, const char *folder, const char *file,
	       CameraFileInfo info, void *data, GPContext *context)
{
	/*Camera *camera = data;*/

	/* Set the file info here from <info> */

	return GP_OK;
}


static int
folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		  void *data, GPContext *context)
{
	/*Camera *camera = data;*/
	/* currently no folders exposed */
	return GP_OK;
}


/**
 * List available files in the specified folder.
 *
 * This function is a CameraFilesystem method.
 */
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	Camera *camera = data;
	int	i;

	for (i=0;i<camera->pl->numpics;i++) {
		if (camera->pl->pics[i].url_raw) {
			char	*s = strrchr(camera->pl->pics[i].url_raw, '/')+1;
			gp_list_append (list, s, NULL);
			continue;
		}
		if (camera->pl->pics[i].url_large) {
			char	*s = strrchr(camera->pl->pics[i].url_large, '/')+1;
			gp_list_append (list, s, NULL);
			continue;
		}
		if (camera->pl->pics[i].url_movie) {
			char	*s = strrchr(camera->pl->pics[i].url_movie, '/')+1;
			gp_list_append (list, s, NULL);
			continue;
		}
	}
	return GP_OK;
}

/**
 * Get information on all available storages in the camera.
 *
 * This function is a CameraFilesystem method.
 */
int
storage_info_func (CameraFilesystem *fs,
		CameraStorageInformation **storageinformations,
		int *nrofstorageinformations, void *data,
		GPContext *context);
int
storage_info_func (CameraFilesystem *fs,
		CameraStorageInformation **storageinformations,
		int *nrofstorageinformations, void *data,
		GPContext *context) 
{
	/*Camera *camera = data;*/

	/* List your storages here */

	return GP_ERROR_NOT_SUPPORTED;
}

/*@}*/


/**********************************************************************/
/**
 * @name camlib API functions
 *
 * @{
 */
/**********************************************************************/


int
camera_id (CameraText *id) 
{
	strcpy(id->text, "Lumix Wifi");

	return GP_OK;
}

static size_t
write_callback(char *contents, size_t size, size_t nmemb, void *userp)
{
	size_t 			realsize = size * nmemb;
	size_t 			oldsize;
	LumixMemoryBuffer	*lmb = userp;

	oldsize = lmb->size;
	/* 1 additionaly byte for 0x00 */
	lmb->data = realloc(lmb->data, lmb->size+realsize+1);
	lmb->size += realsize;
	lmb->data[lmb->size] = 0x00;

	GP_LOG_DATA(contents, realsize, "lumix read from url");

	memcpy(lmb->data+oldsize,contents,realsize);
	return realsize;
}


static char*
loadCmd (Camera *camera,char* cmd) {
	CURL		*curl;
	CURLcode	res;
	char		URL[100];
	GPPortInfo      info;
	char		*xpath;
	LumixMemoryBuffer	lmb;

	curl = curl_easy_init();
	gp_port_get_info (camera->port, &info);
	gp_port_info_get_path (info, &xpath); /* xpath now contains tcp:192.168.1.1 */
	snprintf( URL,100, "http://%s/%s", xpath+4, cmd);
	GP_LOG_D("cam url is %s", URL);

	curl_easy_setopt(curl, CURLOPT_URL, URL);

	lmb.size = 0;
	lmb.data = malloc(0);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &lmb);

	res = curl_easy_perform(curl);
	if(res != CURLE_OK) {
		fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
		return NULL;
	} else {
		/* read the XML that is now in Buffer*/ 
		GP_LOG_D("result %s\n", lmb.data);

		/* <?xml version="1.0" encoding="UTF-8"?> <camrply><result>ok</result></camrply> */
	}
	curl_easy_cleanup(curl);
	return lmb.data;
}

static char*
switchToRecMode(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=camcmd&value=recmode");
}

static char*
switchToPlayMode(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=camcmd&value=playmode");
}


static void Set_ISO(Camera *camera,const char * ISOValue) {
	char buf[200];
	sprintf(buf, "?mode=setsetting&type=iso&value=%s",ISOValue);
	loadCmd(camera,buf);
}

static char*
Get_Clock(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=clock");
}

static char*
Get_ISO(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=iso");
}

static char*
Get_ShutterSpeed(Camera *camera) {
	char	*result, *s;
	char	shutterspeed[20];

	result = loadCmd(camera,"cam.cgi?mode=getsetting&type=shtrspeed");
	/*<?xml version="1.0" encoding="UTF-8"?>
	 * <camrply><result>ok</result><settingvalue shtrspeed="2560/256"></settingvalue></camrply>
	 */
	if (!strstr(result,"<result>ok</result>"))
		return NULL;

	s = strstr(result, "<settingvalue shtrspeed=");
	if (!s) return NULL;
	if (sscanf(s,"<settingvalue shtrspeed=\"%s\">", shutterspeed) != 1)
		return NULL;
	return strdup(shutterspeed);
}

static char*
Get_Aperture(Camera *camera) {
	char	aperture[20];
	char	*result, *s;

	/* <?xml version="1.0" encoding="UTF-8"?>
	 * <camrply><result>ok</result><settingvalue focal="1366/256"></settingvalue></camrply>
	 */
	result = loadCmd(camera,"cam.cgi?mode=getsetting&type=focal");
	if (!strstr(result,"<result>ok</result>"))
		return NULL;
	s = strstr(result, "<settingvalue focal=");
	if (!s) return NULL;
	if (sscanf(s,"<settingvalue focal=\"%s\">", aperture) != 2)
		return NULL;
	return strdup(aperture);
}

static char*
Get_AFMode(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=afmode");
}

static char*
Get_FocusMode(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=focusmode");
}

static char*
Get_MFAssist(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=mf_asst");
}

static char*
Get_MFAssist_Mag(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=mf_asst_mag");
}

static char*
Get_ExTeleConv(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=ex_tele_conv");
}

static char*
Get_Capability(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getinfo&type=capability");
}

static char*
Get_Lens(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getinfo&type=lens");
}

static char*
Get_AllMenu(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getinfo&type=allmenu");
}

static char*
Get_CurMenu(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getinfo&type=curmenu");
}


static void Set_ShutterSpeed(Camera *camera,const char* SpeedValue) {
	char buf[200];
	sprintf(buf, "?mode=setsetting&type=shtrspeed&value=%s",SpeedValue);
	loadCmd(camera,buf);
}

static char*
Get_Quality(Camera *camera) {
	return loadCmd(camera,"cam.cgi?mode=getsetting&type=quality");
}

static void
Set_quality(Camera *camera,const char* Quality) {
	char buf[200];
	sprintf(buf,"cam.cgi?mode=setsetting&type=quality&value=%s", Quality);
	loadCmd(camera,buf);
}


static int
startCapture(Camera *camera) {
	char *result;

	result = loadCmd(camera,"cam.cgi?mode=camcmd&value=capture");

	if (strstr(result,"<result>ok</result>")) return GP_OK;
	if (strstr(result,"<result>err_busy</result>")) return GP_ERROR_CAMERA_BUSY;
	return GP_ERROR;
}

static int
stopCapture(Camera *camera) {
	char	*result;

	result = loadCmd(camera,"cam.cgi?mode=camcmd&value=capture_cancel");

	if (strstr(result,"<result>ok</result>")) return GP_OK;
	if (strstr(result,"<result>err_busy</result>")) return GP_ERROR_CAMERA_BUSY;
	return GP_ERROR;
}

static void startMovie(Camera *camera) {
	loadCmd(camera,"cam.cgi?mode=camcmd&value=video_recstart");
}

static void stopMovie(Camera *camera) {
	loadCmd(camera,"cam.cgi?mode=camcmd&value=video_recstop");
}

static void zoomIn(Camera *camera) {
	loadCmd(camera,"cam.cgi?mode=camcmd&value=tele-fast");
}

static void zoomOut(Camera *camera) {
	loadCmd(camera,"cam.cgi?mode=camcmd&value=wide-fast");
}

static void zoomStop(Camera *camera) {
	loadCmd(camera,"cam.cgi?mode=camcmd&value=zoomstop");
}

static void focusIn(Camera *camera) {
	loadCmd(camera,"cam.cgi?mode=camctrl&type=focus&value=tele-fast");
}

static void focusOut(Camera *camera) {
	loadCmd(camera,"cam.cgi?mode=camctrl&type=focus&value=wide-fast");
}

/*

this is the XML sample to be parsed by the function below   NumberPix() 
<?xml version="1.0" encoding="UTF-8"?>
<camrply><result>ok</result><current_position>341</current_position><total_content_number>372</total_content_number><content_number>342</content_number></camrply>


*/
static int
strend(const char *s, const char *t)
{
    size_t ls = strlen(s); // find length of s
    size_t lt = strlen(t); // find length of t
    if (ls >= lt)  // check if t can fit in s
    {
        // point s to where t should start and compare the strings from there
        return (0 == memcmp(t, s + (ls - lt), lt));
    }
    return 0; // t was longer than s
}

static int
NumberPix(Camera *camera) {
	xmlChar		*keyz = NULL;
	int		numpics = 0;
	char		*temp = loadCmd(camera,"cam.cgi?mode=get_content_info");
	xmlDocPtr	doc = xmlParseDoc((unsigned char*) temp);
	xmlNodePtr	cur = NULL; 

	cur = xmlDocGetRootElement(doc);   
	/*GP_LOG_D("NumberPix Decode current root node is %s \n", doc); */

	if (cur == NULL) {
		GP_LOG_E("empty xml result document");
		xmlFreeDoc(doc);
		return GP_ERROR;
	}
	/*
	 * busy mode:
	 <?xml version="1.0" encoding="UTF-8"?> <camrply><result>err_busy</result></camrply>

	 * regular return:
	 <?xml version="1.0" encoding="UTF-8"?>
	 <camrply><result>ok</result><current_position>2</current_position><total_content_number>651</total_content_number><content_number>651</content_number></camrply>
	 */
	if (strstr(temp, "<result>err_busy</result>")) {
		xmlFreeDoc(doc);
		return GP_ERROR_CAMERA_BUSY;
	}

	cur = cur->xmlChildrenNode;
	while (cur != NULL) {
		/*GP_LOG_D("NumberPix Decode current node is %s \n", (char*)cur);*/
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"content_number"))) {
			keyz = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
			break;
		}
		cur = cur->next;
	}
	if (!keyz) {
		xmlFreeDoc(doc);
		return GP_ERROR;
	}
	GP_LOG_D("NumberPix Found is %s", (char *) keyz);
	numpics = strtol((char*)keyz, NULL, 10);

	xmlFreeDoc(doc);
	return numpics;
}

/*utility function to creat a SOAP envelope for the lumix cam */  
static char*
SoapEnvelop(int start, int num){
	static char  Envelop[1000];
	snprintf(Envelop,1000, "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"xmlns:pana=\"urn:schemas-panasonic-com:pana\"><ObjectID>0</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>*</Filter><StartingIndex>%d</StartingIndex><RequestedCount>%d</RequestedCount><SortCriteria></SortCriteria><pana:X_FromCP>LumixLink2.0</pana:X_FromCP></u:Browse></s:Body></s:Envelope>",start,num);

	return Envelop;
}

static int
traverse_tree (int depth, xmlNodePtr node)
{
        xmlNodePtr      next;
        xmlChar         *xchar;
        int             n;
        char            *xx;


        if (!node) return 0;
        xx = malloc (depth * 4 + 1);
        memset (xx, ' ', depth*4);
        xx[depth*4] = 0;

        n = xmlChildElementCount (node);

        next = node;
        do {
                fprintf(stderr,"%snode %s\n", xx,next->name);
                fprintf(stderr,"%selements %d\n", xx,n);
                xchar = xmlNodeGetContent (next);
                fprintf(stderr,"%scontent %s\n", xx,xchar);
                traverse_tree (depth+1,xmlFirstElementChild (next));
        } while ((next = xmlNextElementSibling (next)));
        free (xx);
        return 1;
}


/*
 * retrieves the XML doc with the last num pictures avail in the camera.
 */

static char*
GetPixRange(Camera *camera, int start, int num) {
	long		NumPix;
	int		numreadint;
        xmlDocPtr       docin, docin2;
        xmlNodePtr      docroot, docroot2, output, output2, next;
	xmlChar 	*xchar, *numread;
	char*		SoapMsg;
	CURL 		*curl;
	CURLcode	res;
	struct curl_slist *list = NULL;
	GPPortInfo      info;
	char		*xpath;
	LumixMemoryBuffer	lmb;
	char		URL[1000];

	switchToPlayMode (camera);
	NumPix  = NumberPix(camera);
	//GP_LOG_D("NumPix is %d \n", NumPix);
	if (NumPix < GP_OK) return NULL;

	if (camera->pl->numpics < NumPix) {
		camera->pl->pics = realloc(camera->pl->pics,NumPix * sizeof(camera->pl->pics[0]));
		memset(camera->pl->pics+camera->pl->numpics, 0, NumPix * sizeof(camera->pl->pics[0]));
		camera->pl->numpics = NumPix;
	}

	while (num > 0) {
		SoapMsg = SoapEnvelop(start, num);
		//GP_LOG_D("SoapMsg is %s \n", SoapMsg);

		curl = curl_easy_init();

		list = curl_slist_append(list, "SOAPaction: urn:schemas-upnp-org:service:ContentDirectory:1#Browse");
		list = curl_slist_append(list, "Content-Type: text/xml; charset=\"utf-8\"");
		list = curl_slist_append(list, "Accept: text/xml");

		gp_port_get_info (camera->port, &info);
		gp_port_info_get_path (info, &xpath); /* xpath now contains tcp:192.168.1.1 */
		snprintf( URL, 1000, "http://%s%s",xpath+4, CDS_Control);
		curl_easy_setopt(curl, CURLOPT_URL, URL);

		lmb.size = 0;
		lmb.data = malloc(0);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &lmb);

		curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
		curl_easy_setopt(curl, CURLOPT_POST,1);
		curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(SoapMsg));

		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, SoapMsg);

		GP_LOG_D("camera url is %s", URL);
		GP_LOG_D("posting %s", SoapMsg);

		res = curl_easy_perform(curl);
		if(res != CURLE_OK) {
			fprintf(stderr, "curl_easy_perform() failed: %s\n",
			curl_easy_strerror(res));
			curl_easy_cleanup(curl);
			return NULL;
		}
		curl_easy_cleanup(curl);

		docin = xmlReadMemory (lmb.data, lmb.size, "http://gphoto.org/", "utf-8", 0);
		if (!docin) return NULL;
		docroot = xmlDocGetRootElement (docin);
		if (!docroot) {
			xmlFreeDoc (docin);
			return NULL;
		}
		if (strcmp((char*)docroot->name,"Envelope")) {
			GP_LOG_E("root node is '%s', expected 'Envelope'", docroot->name);
			xmlFreeDoc (docin);
			return NULL;
		}
		output = xmlFirstElementChild (docroot);
		if (strcmp((char*)output->name,"Body")) {
			GP_LOG_E("second level node is %s, expected Body", docroot->name);
			xmlFreeDoc (docin);
			return NULL;
		}
		output = xmlFirstElementChild (output);
		if (strcmp((char*)output->name,"BrowseResponse")) {
			GP_LOG_E("third level node is %s, expected BrowseResponse", docroot->name);
			xmlFreeDoc (docin);
			return NULL;
		}
		output = xmlFirstElementChild (output);
		if (strcmp((char*)output->name,"Result")) {
			GP_LOG_E("fourth level node is %s, expected Result", docroot->name);
			xmlFreeDoc (docin);
			return NULL;
		}
		xchar = xmlNodeGetContent (output);
		GP_LOG_D("content of %s is %s", output->name, xchar);
	/* 

	<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/">
		<item id="1030822" parentID="0" restricted="0">
			<dc:title>103-0822</dc:title>
			<upnp:writeStatus>WRITABLE</upnp:writeStatus>
			<upnp:class name="imageItem">object.item.imageItem</upnp:class>
			<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_LRG;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_ORG">
				http://192.168.54.1:50001/DO1030822.JPG
			</res>
			<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_TN">
				http://192.168.54.1:50001/DT1030822.JPG
			</res>
			<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN">
				http://192.168.54.1:50001/DL1030822.JPG
			</res>
		</item>
	</DIDL-Lite>

	*/
		docin2 = xmlReadMemory ((char*)xchar, strlen((char*)xchar), "http://gphoto.org/", "utf-8", 0);
		if (!docin2) return NULL;
		docroot2 = xmlDocGetRootElement (docin2);
		if (!docroot) {
			xmlFreeDoc (docin2);
			return NULL;
		}
		if (strcmp((char*)docroot2->name,"DIDL-Lite")) {
			GP_LOG_E("expected DIDL-Lite, got %s", docroot2->name);
			xmlFreeDoc (docin2);
			return NULL;
		}
		output2 = xmlFirstElementChild (docroot2);
		if (strcmp((char*)output2->name,"item")) {
			GP_LOG_E("expected item, got %s", output2->name);
			xmlFreeDoc (docin2);
			return NULL;
		}
	/*
		<item id="1030822" parentID="0" restricted="0">
			<dc:title>103-0822</dc:title>
			<upnp:writeStatus>WRITABLE</upnp:writeStatus>
			<upnp:class name="imageItem">object.item.imageItem</upnp:class>
			<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_LRG;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_ORG">
				http://192.168.54.1:50001/DO1030822.JPG
			</res>
			<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_TN">
				http://192.168.54.1:50001/DT1030822.JPG
			</res>
			<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN">
				http://192.168.54.1:50001/DL1030822.JPG
			</res>
		</item>

we have:
Picture:
	http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_LRG;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_ORG
	http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_TN
	http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN

Movie:
	http-get:*:application/octet-stream:DLNA.ORG_OP=01;PANASONIC.COM_PN=CAM_AVC_MP4_HP_2160_30P_AAC
	http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_TN
	content is http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_SM;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN

Raw:
	http-get:*:application/octet-stream;PANASONIC.COM_PN=CAM_RAW_JPG
	http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_TN
	http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN
	http-get:*:application/octet-stream;PANASONIC.COM_PN=CAM_RAW

	*/
		next = output2;
		do {
			char	*id = NULL;
			int	i;
			xmlNode	*child;
			xmlAttr *attr = next->properties;

			GP_LOG_D("got %s", next->name);

			while (attr) {
				GP_LOG_D("\t attribute %s", attr->name);
				GP_LOG_D("\t attribute content %s", xmlNodeGetContent(attr->children));

				if (!strcmp((char*)attr->name, "id")) {
					id = (char*)xmlNodeGetContent(attr->children);
					break;
				}
				attr = attr->next;
			}
			/* look if we have the id */
			for (i=0;i<camera->pl->numpics;i++)
				if (camera->pl->pics[i].id && !strcmp(camera->pl->pics[i].id, id))
					break;
			if (i<camera->pl->numpics) {
				GP_LOG_D("already read id %s, is element %d\n", id, i);
				continue;
			}
			for (i=0;i<camera->pl->numpics;i++)
				if (!camera->pl->pics[i].id)
					break;
			if (i==camera->pl->numpics) {
				GP_LOG_D("no free slot found for id %s\n", id);
				continue;
			}
			camera->pl->pics[i].id = strdup(id);
			child = next->children;

		/*
			<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN">
				http://192.168.54.1:50001/DL1030822.JPG
			</res>
		*/
			while (child) {
				xmlAttr *attr;
				xmlChar	*attrcontent;

				if (strcmp((char*)child->name,"res")) {
					GP_LOG_D("skipping %s", child->name);
					child = child->next;
					continue;
				}
				attr = child->properties;

				if (strcmp((char*)attr->name,"protocolInfo")) {
					GP_LOG_D("expected attribute protocolInfo, got %s", attr->name);
				}
				attrcontent = xmlNodeGetContent(attr->children);
				GP_LOG_D("\t\tattribute content is %s", attrcontent);

				GP_LOG_D("\t child content %s", xmlNodeGetContent(child));

				/* FIXME: perhaps shorten match? */
				if (strstr((char*)attrcontent,"PANASONIC.COM_PN=CAM_AVC_MP4_HP_2160_30P_AAC")) {
					camera->pl->pics[i].url_movie = strdup((char*)xmlNodeGetContent(child));
				}
				// http-get:*:application/octet-stream;PANASONIC.COM_PN=CAM_RAW
				// but not
				// http-get:*:application/octet-stream;PANASONIC.COM_PN=CAM_RAW_JPG
				if (strstr((char*)attrcontent,"PANASONIC.COM_PN=CAM_RAW") &&
				    !strstr((char*)attrcontent,"PANASONIC.COM_PN=CAM_RAW_JPG")
				) {
					camera->pl->pics[i].url_raw = strdup((char*)xmlNodeGetContent(child));
				}
				if (strstr((char*)attrcontent,"PANASONIC.COM_PN=CAM_ORG")) {
					camera->pl->pics[i].url_large = strdup((char*)xmlNodeGetContent(child));
				}
				if (strstr((char*)attrcontent,"PANASONIC.COM_PN=CAM_LRGTN")) {
					camera->pl->pics[i].url_medium = strdup((char*)xmlNodeGetContent(child));
				}
				if (strstr((char*)attrcontent,"PANASONIC.COM_PN=CAM_TN")) {
					camera->pl->pics[i].url_thumb = strdup((char*)xmlNodeGetContent(child));
				}
				child = child->next;
			}
		} while ((next = xmlNextElementSibling (next)));


		output = xmlNextElementSibling (output);
		if (strcmp((char*)output->name,"NumberReturned")) {
			GP_LOG_E("fourth level node is %s, expected NumberReturned", output->name);
			xmlFreeDoc (docin);
			return NULL;
		}
		numread = xmlNodeGetContent (output);
		GP_LOG_D("content of %s is %s", output->name, numread);

		numreadint = 1;
		sscanf((char*)numread,"%d", &numreadint);

		start += numreadint;
		num -= numreadint;
	}
	return strdup((char*)xchar);
}

static struct shuttermap {
	char	*speed;
	char	*cameraspeed;
} shutterspeeds[] = {
	{"3072/256","4000"},
	{"2987/256","3200"},
	{"2902/256","2500"},
	{"2816/256","2000"},
	{"2731/256","1600"},
	{"2646/256","1300"},
	{"2560/256","1000"},
	{"2475/256","800"},
	{"2390/256","640"},
	{"2304/256","500"},
	{"2219/256","400"},
	{"2134/256","320"},
	{"2048/256","250"},
	{"1963/256","200"},
	{"1878/256","160"},
	{"1792/256","125"},
	{"1707/256","100"},
	{"1622/256","80"},
	{"1536/256","60"},
	{"1451/256","50"},
	{"1366/256","40"},
	{"1280/256","30"},
	{"1195/256","25"},
	{"1110/256","20"},
	{"1024/256","15"},
	{"939/256","13"},
	{"854/256","10"},
	{"768/256","8"},
	{"683/256","6"},
	{"598/256","5"},
	{"512/256","4"},
	{"427/256","3.2"},
	{"342/256","2.5"},
	{"256/256","2"},
	{"171/256","1.6"},
	{"86/256","1.3"},
	{"0/256","1"},
	{"-85/256","1.3s"},
	{"-170/256","1.6s"},
	{"-256/256","2s"},
	{"-341/256","2.5s"},
	{"-426/256","3.2s"},
	{"-512/256","4s"},
	{"-682/256","5s"},
	{"-768/256","6s"},
	{"-853/256","8s"},
	{"-938/256","10s"},
	{"-1024/256","13s"},
	{"-1109/256","15s"},
	{"-1194/256","20s"},
	{"-1280/256","25s"},
	{"-1365/256","30s"},
	{"-1450/256","40s"},
	{"-1536/256","50s"},
	{"16384/256","60s"},
	{"256/256","B"},
};

static struct aperturemap {
	char	*aperture;
	char	*cameraaperture;
} apertures[] = {
	{"392/256","1.7"},
	{"427/256","1.8"},
	{"512/256","2"},
	{"598/256","2.2"},
	{"683/256","2.5"},
	{"768/256","2.8"},
	{"854/256","3.2"},
	{"938/256","3.5"},
	{"1024/256","4"},
	{"1110/256","4.5"},
	{"1195/256","5"},
	{"1280/256","5.6"},
	{"1366/256","6.3"},
	{"1451/256","7.1"},
	{"1536/256","8"},
	{"1622/256","9"},
	{"1707/256","10"},
	{"1792/256","11"},
	{"1878/256","13"},
	{"1963/256","14"},
	{"2048/256","16"},
};

static int
camera_config_get (Camera *camera, CameraWidget **window, GPContext *context) 
{
        CameraWidget	*widget,*section;
        int		ret, i, valset;
	char		*val, *curval;

	switchToRecMode (camera);

        gp_widget_new (GP_WIDGET_WINDOW, _("Lumix Configuration"), window);
        gp_widget_set_name (*window, "config");

	gp_widget_new (GP_WIDGET_SECTION, _("Camera Settings"), &section);
	gp_widget_set_name (section, "settings");
	gp_widget_append (*window, section);

	gp_widget_new (GP_WIDGET_TEXT, _("Clock"), &widget);
	gp_widget_set_name (widget, "clock");
	gp_widget_set_value (widget, Get_Clock(camera));
	gp_widget_append (section, widget);


	val = Get_ShutterSpeed(camera);
	if (!val) val = "unknown";
	gp_widget_new (GP_WIDGET_RADIO, _("Shutterspeed"), &widget);
	gp_widget_set_name (widget, "shutterspeed");
	valset = 0;
	for (i=0;i<sizeof(shutterspeeds)/sizeof(shutterspeeds[0]);i++) {
		gp_widget_add_choice (widget, shutterspeeds[i].speed);
		if (!strcmp(val, shutterspeeds[i].cameraspeed)) {
			valset = 1;
			gp_widget_set_value (widget, shutterspeeds[i].speed);
		}
	}
	if (!valset) gp_widget_set_value (widget, val);
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_TEXT, _("Quality"), &widget);
	gp_widget_set_name (widget, "quality");
	gp_widget_set_value (widget, Get_Quality(camera));
	gp_widget_append (section, widget);


	val = Get_Aperture(camera);
	if (!val) val = "unknown";
	gp_widget_new (GP_WIDGET_RADIO, _("Aperture"), &widget);
	gp_widget_set_name (widget, "aperture");
	valset = 0;
	for (i=0;i<sizeof(apertures)/sizeof(apertures[0]);i++) {
		gp_widget_add_choice (widget, apertures[i].aperture);
		if (!strcmp(val, apertures[i].cameraaperture)) {
			valset = 1;
			gp_widget_set_value (widget, apertures[i].aperture);
		}
	}
	if (!valset) gp_widget_set_value (widget, val);
	gp_widget_append (section, widget);


	gp_widget_new (GP_WIDGET_TEXT, _("ISO"), &widget);
	gp_widget_set_name (widget, "iso");
	gp_widget_set_value (widget, Get_ISO(camera));
	gp_widget_append (section, widget);


	gp_widget_new (GP_WIDGET_TEXT, _("Autofocus Mode"), &widget);
	gp_widget_set_name (widget, "afmode");
	gp_widget_set_value (widget, Get_AFMode(camera));
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_TEXT, _("Focus Mode"), &widget);
	gp_widget_set_name (widget, "focusmode");
	gp_widget_set_value (widget, Get_FocusMode(camera));
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_TEXT, _("MF Assist"), &widget);
	gp_widget_set_name (widget, "mf_assist");
	gp_widget_set_value (widget, Get_MFAssist(camera));
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_TEXT, _("MF Assist Mag"), &widget);
	gp_widget_set_name (widget, "mf_assist_mag");
	gp_widget_set_value (widget, Get_MFAssist_Mag(camera));
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_TEXT, _("Ex Teleconv"), &widget);
	gp_widget_set_name (widget, "ex_tele_conv");
	gp_widget_set_value (widget, Get_ExTeleConv(camera));
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_TEXT, _("Lens"), &widget);
	gp_widget_set_name (widget, "lens");
	gp_widget_set_value (widget, Get_Lens(camera));
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_RADIO, _("Zoom"), &widget);
	gp_widget_set_name (widget, "zoom");
	gp_widget_set_value (widget, "none");
	gp_widget_add_choice (widget, "wide-fast");
	gp_widget_add_choice (widget, "wide-normal");
	gp_widget_add_choice (widget, "tele-normal");
	gp_widget_add_choice (widget, "tele-fast");
	gp_widget_add_choice (widget, "stop");
	gp_widget_append (section, widget);

#if 0
	gp_widget_new (GP_WIDGET_TEXT, _("Capability"), &widget);
	gp_widget_set_name (widget, "capability");
	gp_widget_set_value (widget, Get_Capability(camera));
	gp_widget_append (section, widget);

	/* lots of stuff ... lets see if we can use it */
	gp_widget_new (GP_WIDGET_TEXT, _("All Menu"), &widget);
	gp_widget_set_name (widget, "allmenu");
	gp_widget_set_value (widget, Get_AllMenu(camera));
	gp_widget_append (section, widget);

	gp_widget_new (GP_WIDGET_TEXT, _("Cur Menu"), &widget);
	gp_widget_set_name (widget, "curmenu");
	gp_widget_set_value (widget, Get_CurMenu(camera));
	gp_widget_append (section, widget);
#endif

	return GP_OK;
}

static int
camera_config_set (Camera *camera, CameraWidget *window, GPContext *context) 
{
	CameraWidget	*widget;
	char		*val;
	int		ret;

	if ((GP_OK == gp_widget_get_child_by_name(window, "zoom", &widget)) && gp_widget_changed (widget)) {
		char buf[30];
		if (GP_OK != (ret = gp_widget_get_value (widget, &val)))
			return ret;

		/* all valid values */
		if (	strcmp(val, "wide-fast")	&&
			strcmp(val, "wide-normal")	&&
			strcmp(val, "tele-normal")	&&
			strcmp(val, "tele-fast")	&&
			strcmp(val, "stop")
		)
			return GP_ERROR_BAD_PARAMETERS;

		if (!strcmp(val, "stop"))
			val = "zoomstop";

		sprintf(buf,"cam.cgi?mode=camcmd&value=%s", val);
		loadCmd(camera,buf);
	}

	if ((GP_OK == gp_widget_get_child_by_name(window, "shutterspeed", &widget)) && gp_widget_changed (widget)) {

		if (GP_OK != (ret = gp_widget_get_value (widget, &val)))
			return ret;
		Set_ShutterSpeed(camera,val);
	}

	if ((GP_OK == gp_widget_get_child_by_name(window, "aperture", &widget)) && gp_widget_changed (widget)) {
		char buf[50];

		if (GP_OK != (ret = gp_widget_get_value (widget, &val)))
			return ret;
		sprintf(buf,"cam.cgi?mode=setsetting&type=focal&value=%s", val);
		loadCmd(camera,buf);
	}
	return GP_OK;
}



static char*
processNode(xmlTextReaderPtr reader) {
	char* ret =""; 
	char* lookupImgtag="";

	switch (ReadoutMode) {
	case 0 : //'jpg
		lookupImgtag = "CAM_RAW_JPG";
	break; 
	case 1 :// 'raw
		lookupImgtag = "CAM_RAW";
	break;
	case 2  ://'thumb
		lookupImgtag = "CAM_LRGTN";
	break;
	}

    const xmlChar *name, *value;

    name = xmlTextReaderConstName(reader);
    if (name == NULL)
	name = BAD_CAST "--";

    if (xmlTextReaderNodeType(reader) == 1) {  // Element
	while (xmlTextReaderMoveToNextAttribute(reader)) {
		if (strend((char*)xmlTextReaderConstValue(reader),lookupImgtag)) {
			xmlTextReaderRead(reader);
			ret = (char*)xmlTextReaderConstValue(reader);
			printf("the image file is %s\n" ,ret);
		}
	}
    }
    return ret;
}

/*

below are 2 samples of XML files to be parsed one in case of a JPG/Thumb retrieve the other for RAW

case JPG/Thumb

<?xml version="1.0"?>
-<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
-<s:Body>
-<u:BrowseResponse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">
-<Result>
-<DIDL-Lite xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
-<item restricted="0" parentID="0" id="1030516">
<dc:title>103-0516</dc:title>
<upnp:writeStatus>WRITABLE</upnp:writeStatus>
<upnp:class name="imageItem">object.item.imageItem</upnp:class>
<res protocolInfo="http-get:*:application/octet-stream;PANASONIC.COM_PN=CAM_RAW_JPG">http://192.168.1.26:50001/DO1030516.JPG</res>
<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_TN">http://192.168.1.26:50001/DT1030516.JPG</res>
<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN">http://192.168.1.26:50001/DL1030516.JPG</res>
<res protocolInfo="http-get:*:application/octet-stream;PANASONIC.COM_PN=CAM_RAW">http://192.168.1.26:50001/DO1030516.RW2</res>
</item>
</DIDL-Lite>
</Result>
<NumberReturned>1</NumberReturned>
<TotalMatches>343</TotalMatches>
<UpdateID>1</UpdateID>
</u:BrowseResponse>
</s:Body>
</s:Envelope>

case RAW:
<?xml version="1.0"?>
-<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
-<s:Body>
-<u:BrowseResponse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">
-<Result>
-<DIDL-Lite xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
-<item restricted="0" parentID="0" id="1030517">
<dc:title>103-0517</dc:title>
<upnp:writeStatus>WRITABLE</upnp:writeStatus>
<upnp:class name="imageItem">object.item.imageItem</upnp:class>
<res protocolInfo="http-get:*:application/octet-stream;PANASONIC.COM_PN=CAM_RAW">http://192.168.1.26:50001/DO1030517.RAW</res>
<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=01;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_TN">http://192.168.1.26:50001/DT1030517.JPG</res>
<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00900000000000000000000000000000;PANASONIC.COM_PN=CAM_LRGTN">http://192.168.1.26:50001/DL1030517.JPG</res>
</item>
</DIDL-Lite>
</Result>
<NumberReturned>1</NumberReturned>
<TotalMatches>344</TotalMatches>
<UpdateID>1</UpdateID>
</u:BrowseResponse>
</s:Body>
</s:Envelope>

*/
static int
add_objectid_and_upload (Camera *camera, CameraFilePath *path, GPContext *context, char *ximage, size_t size) {
        int                     ret;
        CameraFile              *file = NULL;
        CameraFileInfo          info;

        ret = gp_file_new(&file);
        if (ret!=GP_OK) return ret;
        gp_file_set_mtime (file, time(NULL));
        strcpy(info.file.type, GP_MIME_JPEG);

        GP_LOG_D ("setting size");
        ret = gp_file_set_data_and_size(file, ximage, size);
        if (ret != GP_OK) {
                gp_file_free (file);
                return ret;
        }
        GP_LOG_D ("append to fs");
        ret = gp_filesystem_append(camera->fs, path->folder, path->name, context);
        if (ret != GP_OK) {
                gp_file_free (file);
                return ret;
        }
        GP_LOG_D ("adding filedata to fs");
        ret = gp_filesystem_set_file_noop(camera->fs, path->folder, path->name, GP_FILE_TYPE_NORMAL, file, context);
        if (ret != GP_OK) {
                gp_file_free (file);
                return ret;
        }

        /* We have now handed over the file, disclaim responsibility by unref. */
        gp_file_unref (file);

        /* we also get the fs info for free, so just set it */
        info.file.fields = GP_FILE_INFO_TYPE |
                        /*GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT |*/
                        GP_FILE_INFO_SIZE /*| GP_FILE_INFO_MTIME */ ;
        strcpy(info.file.type, GP_MIME_JPEG);

        info.preview.fields = 0; /* so far none */
/*
        info.file.width         = oi->ImagePixWidth;
        info.file.height        = oi->ImagePixHeight;
        info.file.size          = oi->ObjectCompressedSize;
        info.file.mtime         = time(NULL);

        info.preview.fields = GP_FILE_INFO_TYPE |
                        GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT |
                        GP_FILE_INFO_SIZE;
        strcpy_mime (info.preview.type, params->deviceinfo.VendorExtensionID, oi->ThumbFormat);
        info.preview.width      = oi->ThumbPixWidth;
        info.preview.height     = oi->ThumbPixHeight;
        info.preview.size       = oi->ThumbCompressedSize;
*/

        GP_LOG_D ("setting fileinfo in fs");
        return gp_filesystem_set_info_noop(camera->fs, path->folder, path->name, info, context);
}

static int
ReadImageFromCamera(Camera *camera, CameraFilePath *path, GPContext *context) {
	char			*image;
	long			nRead;
	LumixMemoryBuffer	lmb;
	char			*xmlimageName;
	xmlDocPtr		doc; /* the resulting document tree */
	int			ret;
	char			* imageURL="";
	xmlTextReaderPtr	reader;

	switchToPlayMode (camera);

	reader = xmlReaderForDoc((xmlChar*)GetPixRange(camera,NumberPix(camera)-1,1), NULL,"noname.xml", XML_PARSE_DTDATTR |  /* default DTD attributes */ XML_PARSE_NOENT); 
	ret = xmlTextReaderRead(reader);
	while (ret == 1) {
	    imageURL = processNode(reader); 
            if (strlen(imageURL))
		break; 
            ret = xmlTextReaderRead(reader);
	}

	GP_DEBUG("the image URL is  %s\n",imageURL); 
	image = strdup(imageURL);
	nRead = 0;
	CURL* imageUrl;
	imageUrl = curl_easy_init();
	CURLcode res;
	double bytesread = 0;
	char filename[100];
	long http_response;
	int ret_val=0;


	while (ret_val!=2) {
		GP_DEBUG("reading stream %s position %ld", image, nRead);

		curl_easy_setopt(imageUrl, CURLOPT_URL, image);
		//curl_easy_setopt(imageUrl,CURLOPT_TCP_KEEPALIVE,1L);
		//curl_easy_setopt(imageUrl, CURLOPT_TCP_KEEPIDLE, 120L);
		//curl_easy_setopt(imageUrl, CURLOPT_TCP_KEEPINTVL, 60L);

#if 0
		/* FIXME trick wont work anymore with new buffering code -Marcus */
		if (nRead) {
			curl_easy_setopt(imageUrl, CURLOPT_RESUME_FROM, nRead);
			GetPix(camera,1);//'if the file not found happened then this trick is to get the camera in a readmode again and making sure it remembers the filename
			GP_DEBUG("continuing the read where it stopped %s  position %ld", image,  nRead);
		}
#endif
		lmb.size = 0;
		lmb.data = malloc(0);
		curl_easy_setopt(imageUrl, CURLOPT_WRITEFUNCTION, write_callback);
		curl_easy_setopt(imageUrl, CURLOPT_WRITEDATA, &lmb);

		res = curl_easy_perform(imageUrl);

		if (res != CURLE_OK) {
			GP_LOG_E("curl_easy_perform() failed: %s", curl_easy_strerror(res));
			GP_DEBUG("error in reading stream %s  position %ld", image,  nRead);
			curl_easy_getinfo(imageUrl, CURLINFO_RESPONSE_CODE, &http_response);
			GP_DEBUG("CURLINFO_RESPONSE_CODE:%ld\n", http_response);
		} else {
			GP_DEBUG("read the whole file");
			ret_val=2;
		}
	}
	curl_easy_cleanup(imageUrl);
	strcpy(path->name, strrchr(image,'/')+1);
	strcpy(path->folder, "/");
	return add_objectid_and_upload (camera, path, context, lmb.data, lmb.size);
}


/**
* Capture an image and tell libgphoto2 where to find it by filling
* out the path.
*
* This function is a method of the Camera object.
*/
static int
camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path, GPContext *context) {
	int	ret, tries, before, after;
	char	*s, *url;


	tries = 10;
	do {
		ret = NumberPix(camera);
		if (ret == GP_ERROR_CAMERA_BUSY)
			sleep(1);
	} while ((ret == GP_ERROR_CAMERA_BUSY) && (tries--));

	if (ret < GP_OK)
		return ret;

	before = ret;
	GP_LOG_D("numberpix before=%d", ret);

	switchToRecMode (camera);

	sleep(2);

	ret = startCapture (camera);
	if (ret != GP_OK)
		return ret;


	if (strcmp(cameraShutterSpeed, "B")!=0) {  
		sleep(captureDuration); // Sleep for the duration to simulate exposure, if this is in Bulb mode 
	} else {
		sleep(3);
	}
	stopCapture(camera);

	tries = 10;
	do {
		ret = NumberPix(camera);
		if (ret == GP_ERROR_CAMERA_BUSY)
			sleep(1);
	} while ((ret == GP_ERROR_CAMERA_BUSY) && (tries--));
	if (ret < GP_OK)
		return ret;

	after = ret;
	GP_LOG_D("numberpix after=%d", ret);

	if (after > before)
		GetPixRange(camera,before,after-before);
	/* handle case where we have more than one picture, otherwise we just take one */
	url = "unknown";
	if (camera->pl->pics[after].url_large) url = camera->pl->pics[after].url_large;
	if (camera->pl->pics[after].url_raw) url = camera->pl->pics[after].url_raw;
	s = strrchr(url,'/')+1;
	strcpy(path->name, s);
	strcpy(path->folder, "/");
	return GP_OK;
}

/**
* Fill out the summary with textual information about the current 
* state of the camera (like pictures taken, etc.).
*
* This function is a method of the Camera object.
*/
static int
camera_summary (Camera *camera, CameraText *summary, GPContext *context)
{
	return GP_OK;
}


/**
* Return the camera drivers manual.
* If you would like to tell the user some information about how 
* to use the camera or the driver, this is the place to do.
*
* This function is a method of the Camera object.
*/
static int camera_manual (Camera *camera, CameraText *manual, GPContext *context) {
	return GP_OK;
}


/**
* Return "About" content as textual description.
* Will be translated.
*
* This function is a method of the Camera object.
*/
int  camera_about (Camera *camera, CameraText *about, GPContext *context);
int camera_about (Camera *camera, CameraText *about, GPContext *context) {
	strcpy (about->text, _("Lumix WiFi Library\n"
	"Robert Hasson <robert_hasson@yahoo.com>\n"
	"Connects to Lumix Cameras over Wifi.\n"
	"using the http GET commands."));
	return GP_OK;
}

/*@}*/


/**********************************************************************/
/**
* @name CameraFilesystem member functions
*
* @{
*/
/**********************************************************************/


/**
* Get the file from the camera.
*
* This function is a CameraFilesystem method.
*/
static int
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileType type, CameraFile *file, void *data, GPContext *context)
{
	Camera		*camera = data;
	int		i;
	CURLcode	res;
	CURL		*imageUrl;
	double		bytesread = 0;
	long		http_response;
	int		ret_val = 0;
	long			nRead;
	LumixMemoryBuffer	lmb;
	const char	*url;

	for (i=0;i<camera->pl->numpics;i++) {
		char *s;

		if (camera->pl->pics[i].url_movie) {
			s = strrchr(camera->pl->pics[i].url_movie,'/')+1;
			if (!strcmp(s,filename)) {
				url = camera->pl->pics[i].url_movie;
				break;
			}
		}
		if (camera->pl->pics[i].url_raw) {
			s = strrchr(camera->pl->pics[i].url_raw,'/')+1;
			if (!strcmp(s,filename)) {
				url = camera->pl->pics[i].url_raw;
				break;
			}
		}
		if (camera->pl->pics[i].url_large) {
			s = strrchr(camera->pl->pics[i].url_large,'/')+1;
			if (!strcmp(s,filename)) {
				url = camera->pl->pics[i].url_large;
				break;
			}
		}
	}
	if (i == camera->pl->numpics) /* not found */
		return GP_ERROR;

	switch (type) {
	case GP_FILE_TYPE_PREVIEW:
		if (camera->pl->pics[i].url_thumb)
			url = camera->pl->pics[i].url_thumb;
		break;
	case GP_FILE_TYPE_NORMAL:
	default:
		/* just use regular url */
		break;
	}

	switchToPlayMode (camera);

	imageUrl = curl_easy_init();

	while (ret_val != 2) {
		GP_DEBUG("reading stream %s position %ld", url, nRead);

		curl_easy_setopt(imageUrl, CURLOPT_URL, url);
		//curl_easy_setopt(imageUrl,CURLOPT_TCP_KEEPALIVE,1L);
		//curl_easy_setopt(imageUrl, CURLOPT_TCP_KEEPIDLE, 120L);
		//curl_easy_setopt(imageUrl, CURLOPT_TCP_KEEPINTVL, 60L);

#if 1
		/* FIXME trick wont work anymore with new buffering code -Marcus */
		if (nRead) {
			curl_easy_setopt(imageUrl, CURLOPT_RESUME_FROM, nRead);
			GetPixRange(camera,NumberPix(camera)-1,1);//'if the file not found happened then this trick is to get the camera in a readmode again and making sure it remembers the filename
			GP_DEBUG("continuing the read where it stopped %s  position %ld", url,  nRead);
		}
#endif
		lmb.size = 0;
		lmb.data = malloc(0);
		curl_easy_setopt(imageUrl, CURLOPT_WRITEFUNCTION, write_callback);
		curl_easy_setopt(imageUrl, CURLOPT_WRITEDATA, &lmb);

		res = curl_easy_perform(imageUrl);

		if (res != CURLE_OK) {
			GP_LOG_E("curl_easy_perform() failed: %s", curl_easy_strerror(res));
			GP_DEBUG("error in reading stream %s  position %ld", url,  nRead);
			curl_easy_getinfo(imageUrl, CURLINFO_RESPONSE_CODE, &http_response);
			GP_DEBUG("CURLINFO_RESPONSE_CODE:%ld\n", http_response);
			return GP_ERROR_IO;
		} else {
			GP_DEBUG("read the whole file");
			ret_val=2;
		}
	}
	curl_easy_cleanup(imageUrl);

	return gp_file_set_data_and_size (file, lmb.data, lmb.size);
}


int camera_abilities (CameraAbilitiesList *list) {
	CameraAbilities a;

	memset(&a, 0, sizeof(a));
	strcpy(a.model, "Panasonic:LumixGSeries");
	a.status	= GP_DRIVER_STATUS_EXPERIMENTAL;
	a.port		= GP_PORT_TCP;
	a.operations	= GP_CAPTURE_IMAGE| GP_OPERATION_CAPTURE_VIDEO | GP_OPERATION_CONFIG;
	a.file_operations = GP_FILE_OPERATION_PREVIEW  ; 
	/* it should be possible to browse and DL images the files using the ReadImageFromCamera() function but for now lets keep it simple*/ 
	a.folder_operations = GP_FOLDER_OPERATION_NONE;
	return gp_abilities_list_append(list, a);
}

/**
* All filesystem accessor functions.
*
* This should contain all filesystem accessor functions
* available in the camera library. Non-present fields
* are NULL.
*
*/
CameraFilesystemFuncs fsfuncs = {
	.file_list_func = file_list_func,
	.folder_list_func = folder_list_func,
//	.get_info_func = get_info_func,
//	.set_info_func = set_info_func,
	.get_file_func = get_file_func,
//	.del_file_func = delete_file_func,
//	.put_file_func = put_file_func,
//	.delete_all_func = delete_all_func,
//	.storage_info_func = storage_info_func
};

/**
* Initialize a Camera object.
*
* Sets up all the proper object function pointers, initialize camlib
* internal data structures, and probably establish a connection to
* the camera.
*
* This is a camlib API function.
*/
int
camera_init (Camera *camera, GPContext *context) 
{
	GPPortInfo      info;
	char            *xpath;
	int		ret;

	camera->pl = calloc(sizeof(CameraPrivateLibrary),1);

	/* First, set up all the function pointers */
	camera->functions->exit                 = camera_exit;
	camera->functions->get_config           = camera_config_get;
	camera->functions->set_config           = camera_config_set;
	camera->functions->capture              = camera_capture;
	camera->functions->capture_preview      = camera_capture_preview;
	camera->functions->summary              = camera_summary;
	camera->functions->manual               = camera_manual;
	camera->functions->about                = camera_about;

	LIBXML_TEST_VERSION

	curl_global_init(CURL_GLOBAL_ALL);

	ret = gp_port_get_info (camera->port, &info);
	if (ret != GP_OK) {
		GP_LOG_E ("Failed to get port info?");
		return ret;
	}
	gp_port_info_get_path (info, &xpath);
	/* xpath now contains tcp:192.168.1.1 */

	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

	if (switchToRecMode (camera) != NULL) {
		int numpix;

		Set_quality(camera,"raw_fine");

		switchToPlayMode (camera);

		numpix = NumberPix(camera);
		GetPixRange(camera,0,numpix);
		return GP_OK;
	} else
		return GP_ERROR_IO;
}