47 size_t size = strlen(newtext) + 1;
48 tp->text = realloc(tp->text, size);
49 memcpy(tp->text, newtext, size);
54 bp->bloblen = blobsize;
71 snprintf(configDir,
MAXRBUF-1,
"%s/.indi/", getenv(
"HOME"));
73 if (getenv(
"INDICONFIG"))
74 snprintf(configFileName,
MAXRBUF,
"%s", getenv(
"INDICONFIG"));
76 snprintf(configFileName,
MAXRBUF-1,
"%s%s_config.xml", configDir,
device);
79 if (stat(configDir, &st) != 0)
82 if (mkdir(configDir) != 0)
84 if (mkdir(configDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0)
89 int statResult = stat(configFileName, &st);
94 SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
95 PSID AdministratorsGroup;
96 if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup))
98 if (CheckTokenMembership(NULL, AdministratorsGroup, &isAdmin) ==
FALSE)
100 FreeSid(AdministratorsGroup);
102 if ((st.st_uid == 0 && st.st_mode & S_IFDIR) || (st.st_gid == 0 && isAdmin ==
TRUE))
107 if (statResult == 0 && st.st_uid == 0 && getuid() != 0)
111 fp = fopen(configFileName,
"r");
130 int foundCounter = 0;
140 if (
crackDN(ep, &rdev, &rname, errmsg) < 0)
147 if (strcmp(nvp->
device, rdev))
150 if (!strcmp(nvp->
name, rname))
174 int foundCounter = 0;
184 if (
crackDN(ep, &rdev, &rname, errmsg) < 0)
191 if (strcmp(tvp->
device, rdev))
194 if (!strcmp(tvp->
name, rname))
218 int foundCounter = 0;
228 if (
crackDN(ep, &rdev, &rname, errmsg) < 0)
235 if (strcmp(svp->
device, rdev))
238 if (!strcmp(svp->
name, rname))
267 for (
int i = 0; i < tvp->
ntp; i++)
268 if (strcmp(tvp->
tp[i].
name, name) == 0)
269 return (&tvp->
tp[i]);
270 fprintf(stderr,
"No IText '%s' in %s.%s\n", name, tvp->
device, tvp->
name);
277 for (
int i = 0; i < nvp->
nnp; i++)
278 if (strcmp(nvp->
np[i].
name, name) == 0)
279 return (&nvp->
np[i]);
280 fprintf(stderr,
"No INumber '%s' in %s.%s\n", name, nvp->
device, nvp->
name);
287 for (
int i = 0; i < svp->
nsp; i++)
288 if (strcmp(svp->
sp[i].
name, name) == 0)
289 return (&svp->
sp[i]);
290 fprintf(stderr,
"No ISwitch '%s' in %s.%s\n", name, svp->
device, svp->
name);
297 for (
int i = 0; i < lvp->
nlp; i++)
298 if (strcmp(lvp->
lp[i].
name, name) == 0)
299 return (&lvp->
lp[i]);
300 fprintf(stderr,
"No ILight '%s' in %s.%s\n", name, lvp->
device, lvp->
name);
307 for (
int i = 0; i < bvp->
nbp; i++)
308 if (strcmp(bvp->
bp[i].
name, name) == 0)
309 return (&bvp->
bp[i]);
310 fprintf(stderr,
"No IBLOB '%s' in %s.%s\n", name, bvp->
device, bvp->
name);
319 for (
int i = 0; i < svp->
nsp; i++)
321 return (&svp->
sp[i]);
328 for (
int i = 0; i < (int)n; i++)
330 if (!strcmp(hay[i], needle))
339 for (
int i = 0; i < svp->
nsp; i++)
348 for (
int i = 0; i < n; i++)
357 for (
int i = 0; i < n; i++)
368 for (
int i = 0; i < svp->
nsp; i++)
378 indi_strlcpy(sp->name, name,
sizeof(sp->name));
380 indi_strlcpy(sp->label, label[0] ? label : name,
sizeof(sp->label));
389 indi_strlcpy(lp->name, name,
sizeof(lp->name));
391 indi_strlcpy(lp->label, label[0] ? label : name,
sizeof(lp->label));
399 double step,
double value)
401 indi_strlcpy(np->name, name,
sizeof(np->name));
403 indi_strlcpy(np->label, label[0] ? label : name,
sizeof(np->label));
405 indi_strlcpy(np->format, format,
sizeof(np->format));
416void IUFillText(
IText *tp,
const char *name,
const char *label,
const char *initialText)
418 indi_strlcpy(tp->name, name,
sizeof(tp->name));
420 indi_strlcpy(tp->label, label[0] ? label : name,
sizeof(tp->label));
422 if (tp->text && tp->text[0])
430 if (initialText && initialText[0])
436 memset(bp, 0,
sizeof(
IBLOB));
438 indi_strlcpy(bp->name, name,
sizeof(bp->name));
440 indi_strlcpy(bp->label, label[0] ? label : name,
sizeof(bp->label));
442 indi_strlcpy(bp->format, format,
sizeof(bp->format));
458 indi_strlcpy(svp->
name, name,
sizeof(svp->
name));
460 indi_strlcpy(svp->
label, label[0] ? label : name,
sizeof(svp->
label));
462 indi_strlcpy(svp->
group, group,
sizeof(svp->
group));
474 const char *label,
const char *group,
IPState s)
478 indi_strlcpy(lvp->
name, name,
sizeof(lvp->
name));
480 indi_strlcpy(lvp->
label, label[0] ? label : name,
sizeof(lvp->
label));
482 indi_strlcpy(lvp->
group, group,
sizeof(lvp->
group));
491 const char *label,
const char *group,
IPerm p,
double timeout,
IPState s)
495 indi_strlcpy(nvp->
name, name,
sizeof(nvp->
name));
497 indi_strlcpy(nvp->
label, label[0] ? label : name,
sizeof(nvp->
label));
499 indi_strlcpy(nvp->
group, group,
sizeof(nvp->
group));
510 const char *label,
const char *group,
IPerm p,
double timeout,
IPState s)
514 indi_strlcpy(tvp->
name, name,
sizeof(tvp->
name));
516 indi_strlcpy(tvp->
label, label[0] ? label : name,
sizeof(tvp->
label));
518 indi_strlcpy(tvp->
group, group,
sizeof(tvp->
group));
529 const char *label,
const char *group,
IPerm p,
double timeout,
IPState s)
534 indi_strlcpy(bvp->
name, name,
sizeof(bvp->
name));
536 indi_strlcpy(bvp->
label, label[0] ? label : name,
sizeof(bvp->
label));
538 indi_strlcpy(bvp->
group, group,
sizeof(bvp->
group));
561 if (strcmp(
tagXMLEle(root) + 3,
"NumberVector") ||
crackDN(root, &dev, &name, NULL) < 0)
563 if (strcmp(dev, nvp->
device) || strcmp(name, nvp->
name))
569 for (
int i = 0; i < nvp->
nnp; i++)
577 indi_locale_C_numeric_pop(orig);
585 indi_locale_C_numeric_pop(orig);
589 indi_locale_C_numeric_pop(orig);
606 if (strcmp(
tagXMLEle(root) + 3,
"TextVector") ||
crackDN(root, &dev, &name, NULL) < 0)
608 if (strcmp(dev, tvp->
device) || strcmp(name, tvp->
name))
613 for (
int i = 0; i < tvp->
ntp; i++)
642 if (strcmp(
tagXMLEle(root) + 3,
"LightVector") ||
crackDN(root, &dev, &name, NULL) < 0)
644 if (strcmp(dev, lvp->
device) || strcmp(name, lvp->
name))
655 for (
int i = 0; i < lvp->
nlp; i++)
657 if (!strcmp(lvp->
lp[i].
name, name))
684 if (strcmp(
tagXMLEle(root) + 3,
"SwitchVector") ||
crackDN(root, &dev, &name, NULL) < 0)
686 if (strcmp(dev, svp->
device) || strcmp(name, svp->
name))
693 if (!strcmp(
tagXMLEle(ep) + 3,
"Switch"))
696 for (
int i = 0; i < svp->
nsp; i++)
698 if (!strcmp(svp->
sp[i].
name, name))
726 if (strcmp(
tagXMLEle(root),
"setBLOBVector") ||
crackDN(root, &dev, &name, NULL) < 0)
729 if (strcmp(dev, bvp->
device) || strcmp(name, bvp->
name))
736 if (strcmp(
tagXMLEle(ep),
"oneBLOB") == 0)
752 assert_mem(bp->blob = realloc(bp->blob, 3 * base64datalen / 4));
795 if (!strcmp(str,
"Idle"))
797 else if (!strncmp(str,
"Ok", 2))
799 else if (!strcmp(str,
"Busy"))
801 else if (!strcmp(str,
"Alert"))
810 if (!strncmp(str,
"On", 2))
812 else if (!strcmp(str,
"Off"))
821 if (!strncmp(str,
"rw", 2))
823 else if (!strncmp(str,
"ro", 2))
825 else if (!strncmp(str,
"wo", 2))
834 if (!strcmp(str,
"OneOfMany"))
836 else if (!strcmp(str,
"AtMostOne"))
838 else if (!strcmp(str,
"AnyOfMany"))
858 fprintf(stderr,
"Impossible IPState %d\n", s);
872 fprintf(stderr,
"Impossible ISState %d\n", s);
888 fprintf(stderr,
"Impossible ISRule %d\n", r);
904 fprintf(stderr,
"Impossible IPerm %d\n", p);
int from64tobits_fast(char *out, const char *in, int inlen)
#define assert_mem(p)
Bails out if memory pointer is 0. Prints file and function.
IPerm
Permission hint, with respect to client.
ISRule
Switch vector rule hint.
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
Implementations for common driver routines.
int IUSnoopSwitch(XMLEle *root, ISwitchVectorProperty *svp)
Update a snooped switch vector property from the given XML root element.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
void IUFillLight(ILight *lp, const char *name, const char *label, IPState s)
Assign attributes for a light property. The light's auxiliary elements will be set to NULL.
int IULoadConfigSwitch(const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
IText * IUFindText(const ITextVectorProperty *tvp, const char *name)
Find an IText member in a vector text property.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
const char * ruleStr(ISRule r)
ILight * IUFindLight(const ILightVectorProperty *lvp, const char *name)
Find an ILight member in a vector Light property.
int IULoadConfigNumber(const INumberVectorProperty *nvp)
Load a number vector property value from the configuration file.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
void IUFillLightVector(ILightVectorProperty *lvp, ILight *lp, int nlp, const char *dev, const char *name, const char *label, const char *group, IPState s)
Assign attributes for a light vector property. The vector's auxiliary elements will be set to NULL.
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
int IUFindIndex(const char *needle, char **hay, unsigned int n)
Returns the index of the string in a string array.
int IUSnoopBLOB(XMLEle *root, IBLOBVectorProperty *bvp)
Update a snooped BLOB vector property from the given XML root element.
int crackDN(XMLEle *root, char **dev, char **name, char msg[])
Extract dev and name attributes from an XML element.
int IUSnoopLight(XMLEle *root, ILightVectorProperty *lvp)
Update a snooped light vector property from the given XML root element.
ISwitch * IUFindSwitch(const ISwitchVectorProperty *svp, const char *name)
Find an ISwitch member in a vector switch property.
int IUSaveBLOB(IBLOB *bp, int size, int blobsize, char *blob, char *format)
Function to save blob metadata in the corresponding blob.
void IUSaveConfigBLOB(FILE *fp, const IBLOBVectorProperty *bvp)
Add a BLOB vector property value to the configuration file.
int IUSnoopText(XMLEle *root, ITextVectorProperty *tvp)
Update a snooped text vector property from the given XML root element.
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
int IUSnoopNumber(XMLEle *root, INumberVectorProperty *nvp)
Update a snooped number vector property from the given XML root element.
XMLEle * configRootFP(const char *device)
const char * sstateStr(ISState s)
const char * permStr(IPerm p)
IBLOB * IUFindBLOB(const IBLOBVectorProperty *bvp, const char *name)
Find an IBLOB member in a vector BLOB property.
void xmlv1()
print the boilerplate comment introducing xml
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
ISwitch * IUFindOnSwitch(const ISwitchVectorProperty *svp)
Returns the first ON switch it finds in the vector switch property.
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
int crackIPerm(const char *str, IPerm *ip)
Extract property permission state (RW, RO, WO) from the supplied string.
void IUSaveConfigText(FILE *fp, const ITextVectorProperty *tvp)
Add a text vector property value to the configuration file.
int crackIPState(const char *str, IPState *ip)
Extract property state (Idle, OK, Busy, Alert) from the supplied string.
const char * pstateStr(IPState s)
int IULoadConfigText(const ITextVectorProperty *tvp)
Load a text vector property value from the configuration file.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
void IUFillBLOBVector(IBLOBVectorProperty *bvp, IBLOB *bp, int nbp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a BLOB vector property. The vector's auxiliary elements will be set to NULL.
void IUFillBLOB(IBLOB *bp, const char *name, const char *label, const char *format)
Assign attributes for a BLOB property. The BLOB's data and auxiliary elements will be set to NULL.
int crackISRule(const char *str, ISRule *ip)
Extract switch rule (OneOfMany, OnlyOne..etc) from the supplied string.
const char * IUFindOnSwitchName(ISState *states, char *names[], int n)
Returns the name of the first ON switch it finds in the supplied arguments.
int crackISState(const char *str, ISState *ip)
Extract switch state (On or Off) from the supplied string.
int IUFindOnStateIndex(ISState *states, int n)
Returns the index of first ON switch it finds in the ISState array.
Interface to the reference INDI C API device implementation on the Device Driver side.
void IUUserIONewBLOB(const userio *io, void *user, const IBLOBVectorProperty *bvp)
void IUUserIONewSwitchFull(const userio *io, void *user, const ISwitchVectorProperty *svp)
void IUUserIONewText(const userio *io, void *user, const ITextVectorProperty *tvp)
void IUUserIONewNumber(const userio *io, void *user, const INumberVectorProperty *nvp)
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
XMLAtt * findXMLAtt(XMLEle *ep, const char *name)
Find an XML attribute within an XML element.
LilXML * newLilXML()
Create a new lilxml parser.
char * tagXMLEle(XMLEle *ep)
Return the tag of an XML element.
char * valuXMLAtt(XMLAtt *ap)
Return the value of an XML attribute.
void delXMLEle(XMLEle *ep)
delXMLEle Delete XML element.
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
void delLilXML(LilXML *lp)
Delete a lilxml parser.
XMLEle * readXMLFile(FILE *fp, LilXML *lp, char ynot[])
Handy wrapper to read one xml file.
int pcdatalenXMLEle(XMLEle *ep)
Return the number of characters in pcdata in an XML element.
One Blob (Binary Large Object) descriptor.
BLOB (Binary Large Object) vector property descriptor.
char timestamp[MAXINDITSTAMP]
char device[MAXINDIDEVICE]
Light vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
Number vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
Switch vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
Text vector property descriptor.
char device[MAXINDIDEVICE]
char timestamp[MAXINDITSTAMP]
void userio_xmlv1(const userio *io, void *user)
const struct userio * userio_file()