libsyncml  0.5.4
sml_devinf.c
1 /*
2  * libsyncml - A syncml protocol implementation
3  * Copyright (C) 2005 Armin Bauer <armin.bauer@opensync.org>
4  * Copyright (C) 2007-2008 Michael Bell <michael.bell@opensync.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "syncml.h"
23 
24 #include "syncml_internals.h"
25 #include "sml_devinf_internals.h"
26 #include "sml_command_internals.h"
27 #include "sml_elements_internals.h"
28 #include "sml_parse_internals.h"
29 #include "parser/sml_xml_assm.h"
30 #include "parser/sml_xml_parse.h"
31 #include "sml_error_internals.h"
32 
33 SmlDevInfDevTyp smlDevInfDevTypeFromString(const char *name, SmlError **error)
34 {
35  CHECK_ERROR_REF
36 
37  if (!strcmp(name, SML_ELEMENT_DEVTYP_PAGER)) {
38  return SML_DEVINF_DEVTYPE_PAGER;
39  } else if (!strcmp(name, SML_ELEMENT_DEVTYP_HANDHELD)) {
40  return SML_DEVINF_DEVTYPE_HANDHELD;
41  } else if (!strcmp(name, SML_ELEMENT_DEVTYP_PDA)) {
42  return SML_DEVINF_DEVTYPE_PDA;
43  } else if (!strcmp(name, SML_ELEMENT_DEVTYP_PHONE)) {
44  return SML_DEVINF_DEVTYPE_PHONE;
45  } else if (!strcmp(name, SML_ELEMENT_DEVTYP_SMARTPHONE)) {
46  return SML_DEVINF_DEVTYPE_SMARTPHONE;
47  } else if (!strcmp(name, SML_ELEMENT_DEVTYP_SERVER)) {
48  return SML_DEVINF_DEVTYPE_SERVER;
49  } else if (!strcmp(name, SML_ELEMENT_DEVTYP_WORKSTATION)) {
50  return SML_DEVINF_DEVTYPE_WORKSTATION;
51  }
52 
53  smlErrorSet(error, SML_ERROR_GENERIC, "Unknown devinf type name \"%s\"", name);
54  return SML_DEVINF_DEVTYPE_UNKNOWN;
55 }
56 
57 const char *smlDevInfDevTypeToString(SmlDevInfDevTyp type, SmlError **error)
58 {
59  CHECK_ERROR_REF
60 
61  switch (type) {
62  case SML_DEVINF_DEVTYPE_PAGER:
63  return SML_ELEMENT_DEVTYP_PAGER;
64  case SML_DEVINF_DEVTYPE_HANDHELD:
65  return SML_ELEMENT_DEVTYP_HANDHELD;
66  case SML_DEVINF_DEVTYPE_PDA:
67  return SML_ELEMENT_DEVTYP_PDA;
68  case SML_DEVINF_DEVTYPE_PHONE:
69  return SML_ELEMENT_DEVTYP_PHONE;
70  case SML_DEVINF_DEVTYPE_SMARTPHONE:
71  return SML_ELEMENT_DEVTYP_SMARTPHONE;
72  case SML_DEVINF_DEVTYPE_SERVER:
73  return SML_ELEMENT_DEVTYP_SERVER;
74  case SML_DEVINF_DEVTYPE_WORKSTATION:
75  return SML_ELEMENT_DEVTYP_WORKSTATION;
76  case SML_DEVINF_DEVTYPE_UNKNOWN:
77  smlErrorSet(error, SML_ERROR_GENERIC, "Unknown devinf type \"%i\"", type);
78  /* fall through! */
79  }
80 
81  return NULL;
82 }
83 
84 SmlDevInf *smlDevInfNew(const char *devid, SmlDevInfDevTyp devtyp, SmlError **error)
85 {
86  smlTrace(TRACE_ENTRY, "%s(%s, %i, %p)", __func__, VA_STRING(devid), devtyp, error);
87  CHECK_ERROR_REF
88  smlAssert(devid);
89 
90  SmlDevInf *devinf = smlTryMalloc0(sizeof(SmlDevInf), error);
91  if (!devinf)
92  goto error;
93 
94  devinf->devid = g_strdup(devid);
95  devinf->devtyp = devtyp;
96  devinf->refCount = 1;
97 
98  smlTrace(TRACE_EXIT, "%s: %p", __func__, devinf);
99  return devinf;
100 
101 error:
102  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
103  return NULL;
104 }
105 
106 SmlDevInf *smlDevInfRef(SmlDevInf *devinf)
107 {
108  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, devinf);
109  smlAssert(devinf);
110 
111  g_atomic_int_inc(&(devinf->refCount));
112 
113  smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, devinf->refCount);
114  return devinf;
115 }
116 
117 void smlDevInfUnref(SmlDevInf *devinf)
118 {
119  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, devinf);
120  smlAssert(devinf);
121 
122  if (g_atomic_int_dec_and_test(&(devinf->refCount))) {
123  smlTrace(TRACE_INTERNAL, "%s: Refcount == 0!", __func__);
124 
125  if (devinf->manufacturer)
126  smlSafeCFree(&(devinf->manufacturer));
127  if (devinf->model)
128  smlSafeCFree(&(devinf->model));
129  if (devinf->oem)
130  smlSafeCFree(&(devinf->oem));
131  if (devinf->softwareVersion)
132  smlSafeCFree(&(devinf->softwareVersion));
133  if (devinf->hardwareVersion)
134  smlSafeCFree(&(devinf->hardwareVersion));
135  if (devinf->firmwareVersion)
136  smlSafeCFree(&(devinf->firmwareVersion));
137  if (devinf->devid)
138  smlSafeCFree(&(devinf->devid));
139 
140  while (devinf->datastores) {
141  SmlDevInfDataStore *store = devinf->datastores->data;
142  devinf->datastores = g_list_remove(devinf->datastores, store);
143  smlDevInfDataStoreUnref(store);
144  }
145 
146  while (devinf->ctcaps) {
147  SmlDevInfCTCap *ctcap = devinf->ctcaps->data;
148  devinf->ctcaps = g_list_remove(devinf->ctcaps, ctcap);
149  smlSafeCFree(&(ctcap->ct->cttype));
150  if (ctcap->ct->verct)
151  smlSafeCFree(&(ctcap->ct->verct));
152  smlSafeFree((gpointer *)&(ctcap->ct));
153  while (ctcap->properties) {
154  SmlDevInfProperty *prop = ctcap->properties->data;
155  ctcap->properties = g_list_remove(ctcap->properties, prop);
156  smlSafeCFree(&(prop->propName));
157  if (prop->dataType)
158  smlSafeCFree(&(prop->dataType));
159  if (prop->displayName)
160  smlSafeCFree(&(prop->displayName));
161  /* if lists are removed
162  * then the data must be removed separately
163  */
164  while (prop->valEnums) {
165  char *valEnum = prop->valEnums->data;
166  prop->valEnums = g_list_remove(prop->valEnums, valEnum);
167  smlSafeCFree(&valEnum);
168  }
169  while (prop->propParams) {
170  SmlDevInfPropParam *param = prop->propParams->data;
171  prop->propParams = g_list_remove(prop->propParams, param);
172  smlSafeCFree(&(param->paramName));
173  if (param->dataType)
174  smlSafeCFree(&(param->dataType));
175  if (param->displayName)
176  smlSafeCFree(&(param->displayName));
177  /* if lists are removed
178  * then the data must be removed separately
179  */
180  while (param->valEnums) {
181  char *valEnum = param->valEnums->data;
182  param->valEnums = g_list_remove(param->valEnums, valEnum);
183  smlSafeCFree(&valEnum);
184  }
185  /* free PropParam itself */
186  smlSafeFree((gpointer *) &param);
187  }
188  /* free Property itself */
189  smlSafeFree((gpointer *) &prop);
190  }
191  /* don't use ctcap here because the list must be cleaned up */
192  smlSafeFree((gpointer *)&ctcap);
193  }
194 
195  smlSafeFree((gpointer *)&devinf);
196  }
197 
198  smlTrace(TRACE_EXIT, "%s", __func__);
199 }
200 
201 const char *smlDevInfGetManufacturer(SmlDevInf *devinf)
202 {
203  return devinf->manufacturer;
204 }
205 
206 void smlDevInfSetManufacturer(SmlDevInf *devinf, const char *man)
207 {
208  if (devinf->manufacturer)
209  smlSafeCFree(&(devinf->manufacturer));
210  devinf->manufacturer = g_strdup(man);
211 }
212 
213 const char *smlDevInfGetModel(SmlDevInf *devinf)
214 {
215  return devinf->model;
216 }
217 
218 void smlDevInfSetModel(SmlDevInf *devinf, const char *model)
219 {
220  if (devinf->model)
221  smlSafeCFree(&(devinf->model));
222  devinf->model = g_strdup(model);
223 }
224 
225 const char *smlDevInfGetOEM(SmlDevInf *devinf)
226 {
227  return devinf->oem;
228 }
229 
230 void smlDevInfSetOEM(SmlDevInf *devinf, const char *oem)
231 {
232  if (devinf->oem)
233  smlSafeCFree(&(devinf->oem));
234  devinf->oem = g_strdup(oem);
235 }
236 
237 const char *smlDevInfGetFirmwareVersion(SmlDevInf *devinf)
238 {
239  return devinf->firmwareVersion;
240 }
241 
242 void smlDevInfSetFirmwareVersion(SmlDevInf *devinf, const char *firmwareVersion)
243 {
244  if (devinf->firmwareVersion)
245  smlSafeCFree(&(devinf->firmwareVersion));
246  devinf->firmwareVersion = g_strdup(firmwareVersion);
247 }
248 
249 const char *smlDevInfGetSoftwareVersion(SmlDevInf *devinf)
250 {
251  return devinf->softwareVersion;
252 }
253 
254 void smlDevInfSetSoftwareVersion(SmlDevInf *devinf, const char *softwareVersion)
255 {
256  if (devinf->softwareVersion)
257  smlSafeCFree(&(devinf->softwareVersion));
258  devinf->softwareVersion = g_strdup(softwareVersion);
259 }
260 
261 const char *smlDevInfGetHardwareVersion(SmlDevInf *devinf)
262 {
263  return devinf->hardwareVersion;
264 }
265 
266 void smlDevInfSetHardwareVersion(SmlDevInf *devinf, const char *hardwareVersion)
267 {
268  if (devinf->hardwareVersion)
269  smlSafeCFree(&(devinf->hardwareVersion));
270  devinf->hardwareVersion = g_strdup(hardwareVersion);
271 }
272 
273 const char *smlDevInfGetDeviceID(SmlDevInf *devinf)
274 {
275  return devinf->devid;
276 }
277 
278 void smlDevInfSetDeviceID(SmlDevInf *devinf, const char *devid)
279 {
280  if (devinf->devid)
281  smlSafeCFree(&(devinf->devid));
282  devinf->devid = g_strdup(devid);
283 }
284 
285 SmlDevInfDevTyp smlDevInfGetDeviceType(SmlDevInf *devinf)
286 {
287  return devinf->devtyp;
288 }
289 
290 void smlDevInfSetDeviceType(SmlDevInf *devinf, SmlDevInfDevTyp devtyp)
291 {
292  devinf->devtyp = devtyp;
293 }
294 
295 SmlBool smlDevInfSupportsUTC(SmlDevInf *devinf)
296 {
297  return devinf->supportsUTC;
298 }
299 
300 void smlDevInfSetSupportsUTC(SmlDevInf *devinf, SmlBool supports)
301 {
302  devinf->supportsUTC = supports;
303 }
304 
305 SmlBool smlDevInfSupportsLargeObjs(SmlDevInf *devinf)
306 {
307  return devinf->supportsLargeObjs;
308 }
309 
310 void smlDevInfSetSupportsLargeObjs(SmlDevInf *devinf, SmlBool supports)
311 {
312  devinf->supportsLargeObjs = supports;
313 }
314 
315 SmlBool smlDevInfSupportsNumberOfChanges(SmlDevInf *devinf)
316 {
317  return devinf->supportsNumberOfChanges;
318 }
319 
320 void smlDevInfSetSupportsNumberOfChanges(SmlDevInf *devinf, SmlBool supports)
321 {
322  devinf->supportsNumberOfChanges = supports;
323 }
324 
325 void smlDevInfAddDataStore(SmlDevInf *devinf, SmlDevInfDataStore *datastore)
326 {
327  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, devinf, datastore);
328  smlAssert(devinf);
329  smlAssert(datastore);
330 
331  devinf->datastores = g_list_append(devinf->datastores, datastore);
332 
333 
334  smlTrace(TRACE_EXIT, "%s", __func__);
335 }
336 
337 unsigned int smlDevInfNumDataStores(SmlDevInf *devinf)
338 {
339  smlAssert(devinf);
340 
341  return g_list_length(devinf->datastores);
342 }
343 
344 const SmlDevInfDataStore *smlDevInfGetNthDataStore(const SmlDevInf *devinf, unsigned int nth)
345 {
346  smlAssert(devinf);
347 
348  return g_list_nth_data(devinf->datastores, nth);
349 }
350 
351 SmlDevInfDataStore *smlDevInfDataStoreNew(const char *sourceRef, SmlError **error)
352 {
353  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, sourceRef, error);
354  CHECK_ERROR_REF
355 
356  SmlDevInfDataStore *datastore = smlTryMalloc0(sizeof(SmlDevInfDataStore), error);
357  if (!datastore)
358  goto error;
359 
360  datastore->sourceref = g_strdup(sourceRef);
361  datastore->refCount = 1;
362 
363  smlTrace(TRACE_EXIT, "%s: %p", __func__, datastore);
364  return datastore;
365 
366 error:
367  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
368  return NULL;
369 }
370 
371 
372 SmlDevInfDataStore *smlDevInfDataStoreRef(SmlDevInfDataStore *datastore)
373 {
374  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, datastore);
375  smlAssert(datastore);
376 
377  g_atomic_int_inc(&(datastore->refCount));
378 
379  smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, datastore->refCount);
380  return datastore;
381 }
382 
383 void smlDevInfDataStoreUnref(SmlDevInfDataStore *datastore)
384 {
385  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, datastore);
386  smlAssert(datastore);
387 
388  if (g_atomic_int_dec_and_test(&(datastore->refCount))) {
389  smlTrace(TRACE_INTERNAL, "%s: Refcount == 0!", __func__);
390 
391  smlSafeCFree(&(datastore->sourceref));
392  if (datastore->displayname)
393  smlSafeCFree(&(datastore->displayname));
394 
395  smlSafeCFree(&(datastore->rxPrefContentType));
396  smlSafeCFree(&(datastore->rxPrefVersion));
397  GList *d = NULL;
398  for (d = datastore->rx; d; d = d->next) {
399  SmlDevInfContentType *ct = d->data;
400  smlDevInfFreeContentType(ct);
401  }
402  g_list_free(datastore->rx);
403 
404  smlSafeCFree(&(datastore->txPrefContentType));
405  smlSafeCFree(&(datastore->txPrefVersion));
406  for (d = datastore->tx; d; d = d->next) {
407  SmlDevInfContentType *ct = d->data;
408  smlDevInfFreeContentType(ct);
409  }
410  g_list_free(datastore->tx);
411 
412  smlSafeFree((gpointer *)&datastore);
413  }
414 
415  smlTrace(TRACE_EXIT, "%s", __func__);
416 }
417 
418 const char *smlDevInfDataStoreGetSourceRef(const SmlDevInfDataStore *datastore)
419 {
420  return datastore->sourceref;
421 }
422 
423 void smlDevInfDataStoreSetSourceRef(SmlDevInfDataStore *datastore, const char *sourceref)
424 {
425  if (datastore->sourceref)
426  smlSafeCFree(&(datastore->sourceref));
427  datastore->sourceref = g_strdup(sourceref);
428 }
429 
430 const char *smlDevInfDataStoreGetDisplayName(const SmlDevInfDataStore *datastore)
431 {
432  return datastore->displayname;
433 }
434 
435 void smlDevInfDataStoreSetDisplayName(SmlDevInfDataStore *datastore, const char *displayName)
436 {
437  if (datastore->displayname)
438  smlSafeCFree(&(datastore->displayname));
439  datastore->displayname = g_strdup(displayName);
440 }
441 
442 unsigned int smlDevInfGetMaxGUIDSize(const SmlDevInfDataStore *datastore)
443 {
444  return datastore->maxGUIDSize;
445 }
446 
447 void smlDevInfSetMaxGUIDSize(SmlDevInfDataStore *datastore, unsigned int max)
448 {
449  datastore->maxGUIDSize = max;
450 }
451 
452 void smlDevInfDataStoreSetRxPref(SmlDevInfDataStore *datastore, const char *contenttype, const char *version)
453 {
454  if (datastore->rxPrefContentType)
455  smlSafeCFree(&(datastore->rxPrefContentType));
456  datastore->rxPrefContentType = g_strdup(contenttype);
457 
458  if (datastore->rxPrefVersion)
459  smlSafeCFree(&(datastore->rxPrefVersion));
460  datastore->rxPrefVersion = g_strdup(version);
461 }
462 
463 SmlBool smlDevInfDataStoreGetRxPref(const SmlDevInfDataStore *datastore, char **contenttype, char **version)
464 {
465  if (!datastore->rxPrefContentType)
466  return FALSE;
467 
468  *contenttype = datastore->rxPrefContentType;
469  *version = datastore->rxPrefVersion;
470 
471  return TRUE;
472 }
473 
474 /* FIXME: DEPRECATED*/
475 void smlDevInfDataStoreSetRx(SmlDevInfDataStore *datastore, const char *contenttype, const char *version)
476 {
477  SmlError *error = NULL;
478  SmlDevInfContentType *ct = smlDevInfNewContentType(contenttype, version, &error);
479  if (!ct)
480  {
481  smlTrace(TRACE_ERROR, "%s - %s", __func__, smlErrorPrint(&error));
482  smlErrorDeref(&error);
483  return;
484  }
485  smlDevInfDataStoreAddRx(datastore, ct);
486 }
487 
488 /* FIXME: DEPRECATED*/
489 SmlBool smlDevInfDataStoreGetRx(const SmlDevInfDataStore *datastore, char **contenttype, char **version)
490 {
491  const SmlDevInfContentType *ct = smlDevInfDataStoreGetNthRx(datastore, 0);
492  if (!ct)
493  return FALSE;
494 
495  *contenttype = smlDevInfContentTypeGetCTType(ct);
496  *version = smlDevInfContentTypeGetVerCT(ct);
497  return TRUE;
498 }
499 
500 void smlDevInfDataStoreAddRx(SmlDevInfDataStore *datastore, SmlDevInfContentType *ct)
501 {
502  smlAssert(datastore);
503  datastore->rx = g_list_append(datastore->rx, ct);
504 }
505 
506 unsigned int smlDevInfDataStoreNumRx(const SmlDevInfDataStore *datastore)
507 {
508  return g_list_length(datastore->rx);
509 }
510 
511 const SmlDevInfContentType *smlDevInfDataStoreGetNthRx(
512  const SmlDevInfDataStore *datastore,
513  unsigned int n)
514 {
515  return g_list_nth_data(datastore->rx, n);
516 }
517 
518 void smlDevInfDataStoreSetTxPref(SmlDevInfDataStore *datastore, const char *contenttype, const char *version)
519 {
520  if (datastore->txPrefContentType)
521  smlSafeCFree(&(datastore->txPrefContentType));
522  datastore->txPrefContentType = g_strdup(contenttype);
523 
524  if (datastore->txPrefVersion)
525  smlSafeCFree(&(datastore->txPrefVersion));
526  datastore->txPrefVersion = g_strdup(version);
527 }
528 
529 SmlBool smlDevInfDataStoreGetTxPref(const SmlDevInfDataStore *datastore, char **contenttype, char **version)
530 {
531  if (!datastore->txPrefContentType)
532  return FALSE;
533 
534  *contenttype = datastore->txPrefContentType;
535  *version = datastore->txPrefVersion;
536 
537  return TRUE;
538 }
539 
540 /* FIXME: DEPRECATED*/
541 void smlDevInfDataStoreSetTx(SmlDevInfDataStore *datastore, const char *contenttype, const char *version)
542 {
543  SmlError *error = NULL;
544  SmlDevInfContentType *ct = smlDevInfNewContentType(contenttype, version, &error);
545  if (!ct)
546  {
547  smlTrace(TRACE_ERROR, "%s - %s", __func__, smlErrorPrint(&error));
548  smlErrorDeref(&error);
549  return;
550  }
551  smlDevInfDataStoreAddTx(datastore, ct);
552 }
553 
554 /* FIXME: DEPRECATED*/
555 SmlBool smlDevInfDataStoreGetTx(const SmlDevInfDataStore *datastore, char **contenttype, char **version)
556 {
557  const SmlDevInfContentType *ct = smlDevInfDataStoreGetNthRx(datastore, 0);
558  if (!ct)
559  return FALSE;
560 
561  *contenttype = smlDevInfContentTypeGetCTType(ct);
562  *version = smlDevInfContentTypeGetVerCT(ct);
563  return TRUE;
564 }
565 
566 void smlDevInfDataStoreAddTx(SmlDevInfDataStore *datastore, SmlDevInfContentType *ct)
567 {
568  smlAssert(datastore);
569  datastore->tx = g_list_append(datastore->tx, ct);
570 }
571 
572 unsigned int smlDevInfDataStoreNumTx(const SmlDevInfDataStore *datastore)
573 {
574  return g_list_length(datastore->tx);
575 }
576 
577 const SmlDevInfContentType *smlDevInfDataStoreGetNthTx(
578  const SmlDevInfDataStore *datastore,
579  unsigned int n)
580 {
581  return g_list_nth_data(datastore->tx, n);
582 }
583 
584 void smlDevInfDataStoreSetMemory(SmlDevInfDataStore *datastore, SmlBool shared, unsigned int maxid, unsigned int maxmem)
585 {
586  datastore->sharedMem = shared;
587  datastore->maxid = maxid;
588  datastore->maxmem = maxmem;
589 }
590 
591 void smlDevInfDataStoreGetMemory(const SmlDevInfDataStore *datastore, SmlBool *shared, unsigned int *maxid, unsigned int *maxmem)
592 {
593  if (shared)
594  *shared = datastore->sharedMem;
595 
596  if (maxid)
597  *maxid = datastore->maxid;
598 
599  if (maxmem)
600  *maxmem = datastore->maxmem;
601 }
602 
603 void smlDevInfDataStoreSetSyncCap(SmlDevInfDataStore *datastore, SmlDevInfSyncCap cap, SmlBool supported)
604 {
605  if (supported)
606  datastore->synccap = datastore->synccap | cap;
607  else
608  datastore->synccap = datastore->synccap & ~cap;
609 }
610 
611 SmlBool smlDevInfDataStoreGetSyncCap(const SmlDevInfDataStore *datastore, SmlDevInfSyncCap cap)
612 {
613  return datastore->synccap & cap ? TRUE : FALSE;
614 }
615 
616 void smlDevInfConfigureSession(SmlDevInf *devinf, SmlSession *session)
617 {
618  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, devinf, session);
619  smlAssert(devinf);
620  smlAssert(session);
621 
622  if (!devinf->supportsNumberOfChanges)
623  smlSessionUseNumberOfChanges(session, FALSE);
624 
625  if (!devinf->supportsLargeObjs)
626  smlSessionUseLargeObjects(session, FALSE);
627 
628  smlTrace(TRACE_EXIT, "%s", __func__);
629 }
630 
631 SmlBool smlDevInfAssemble(SmlDevInf *devinf, char **data, unsigned int *size, SmlError **error)
632 {
633  CHECK_ERROR_REF
634  return smlXmlDevInfAssemble(devinf, devinf->version, data, size, error);
635 }
636 
637 SmlCommand *smlDevInfNewResult(SmlCommand *cmd, SmlDevInf *devinf, SmlDevInfVersion version, SmlError **error)
638 {
639  smlTrace(TRACE_ENTRY, "%s(%p, %i, %p, %p)", __func__, cmd, devinf, version, error);
640  CHECK_ERROR_REF
641  smlAssert(cmd);
642  SmlLocation *source = NULL;
643 
644  char *data = NULL;
645  unsigned int size = 0;
646  if (!smlXmlDevInfAssemble(devinf, version, &data, &size, error))
647  goto error;
648 
649  if (version == SML_DEVINF_VERSION_10)
650  source = smlLocationNew("./devinf10", NULL, error);
651  else if (version == SML_DEVINF_VERSION_12)
652  source = smlLocationNew("./devinf12", NULL, error);
653  else
654  source = smlLocationNew("./devinf11", NULL, error);
655 
656  if (!source)
657  goto error_free_data;
658 
659  SmlCommand *result = smlCommandNewResult(cmd, source, data, size, SML_ELEMENT_DEVINF_XML, error);
660  if (!result) {
661  smlLocationUnref(source);
662  goto error_free_data;
663  }
664  /* Since the devinf is xml, we want to send it "raw" (without cdata) */
665  result->private.results.status->item->raw = TRUE;
666 
667  smlLocationUnref(source);
668 
669  smlTrace(TRACE_EXIT, "%s: %p", __func__, result);
670  return result;
671 
672 error_free_data:
673  smlSafeCFree(&data);
674 error:
675  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
676  return NULL;
677 }
678 
679 SmlCommand *smlDevInfNewPut(SmlDevInf *devinf, SmlDevInfVersion version, SmlError **error)
680 {
681  smlTrace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, devinf, version, error);
682  CHECK_ERROR_REF
683  smlAssert(devinf);
684  SmlLocation *source = NULL;
685 
686  // update version
687  if (devinf->version == SML_DEVINF_VERSION_UNKNOWN)
688  devinf->version = version;
689 
690  if (version == SML_DEVINF_VERSION_10)
691  source = smlLocationNew("./devinf10", NULL, error);
692  else if (version == SML_DEVINF_VERSION_12)
693  source = smlLocationNew("./devinf12", NULL, error);
694  else
695  source = smlLocationNew("./devinf11", NULL, error);
696 
697  if (!source)
698  goto error;
699 
700  SmlCommand *cmd = smlCommandNewPut(NULL, source, NULL, 0, SML_ELEMENT_DEVINF_XML, error);
701  if (!cmd)
702  goto error_free_source;
703 
704  smlLocationUnref(source);
705 
706  char *data = NULL;
707  unsigned int size = 0;
708  if (!smlXmlDevInfAssemble(devinf, version, &data, &size, error))
709  goto error_free_cmd;
710 
711  if (!smlItemAddData(cmd->private.access.item, data, size, error)) {
712  smlSafeCFree(&data);
713  goto error_free_cmd;
714  }
715  smlSafeCFree(&data);
716  smlItemSetRaw(cmd->private.access.item, TRUE);
717 
718  smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
719  return cmd;
720 
721 error_free_cmd:
722  smlCommandUnref(cmd);
723 error_free_source:
724  smlLocationUnref(source);
725 error:
726  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
727  return NULL;
728 }
729 
730 SmlCommand *smlDevInfNewGet(SmlDevInfVersion version, SmlError **error)
731 {
732  smlTrace(TRACE_ENTRY, "%s(%i, %p)", __func__, version, error);
733  CHECK_ERROR_REF
734  SmlLocation *target = NULL;
735 
736  if (version == SML_DEVINF_VERSION_10)
737  target = smlLocationNew("./devinf10", NULL, error);
738  else if (version == SML_DEVINF_VERSION_12)
739  target = smlLocationNew("./devinf12", NULL, error);
740  else
741  target = smlLocationNew("./devinf11", NULL, error);
742 
743  if (!target)
744  goto error;
745 
746  SmlCommand *cmd = smlCommandNewGet(target, SML_ELEMENT_DEVINF_XML, error);
747  if (!cmd)
748  goto error_free_target;
749 
750  smlLocationUnref(target);
751 
752  smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
753  return cmd;
754 
755 error_free_target:
756  smlLocationUnref(target);
757 error:
758  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
759  return NULL;
760 }
761 
762 SmlDevInf *smlDevInfParse(const char *data, unsigned int length, SmlError **error)
763 {
764  smlTrace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, data, length, error);
765  CHECK_ERROR_REF
766  smlAssert(data);
767  smlAssert(length);
768 
769  SmlDevInf *devinf = smlXmlDevInfParse(data, length, error);
770  if (!devinf)
771  goto error;
772 
773  smlTrace(TRACE_EXIT, "%s", __func__);
774  return devinf;
775 
776 error:
777  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
778  return NULL;
779 }
780 
781 SmlDevInf *smlDevInfFromResult(SmlCommand *result, SmlError **error)
782 {
783  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, result, error);
784  CHECK_ERROR_REF
785  smlAssert(result);
786 
787  if (result->type != SML_COMMAND_TYPE_RESULTS) {
788  smlErrorSet(error, SML_ERROR_GENERIC, "devinf command was not a result");
789  goto error;
790  }
791 
792  SmlItem *item = result->private.results.status->item;
793  if (!item) {
794  smlErrorSet(error, SML_ERROR_GENERIC, "devinf result did not have a item");
795  goto error;
796  }
797 
798  char *data = NULL;
799  unsigned int size = 0;
800  if (!smlItemGetData(item, &data, &size, error))
801  goto error;
802 
803  SmlDevInf *devinf = smlDevInfParse(data, size, error);
804  if (!devinf)
805  goto error;
806 
807  smlTrace(TRACE_EXIT, "%s", __func__);
808  return devinf;
809 
810 error:
811  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
812  return NULL;
813 }
814 
815 SmlDevInfCTCapType smlDevInfCTCapTypeFromString(const char *name, SmlError **error)
816 {
817  CHECK_ERROR_REF
818 
819  if (!strcmp(name, SML_ELEMENT_CTTYPE)) {
820  return SML_DEVINF_CTCAP_CTTYPE;
821  } else if (!strcmp(name, SML_ELEMENT_PROPNAME)) {
822  return SML_DEVINF_CTCAP_PROPNAME;
823  } else if (!strcmp(name, SML_ELEMENT_VALENUM)) {
824  return SML_DEVINF_CTCAP_VALENUM;
825  } else if (!strcmp(name, SML_ELEMENT_DATATYPE)) {
826  return SML_DEVINF_CTCAP_DATATYPE;
827  } else if (!strcmp(name, SML_ELEMENT_SIZE)) {
828  return SML_DEVINF_CTCAP_SIZE;
829  } else if (!strcmp(name, SML_ELEMENT_DISPLAYNAME)) {
830  return SML_DEVINF_CTCAP_DISPLAYNAME;
831  } else if (!strcmp(name, SML_ELEMENT_PARAMNAME)) {
832  return SML_DEVINF_CTCAP_PARAMNAME;
833  } else if (!strcmp(name, SML_ELEMENT_VERCT)) {
834  return SML_DEVINF_CTCAP_VERCT;
835  } else if (!strcmp(name, SML_ELEMENT_PROPERTY)) {
836  return SML_DEVINF_CTCAP_PROPERTY;
837  } else if (!strcmp(name, SML_ELEMENT_PROPPARAM)) {
838  return SML_DEVINF_CTCAP_PROPPARAM;
839  } else if (!strcmp(name, SML_ELEMENT_NOTRUNCATE)) {
840  return SML_DEVINF_CTCAP_NOTRUNCATE;
841  } else if (!strcmp(name, SML_ELEMENT_MAXOCCUR)) {
842  return SML_DEVINF_CTCAP_MAXOCCUR;
843  } else if (!strcmp(name, SML_ELEMENT_MAXSIZE)) {
844  return SML_DEVINF_CTCAP_MAXSIZE;
845  }
846 
847  smlErrorSet(error, SML_ERROR_GENERIC, "Unknown ctcap type name \"%s\"", name);
848  smlTrace(TRACE_ERROR, "%s - %s", __func__, smlErrorPrint(error));
849  return SML_DEVINF_CTCAP_UNKNOWN;
850 }
851 
852 
853 const char *smlDevInfCTCapTypeToString(SmlDevInfCTCapType type, SmlError **error)
854 {
855  CHECK_ERROR_REF
856 
857  switch (type) {
858  case SML_DEVINF_CTCAP_CTTYPE:
859  return SML_ELEMENT_CTTYPE;
860  case SML_DEVINF_CTCAP_PROPNAME:
861  return SML_ELEMENT_PROPNAME;
862  case SML_DEVINF_CTCAP_VALENUM:
863  return SML_ELEMENT_VALENUM;
864  case SML_DEVINF_CTCAP_DATATYPE:
865  return SML_ELEMENT_DATATYPE;
866  case SML_DEVINF_CTCAP_SIZE:
867  return SML_ELEMENT_SIZE;
868  case SML_DEVINF_CTCAP_DISPLAYNAME:
869  return SML_ELEMENT_DISPLAYNAME;
870  case SML_DEVINF_CTCAP_PARAMNAME:
871  return SML_ELEMENT_PARAMNAME;
872  case SML_DEVINF_CTCAP_NOTRUNCATE:
873  return SML_ELEMENT_NOTRUNCATE;
874  case SML_DEVINF_CTCAP_MAXOCCUR:
875  return SML_ELEMENT_MAXOCCUR;
876  case SML_DEVINF_CTCAP_VERCT:
877  return SML_ELEMENT_VERCT;
878  case SML_DEVINF_CTCAP_PROPERTY:
879  return SML_ELEMENT_PROPERTY;
880  case SML_DEVINF_CTCAP_PROPPARAM:
881  return SML_ELEMENT_PROPPARAM;
882  case SML_DEVINF_CTCAP_MAXSIZE:
883  return SML_ELEMENT_MAXSIZE;
884  case SML_DEVINF_CTCAP_UNKNOWN:
885  smlErrorSet(error, SML_ERROR_GENERIC, "Unknown ctcap type \"%i\"", type);
886  /* fall through! */
887  }
888 
889  return NULL;
890 }
891 
892 /* PropParam stuff */
893 
894 SmlDevInfPropParam *smlDevInfNewPropParam(SmlError **error)
895 {
896  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, error);
897  CHECK_ERROR_REF
898 
899  SmlDevInfPropParam *param = smlTryMalloc0(sizeof(SmlDevInfPropParam), error);
900  if (!param) {
901  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
902  return NULL;
903  }
904 
905  param->paramName = NULL;
906  param->dataType = NULL;
907  param->displayName = NULL;
908  param->valEnums = NULL;
909 
910  smlTrace(TRACE_EXIT, "%s", __func__);
911  return param;
912 }
913 
914 void smlDevInfPropParamSetParamName(
915  SmlDevInfPropParam *propParam,
916  const char *paramName)
917 {
918  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, propParam, VA_STRING(paramName));
919  smlAssert(propParam);
920  smlAssert(paramName);
921 
922  if (propParam->paramName != NULL)
923  smlSafeCFree(&(propParam->paramName));
924  propParam->paramName = g_strdup(paramName);
925 
926  smlTrace(TRACE_EXIT, "%s", __func__);
927 }
928 
929 void smlDevInfPropParamSetDataType(
930  SmlDevInfPropParam *propParam,
931  const char *dataType)
932 {
933  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, propParam, VA_STRING(dataType));
934  smlAssert(propParam);
935  smlAssert(dataType);
936 
937  if (propParam->dataType != NULL)
938  smlSafeCFree(&(propParam->dataType));
939  propParam->dataType = g_strdup(dataType);
940 
941  smlTrace(TRACE_EXIT, "%s", __func__);
942 }
943 
944 void smlDevInfPropParamSetDisplayName(
945  SmlDevInfPropParam *propParam,
946  const char *displayName)
947 {
948  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, propParam, VA_STRING(displayName));
949  smlAssert(propParam);
950  smlAssert(displayName);
951 
952  if (propParam->displayName != NULL)
953  smlSafeCFree(&(propParam->displayName));
954  propParam->displayName = g_strdup(displayName);
955 
956  smlTrace(TRACE_EXIT, "%s", __func__);
957 }
958 
959 void smlDevInfPropParamAddValEnum(
960  SmlDevInfPropParam *propParam,
961  const char *valEnum)
962 {
963  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, propParam, VA_STRING(valEnum));
964  smlAssert(propParam);
965  smlAssert(valEnum);
966  propParam->valEnums = g_list_append(propParam->valEnums, g_strdup(valEnum));
967  smlTrace(TRACE_EXIT, "%s", __func__);
968 }
969 
970 char *smlDevInfPropParamGetParamName(const SmlDevInfPropParam *propParam)
971 {
972  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, propParam);
973  smlAssert(propParam);
974  char *result = g_strdup(propParam->paramName);
975  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
976  return result;
977 }
978 
979 char *smlDevInfPropParamGetDataType(const SmlDevInfPropParam *propParam)
980 {
981  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, propParam);
982  smlAssert(propParam);
983  char *result = g_strdup(propParam->dataType);
984  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
985  return result;
986 }
987 
988 char *smlDevInfPropParamGetDisplayName(const SmlDevInfPropParam *propParam)
989 {
990  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, propParam);
991  smlAssert(propParam);
992  char *result = g_strdup(propParam->displayName);
993  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
994  return result;
995 }
996 
997 unsigned int smlDevInfPropParamNumValEnums(const SmlDevInfPropParam *propParam)
998 {
999  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, propParam);
1000  smlAssert(propParam);
1001  unsigned int num = g_list_length(propParam->valEnums);
1002  smlTrace(TRACE_EXIT, "%s - %d", __func__, num);
1003  return num;
1004 }
1005 
1006 char *smlDevInfPropParamGetNthValEnum(
1007  const SmlDevInfPropParam *propParam,
1008  unsigned int n)
1009 {
1010  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, propParam, n);
1011  smlAssert(propParam);
1012  char *result = g_strdup(g_list_nth_data(propParam->valEnums, n));
1013  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
1014  return result;
1015 }
1016 
1017 /* Property stuff */
1018 
1019 SmlDevInfProperty *smlDevInfNewProperty(SmlError **error)
1020 {
1021  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, error);
1022  CHECK_ERROR_REF
1023 
1024  SmlDevInfProperty *property = smlTryMalloc0(sizeof(SmlDevInfProperty), error);
1025  if (!property) {
1026  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
1027  return NULL;
1028  }
1029 
1030  property->propName = NULL;
1031  property->dataType = NULL;
1032  property->maxOccur = 0;
1033  property->maxSize = 0;
1034  property->noTruncate = FALSE;
1035  property->displayName = NULL;
1036  property->valEnums = NULL;
1037  property->propParams = NULL;
1038 
1039  smlTrace(TRACE_EXIT, "%s", __func__);
1040  return property;
1041 }
1042 
1043 void smlDevInfPropertySetPropName(
1044  SmlDevInfProperty *property,
1045  const char *propName)
1046 {
1047  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, property, VA_STRING(propName));
1048  smlAssert(property);
1049  smlAssert(propName);
1050 
1051  if (property->propName != NULL)
1052  smlSafeCFree(&(property->propName));
1053  property->propName = g_strdup(propName);
1054 
1055  smlTrace(TRACE_EXIT, "%s", __func__);
1056 }
1057 
1058 void smlDevInfPropertySetDataType(
1059  SmlDevInfProperty *property,
1060  const char *dataType)
1061 {
1062  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, property, VA_STRING(dataType));
1063  smlAssert(property);
1064  smlAssert(dataType);
1065 
1066  if (property->dataType != NULL)
1067  smlSafeCFree(&(property->dataType));
1068  property->dataType = g_strdup(dataType);
1069 
1070  smlTrace(TRACE_EXIT, "%s", __func__);
1071 }
1072 
1073 void smlDevInfPropertySetMaxOccur(
1074  SmlDevInfProperty *property,
1075  unsigned int maxOccur)
1076 {
1077  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, property, maxOccur);
1078  smlAssert(property);
1079 
1080  property->maxOccur = maxOccur;
1081 
1082  smlTrace(TRACE_EXIT, "%s", __func__);
1083 }
1084 
1085 void smlDevInfPropertySetMaxSize(
1086  SmlDevInfProperty *property,
1087  unsigned int maxSize)
1088 {
1089  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, property, maxSize);
1090  smlAssert(property);
1091 
1092  property->maxSize = maxSize;
1093 
1094  smlTrace(TRACE_EXIT, "%s", __func__);
1095 }
1096 
1097 void smlDevInfPropertySetPropSize(
1098  SmlDevInfProperty *property,
1099  unsigned int propSize)
1100 {
1101  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, property, propSize);
1102  smlAssert(property);
1103 
1104  property->propSize = propSize;
1105 
1106  smlTrace(TRACE_EXIT, "%s", __func__);
1107 }
1108 
1109 void smlDevInfPropertySetNoTruncate(
1110  SmlDevInfProperty *property)
1111 {
1112  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1113  smlAssert(property);
1114 
1115  property->noTruncate = TRUE;
1116 
1117  smlTrace(TRACE_EXIT, "%s", __func__);
1118 }
1119 
1120 void smlDevInfPropertySetDisplayName(
1121  SmlDevInfProperty *property,
1122  const char *displayName)
1123 {
1124  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, property, VA_STRING(displayName));
1125  smlAssert(property);
1126  smlAssert(displayName);
1127 
1128  if (property->displayName != NULL)
1129  smlSafeCFree(&(property->displayName));
1130  property->displayName = g_strdup(displayName);
1131 
1132  smlTrace(TRACE_EXIT, "%s", __func__);
1133 }
1134 
1135 void smlDevInfPropertyAddValEnum(
1136  SmlDevInfProperty *property,
1137  const char *valEnum)
1138 {
1139  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, property, VA_STRING(valEnum));
1140  smlAssert(property);
1141  smlAssert(valEnum);
1142  property->valEnums = g_list_append(property->valEnums, g_strdup(valEnum));
1143  smlTrace(TRACE_EXIT, "%s", __func__);
1144 }
1145 
1146 void smlDevInfPropertyAddPropParam(
1147  SmlDevInfProperty *property,
1148  SmlDevInfPropParam *propParam)
1149 {
1150  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, property, propParam);
1151  smlAssert(property);
1152  smlAssert(propParam);
1153  property->propParams = g_list_append(property->propParams, propParam);
1154  smlTrace(TRACE_EXIT, "%s", __func__);
1155 }
1156 
1157 char *smlDevInfPropertyGetPropName(const SmlDevInfProperty *property)
1158 {
1159  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1160  smlAssert(property);
1161  char *result = g_strdup(property->propName);
1162  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
1163  return result;
1164 }
1165 
1166 char *smlDevInfPropertyGetDataType(const SmlDevInfProperty *property)
1167 {
1168  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1169  smlAssert(property);
1170  char *result = g_strdup(property->dataType);
1171  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
1172  return result;
1173 }
1174 
1175 unsigned int smlDevInfPropertyGetMaxOccur(const SmlDevInfProperty *property)
1176 {
1177  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1178  smlAssert(property);
1179  smlTrace(TRACE_EXIT, "%s - %d", __func__, property->maxOccur);
1180  return property->maxOccur;
1181 }
1182 
1183 unsigned int smlDevInfPropertyGetMaxSize(const SmlDevInfProperty *property)
1184 {
1185  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1186  smlAssert(property);
1187  smlTrace(TRACE_EXIT, "%s - %d", __func__, property->maxSize);
1188  return property->maxSize;
1189 }
1190 
1191 SmlBool smlDevInfPropertyGetNoTruncate(const SmlDevInfProperty *property)
1192 {
1193  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1194  smlAssert(property);
1195  smlTrace(TRACE_EXIT, "%s - %d", __func__, property->noTruncate);
1196  return property->noTruncate;
1197 }
1198 
1199 char *smlDevInfPropertyGetDisplayName(const SmlDevInfProperty *property)
1200 {
1201  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1202  smlAssert(property);
1203  char *result = g_strdup(property->displayName);
1204  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
1205  return result;
1206 }
1207 
1208 unsigned int smlDevInfPropertyNumValEnums(const SmlDevInfProperty *property)
1209 {
1210  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1211  smlAssert(property);
1212  unsigned int num = g_list_length(property->valEnums);
1213  smlTrace(TRACE_EXIT, "%s - %d", __func__, num);
1214  return num;
1215 }
1216 
1217 char *smlDevInfPropertyGetNthValEnum(
1218  const SmlDevInfProperty *property,
1219  unsigned int n)
1220 {
1221  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, property, n);
1222  smlAssert(property);
1223  char *result = g_strdup(g_list_nth_data(property->valEnums, n));
1224  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(result));
1225  return result;
1226 }
1227 
1228 unsigned int smlDevInfPropertyNumPropParams(const SmlDevInfProperty *property)
1229 {
1230  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, property);
1231  smlAssert(property);
1232  unsigned int num = g_list_length(property->propParams);
1233  smlTrace(TRACE_EXIT, "%s - %d", __func__, num);
1234  return num;
1235 }
1236 
1237 const SmlDevInfPropParam *smlDevInfPropertyGetNthPropParam(
1238  const SmlDevInfProperty *property,
1239  unsigned int n)
1240 {
1241  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, property, n);
1242  smlAssert(property);
1243  SmlDevInfPropParam *param = g_list_nth_data(property->propParams, n);
1244  smlTrace(TRACE_EXIT, "%s - %p", __func__, param);
1245  return param;
1246 }
1247 
1248 /* CTCap stuff */
1249 
1250 SmlDevInfContentType *smlDevInfNewContentType(
1251  const char *cttype,
1252  const char *verct,
1253  SmlError **error)
1254 {
1255  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, error);
1256  CHECK_ERROR_REF
1257 
1259  if (!ct) {
1260  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
1261  return NULL;
1262  }
1263 
1264  if (cttype != NULL)
1265  ct->cttype = g_strdup(cttype);
1266  else
1267  ct->cttype = NULL;
1268  if (verct != NULL)
1269  ct->verct = g_strdup(verct);
1270  else
1271  ct->verct = NULL;
1272 
1273  smlTrace(TRACE_EXIT, "%s", __func__);
1274  return ct;
1275 }
1276 
1277 char *smlDevInfContentTypeGetCTType(const SmlDevInfContentType *ct)
1278 {
1279  return g_strdup(ct->cttype);
1280 }
1281 
1282 char *smlDevInfContentTypeGetVerCT(const SmlDevInfContentType *ct)
1283 {
1284  return g_strdup(ct->verct);
1285 }
1286 
1287 void smlDevInfFreeContentType(SmlDevInfContentType *ct)
1288 {
1289  smlTrace(TRACE_ENTRY, "%s", __func__);
1290  smlAssert(ct);
1291 
1292  if (ct->cttype != NULL)
1293  smlSafeCFree(&(ct->cttype));
1294  if (ct->verct != NULL)
1295  smlSafeCFree(&(ct->verct));
1296  smlSafeFree((gpointer *)&ct);
1297 
1298  smlTrace(TRACE_EXIT, "%s", __func__);
1299 }
1300 
1301 SmlDevInfCTCap *smlDevInfNewCTCap(SmlError **error)
1302 {
1303  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, error);
1304  CHECK_ERROR_REF
1305 
1306  SmlDevInfCTCap *ctcap = smlTryMalloc0(sizeof(SmlDevInfCTCap), error);
1307  if (!ctcap) {
1308  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
1309  return NULL;
1310  }
1311 
1312  ctcap->ct = smlDevInfNewContentType(NULL, NULL, error);
1313  if (!ctcap->ct) {
1314  smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
1315  smlSafeFree((gpointer *)&ctcap);
1316  return NULL;
1317  }
1318  ctcap->properties = NULL;
1319 
1320  smlTrace(TRACE_EXIT, "%s", __func__);
1321  return ctcap;
1322 }
1323 
1324 void smlDevInfCTCapSetCTType(
1325  SmlDevInfCTCap *ctcap,
1326  const char *cttype)
1327 {
1328  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, ctcap, VA_STRING(cttype));
1329  smlAssert(ctcap);
1330  smlAssert(cttype);
1331 
1332  ctcap->ct->cttype = g_strdup(cttype);
1333 
1334  smlTrace(TRACE_EXIT, "%s", __func__);
1335 }
1336 
1337 void smlDevInfCTCapSetVerCT(
1338  SmlDevInfCTCap *ctcap,
1339  const char *verct)
1340 {
1341  smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, ctcap, VA_STRING(verct));
1342  smlAssert(ctcap);
1343  smlAssert(verct);
1344 
1345  ctcap->ct->verct = g_strdup(verct);
1346 
1347  smlTrace(TRACE_EXIT, "%s", __func__);
1348 }
1349 
1350 char *smlDevInfCTCapGetCTType(const SmlDevInfCTCap *ctcap)
1351 {
1352  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, ctcap);
1353  smlAssert(ctcap);
1354  char *cttype;
1355 
1356  cttype = g_strdup(ctcap->ct->cttype);
1357 
1358  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(cttype));
1359  return cttype;
1360 }
1361 
1362 char *smlDevInfCTCapGetVerCT(const SmlDevInfCTCap *ctcap)
1363 {
1364  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, ctcap);
1365  smlAssert(ctcap);
1366  char *verct;
1367 
1368  verct = g_strdup(ctcap->ct->verct);
1369 
1370  smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(verct));
1371  return verct;
1372 }
1373 
1374 void smlDevInfCTCapAddProperty(
1375  SmlDevInfCTCap *ctcap,
1376  SmlDevInfProperty *property)
1377 {
1378  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctcap, property);
1379  smlAssert(ctcap);
1380  smlAssert(property);
1381  ctcap->properties = g_list_append(ctcap->properties, property);
1382  smlTrace(TRACE_EXIT, "%s", __func__);
1383 }
1384 
1385 void smlDevInfAppendCTCap(SmlDevInf *devinf, SmlDevInfCTCap *ctcap)
1386 {
1387  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, devinf, ctcap);
1388  smlAssert(devinf);
1389  smlAssert(ctcap);
1390  devinf->ctcaps = g_list_append(devinf->ctcaps, ctcap);
1391  smlTrace(TRACE_EXIT, "%s", __func__);
1392 }
1393 
1394 /* FIXME: DEPRECATED*/
1395 void smlDevInfAddCTCap(SmlDevInf *devinf, SmlDevInfCTCapType type, const char *value)
1396 {
1397  SmlDevInfCTCap *ctcap = smlDevInfNewCTCap(NULL);
1398  smlDevInfCTCapSetCTType(ctcap, smlDevInfCTCapTypeToString(type, NULL));
1399  smlDevInfCTCapSetVerCT(ctcap, value);
1400  smlDevInfAppendCTCap(devinf, ctcap);
1401 }
1402 
1403 /* FIXME: DEPRECATED*/
1404 SmlDevInfCTCapType smlDevInfGetNthCTCapType(SmlDevInf *devinf, unsigned int nth)
1405 {
1406  const SmlDevInfCTCap *ctcap = smlDevInfGetNthCTCap(devinf, nth);
1407  char *type = smlDevInfCTCapGetCTType(ctcap);
1408  SmlError *error = NULL;
1409  SmlDevInfCTCapType cttype = smlDevInfCTCapTypeFromString(type, &error);
1410  smlSafeCFree(&type);
1411  return cttype;
1412 }
1413 
1414 /* FIXME: DEPRECATED*/
1415 const char *smlDevInfGetNthCTCapValue(SmlDevInf *devinf, unsigned int nth)
1416 {
1417  const SmlDevInfCTCap *ctcap = smlDevInfGetNthCTCap(devinf, nth);
1418  return smlDevInfCTCapGetVerCT(ctcap);
1419 }
1420 
1421 const SmlDevInfCTCap *smlDevInfGetCTCap(
1422  const SmlDevInf *devinf,
1424 {
1425  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, devinf, ct);
1426  smlAssert(devinf);
1427  smlAssert(ct);
1428  smlAssert(ct->cttype);
1429  smlAssert(ct->verct);
1430 
1431  GList *h;
1432  for (h = devinf->ctcaps; h; h = h->next)
1433  {
1434  SmlDevInfCTCap *ctcap = h->data;
1435  // check that CTType matches
1436  if (!strcmp(ct->cttype, ctcap->ct->cttype) &&
1437  !strcmp(ct->verct, ctcap->ct->verct))
1438  {
1439  smlTrace(TRACE_EXIT, "%s - succeeded", __func__);
1440  return ctcap;
1441  }
1442  }
1443  smlTrace(TRACE_EXIT, "%s - nothing found", __func__);
1444  return NULL;
1445 }
1446 
1447 unsigned int smlDevInfNumCTCaps(const SmlDevInf *devinf)
1448 {
1449  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, devinf);
1450  smlAssert(devinf);
1451  unsigned int num = g_list_length(devinf->ctcaps);
1452  smlTrace(TRACE_EXIT, "%s - %d", __func__, num);
1453  return num;
1454 }
1455 
1456 const SmlDevInfCTCap *smlDevInfGetNthCTCap(
1457  const SmlDevInf *devinf,
1458  unsigned int n)
1459 {
1460  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, devinf, n);
1461  smlAssert(devinf);
1462  SmlDevInfCTCap *ctcap = g_list_nth_data(devinf->ctcaps, n);
1463  smlTrace(TRACE_EXIT, "%s - %p", __func__, ctcap);
1464  return ctcap;
1465 }
1466 
1467 unsigned int smlDevInfCTCapNumProperties(const SmlDevInfCTCap *ctcap)
1468 {
1469  smlTrace(TRACE_ENTRY, "%s(%p)", __func__, ctcap);
1470  smlAssert(ctcap);
1471  unsigned int num = g_list_length(ctcap->properties);
1472  smlTrace(TRACE_EXIT, "%s - %d", __func__, num);
1473  return num;
1474 }
1475 
1476 const SmlDevInfProperty *smlDevInfCTCapGetNthProperty(
1477  const SmlDevInfCTCap *ctcap,
1478  unsigned int n)
1479 {
1480  smlTrace(TRACE_ENTRY, "%s(%p, %d)", __func__, ctcap, n);
1481  smlAssert(ctcap);
1482  SmlDevInfProperty *property = g_list_nth_data(ctcap->properties, n);
1483  smlTrace(TRACE_EXIT, "%s - %p", __func__, property);
1484  return property;
1485 }
1486 
1487 SmlDevInfSyncCap smlDevInfSyncCapConvert(unsigned int id, SmlError **error)
1488 {
1489  smlTrace(TRACE_ENTRY, "%s(%u, %p)", __func__, id, error);
1490  CHECK_ERROR_REF
1491  SmlDevInfSyncCap result = SML_DEVINF_SYNCTYPE_UNKNOWN;
1492 
1493  switch (id)
1494  {
1495  case SML_DEVINF_SYNCTYPE_TWO_WAY:
1496  result = SML_DEVINF_SYNCTYPE_TWO_WAY;
1497  break;
1498  case SML_DEVINF_SYNCTYPE_SLOW_SYNC:
1499  result = SML_DEVINF_SYNCTYPE_SLOW_SYNC;
1500  break;
1501  case SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT:
1502  result = SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT;
1503  break;
1504  case SML_DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT:
1505  result = SML_DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT;
1506  break;
1507  case SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER:
1508  result = SML_DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER;
1509  break;
1510  case SML_DEVINF_SYNCTYPE_REFRESH_FROM_SERVER:
1511  result = SML_DEVINF_SYNCTYPE_REFRESH_FROM_SERVER;
1512  break;
1513  case SML_DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC:
1514  result = SML_DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC;
1515  break;
1516  default:
1517  smlErrorSet(error, SML_ERROR_GENERIC,
1518  "The synchronization type %u is unknwon.", id);
1519  smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error));
1520  return SML_DEVINF_SYNCTYPE_UNKNOWN;
1521  break;
1522  }
1523  smlTrace(TRACE_EXIT, "%s - %u", __func__, result);
1524  return result;
1525 }
1526 
const char * smlErrorPrint(SmlError **error)
Returns the message of the error.
Definition: sml_error.c:299
SmlBool smlItemGetData(SmlItem *item, char **data, unsigned int *size, SmlError **error)
Definition: sml_elements.c:495
void smlTrace(SmlTraceType type, const char *message,...)
Used for tracing the application.
Definition: sml_support.c:120
void * smlTryMalloc0(long n_bytes, SmlError **error)
Safely mallocs.
Definition: sml_support.c:335
void smlErrorSet(SmlError **error, SmlErrorType type, const char *format,...)
Sets the error.
Definition: sml_error.c:355
Represent an error.