/*=====================================================================================================*/ int main( void ) { u8 TrData[10] = {0}; u8 RrData[7] = {0}; GPIO_Config(); USART1_Init(); while(1) { USART_WriteString((u8*)"Waiting for cmommand!\r\n"); USART_ReceiveStdString(RrData,sizeof(RrData)); USART_WriteString((u8*)"USART Received: "); USART_WriteString(RrData); USART_WriteString((u8*)"\n\r"); if(STR_CMP(RrData,str1,6)) { USART_WriteString((u8*)"Relay1 toggle\n\r"); OUT1 = ~OUT1; LED_B = ~LED_B; } else if(STR_CMP(RrData,str2,6)) { USART_WriteString((u8*)"Relay2 toggle\n\r"); OUT2 = ~OUT2; LED_R = ~LED_R; } LED_G = ~LED_G; } }
extern int base_compare (Entity* e1, Entity* e2){ Vtype vtype = e1->_vtype; int ret; switch (vtype) { case EINT: NUM_CMP(e1->_data.ie, e2->_data.ie); case EFLOAT: NUM_CMP(e1->_data.fe, e2->_data.fe); case ESTRING: STR_CMP(e1->_data.string, e2->_data.string); case EPOINTER: return e1->_data.pointer == e2->_data.pointer ? 0: -2; } }
static int write_shadow(TFILE *fp, MYLDAP_ENTRY *entry, const char *requser, uid_t calleruid) { int32_t tmpint32; const char **usernames; const char *passwd; long lastchangedate; long mindays; long maxdays; long warndays; long inactdays; long expiredate; unsigned long flag; int i; char passbuffer[BUFLEN_PASSWORDHASH]; /* get username */ usernames = myldap_get_values(entry, attmap_shadow_uid); if ((usernames == NULL) || (usernames[0] == NULL)) { log_log(LOG_WARNING, "%s: %s: missing", myldap_get_dn(entry), attmap_shadow_uid); return 0; } /* get password */ passwd = get_userpassword(entry, attmap_shadow_userPassword, passbuffer, sizeof(passbuffer)); if ((passwd == NULL) || (calleruid != 0)) passwd = default_shadow_userPassword; /* get expiry properties */ get_shadow_properties(entry, &lastchangedate, &mindays, &maxdays, &warndays, &inactdays, &expiredate, &flag); /* write the entries */ for (i = 0; usernames[i] != NULL; i++) if ((requser == NULL) || (STR_CMP(requser, usernames[i]) == 0)) { WRITE_INT32(fp, NSLCD_RESULT_BEGIN); WRITE_STRING(fp, usernames[i]); WRITE_STRING(fp, passwd); WRITE_INT32(fp, lastchangedate); WRITE_INT32(fp, mindays); WRITE_INT32(fp, maxdays); WRITE_INT32(fp, warndays); WRITE_INT32(fp, inactdays); WRITE_INT32(fp, expiredate); WRITE_INT32(fp, flag); } return 0; }
static void scan_object(EdbusConnection *conn, EdbusMessage &msg, const char *service, const char *path, ObjectTree *self) { EdbusMessage reply; msg.create_method_call(service, path, INTROSPECTABLE_INTERFACE, INTROSPECTABLE_METHOD); if(!conn->send_with_reply_and_block(msg, 1000, reply)) { E_WARNING(E_STRLOC ": Did not get reply from service bus. Skipping introspection of '%s' service (object path: '%s')\n", service, path); return; } /* reply must be single element and string, which is xml */ if(reply.size() != 1) { E_WARNING(E_STRLOC ": Expected only one element, but got '%i'\n", reply.size()); return; } EdbusMessage::const_iterator it = reply.begin(); if(!it->is_string()) { E_WARNING(E_STRLOC ": Expected string in reply, but got some junk\n"); return; } TiXmlDocument doc; char buf[128]; Fl_Tree_Item *titem; doc.Parse(it->to_string()); TiXmlNode *el = doc.FirstChild("node"); if(!el) return; for(el = el->FirstChildElement(); el; el = el->NextSibling()) { /* we have subobjects */ if(STR_CMP_VALUE(el, "node")) { const char *name = el->ToElement()->Attribute("name"); if(!name) { E_DEBUG(E_STRLOC ": <node> is expected to have 'name' attribute\n"); continue; } /* TODO: maybe use EdbusObjectPath? */ if(strcmp(path, "/") == 0) snprintf(buf, sizeof(buf), "/%s", name); else snprintf(buf, sizeof(buf), "%s/%s", path, name); titem = self->add(buf); self->close(titem); titem->usericon(&image_package); /* recurse */ scan_object(conn, msg, service, buf, self); } else if(STR_CMP_VALUE(el, "interface")) { /* full interface: get methods and properties */ const char *interface_name, *name = el->ToElement()->Attribute("name"); /* remember it for Entity */ interface_name = name; if(!name) { E_DEBUG(E_STRLOC ": <interface> is expected to have 'name' attribute\n"); continue; } /* append interface to tree */ snprintf(buf, sizeof(buf), "%s/%s", path, name); titem = self->add(buf); self->close(titem); titem->usericon(&image_interface); /* append methods, signals and properties */ TiXmlNode *sel; char buf2[256]; Fl_Pixmap *icon; EntityType et; for(sel = el->FirstChildElement(); sel; sel = sel->NextSibling()) { if(STR_CMP_VALUE(sel, "method")) { icon = &image_method; et = ENTITY_METHOD; } else if(STR_CMP_VALUE(sel, "signal")) { icon = &image_signal; et = ENTITY_SIGNAL; } else if(STR_CMP_VALUE(sel, "property")) { icon = &image_property; et = ENTITY_PROPERTY; } else { E_WARNING(E_STRLOC ": Got unknown node '%s'. Skipping...\n", sel->Value()); continue; } /* everything else are common elements between different types */ name = sel->ToElement()->Attribute("name"); snprintf(buf2, sizeof(buf2), "%s/%s", buf, name); titem = self->add(buf2); titem->usericon(icon); self->close(titem); /* fill our metadata */ Entity *en = new Entity(); en->set_type(et); en->set_name(name); en->set_interface(interface_name); en->set_path(path); /* TODO: this doesn't have to be copied */ en->set_service(service); if(et == ENTITY_PROPERTY) { const char *argstype, *argsname, *argsaccess; argstype = sel->ToElement()->Attribute("type"); argsname = sel->ToElement()->Attribute("name"); argsaccess = sel->ToElement()->Attribute("access"); en->append_arg(argsname, argstype, DIRECTION_NONE, argsaccess); } else { TiXmlNode *argsnode; for(argsnode = sel->FirstChildElement(); argsnode; argsnode = argsnode->NextSibling()) { if(STR_CMP_VALUE(argsnode, "arg")) { /* arguments */ const char *argstype, *argsname, *argsdirection; ArgDirection dir = DIRECTION_NONE; argstype = argsnode->ToElement()->Attribute("type"); if(!argstype) continue; argsname = argsnode->ToElement()->Attribute("name"); if(!argsname) continue; /* it is fine to not have direction, which means it is only a method */ argsdirection = argsnode->ToElement()->Attribute("direction"); if(argsdirection) { if(STR_CMP(argsdirection, "in")) dir = DIRECTION_IN; else if(STR_CMP(argsdirection, "out")) dir = DIRECTION_OUT; } en->append_arg(argsname, argstype, dir); } else if(STR_CMP_VALUE(argsnode, "annotation")) { const char *annoname, *argsval; annoname = argsnode->ToElement()->Attribute("name"); /* allow whatever annotation name ending with '.DocString' to be supported (e.g. org.gtk.GDBus.DocString or org.equinoxproject.DBus.DocString) */ if(!str_ends(annoname, ".DocString")) { E_WARNING(E_STRLOC ": We are supporting now only DocString annotations. Skipping '%s'...\n", annoname); continue; } argsval = argsnode->ToElement()->Attribute("value"); if(argsval) en->set_doc(argsval); } } } /* put it inside our tree so we can manage it */ self->append_entity(en); /* add also inside Fl_Tree_Item */ titem->user_data(en); } } } }
static int write_protocol(TFILE *fp, MYLDAP_ENTRY *entry, const char *reqname) { int32_t tmpint32, tmp2int32, tmp3int32; const char *name; const char **aliases; const char **protos; char *tmp; long proto; int i; /* get the most canonical name */ name = myldap_get_rdn_value(entry, attmap_protocol_cn); /* get the other names for the protocol */ aliases = myldap_get_values(entry, attmap_protocol_cn); if ((aliases == NULL) || (aliases[0] == NULL)) { log_log(LOG_WARNING, "%s: %s: missing", myldap_get_dn(entry), attmap_protocol_cn); return 0; } /* if the protocol name is not yet found, get the first entry */ if (name == NULL) name = aliases[0]; /* check case of returned protocol entry */ if ((reqname != NULL) && (STR_CMP(reqname, name) != 0)) { for (i = 0; (aliases[i] != NULL) && (STR_CMP(reqname, aliases[i]) != 0); i++) /* nothing */ ; if (aliases[i] == NULL) return 0; /* neither the name nor any of the aliases matched */ } /* get the protocol number */ protos = myldap_get_values(entry, attmap_protocol_ipProtocolNumber); if ((protos == NULL) || (protos[0] == NULL)) { log_log(LOG_WARNING, "%s: %s: missing", myldap_get_dn(entry), attmap_protocol_ipProtocolNumber); return 0; } else if (protos[1] != NULL) { log_log(LOG_WARNING, "%s: %s: multiple values", myldap_get_dn(entry), attmap_protocol_ipProtocolNumber); } errno = 0; proto = strtol(protos[0], &tmp, 10); if ((*(protos[0]) == '\0') || (*tmp != '\0')) { log_log(LOG_WARNING, "%s: %s: non-numeric", myldap_get_dn(entry), attmap_protocol_ipProtocolNumber); return 0; } else if ((errno != 0) || (proto < 0) || (proto > (long)UINT8_MAX)) { log_log(LOG_WARNING, "%s: %s: out of range", myldap_get_dn(entry), attmap_protocol_ipProtocolNumber); return 0; } /* write entry */ WRITE_INT32(fp, NSLCD_RESULT_BEGIN); WRITE_STRING(fp, name); WRITE_STRINGLIST_EXCEPT(fp, aliases, name); /* proto number is actually an 8-bit value but we write 32 bits anyway */ WRITE_INT32(fp, proto); return 0; }
EdbusErrorType from_dbus_errorstr(const char* msg) { if(!msg) return EDBUS_ERROR_INVALID; if(STR_CMP(msg, DBUS_ERROR_FAILED)) return EDBUS_ERROR_FAILED; if(STR_CMP(msg, DBUS_ERROR_NO_MEMORY)) return EDBUS_ERROR_NO_MEMORY; if(STR_CMP(msg, DBUS_ERROR_SERVICE_UNKNOWN)) return EDBUS_ERROR_SERVICE_UNKNOWN; if(STR_CMP(msg, DBUS_ERROR_NAME_HAS_NO_OWNER)) return EDBUS_ERROR_NAME_HAS_NO_OWNER; if(STR_CMP(msg, DBUS_ERROR_NO_REPLY)) return EDBUS_ERROR_NO_REPLY; if(STR_CMP(msg, DBUS_ERROR_IO_ERROR)) return EDBUS_ERROR_IO_ERROR; if(STR_CMP(msg, DBUS_ERROR_BAD_ADDRESS)) return EDBUS_ERROR_BAD_ADDRESS; if(STR_CMP(msg, DBUS_ERROR_NOT_SUPPORTED)) return EDBUS_ERROR_NOT_SUPPORTED; if(STR_CMP(msg, DBUS_ERROR_LIMITS_EXCEEDED)) return EDBUS_ERROR_LIMITS_EXCEEDED; if(STR_CMP(msg, DBUS_ERROR_ACCESS_DENIED)) return EDBUS_ERROR_ACCESS_DENIED; if(STR_CMP(msg, DBUS_ERROR_AUTH_FAILED)) return EDBUS_ERROR_AUTH_FAILED; if(STR_CMP(msg, DBUS_ERROR_NO_SERVER)) return EDBUS_ERROR_NO_SERVER; if(STR_CMP(msg, DBUS_ERROR_TIMEOUT)) return EDBUS_ERROR_TIMEOUT; if(STR_CMP(msg, DBUS_ERROR_NO_NETWORK)) return EDBUS_ERROR_NO_NETWORK; if(STR_CMP(msg, DBUS_ERROR_DISCONNECTED)) return EDBUS_ERROR_DISCONNECTED; if(STR_CMP(msg, DBUS_ERROR_INVALID_ARGS)) return EDBUS_ERROR_INVALID_ARGS; if(STR_CMP(msg, DBUS_ERROR_FILE_NOT_FOUND)) return EDBUS_ERROR_FILE_NOT_FOUND; if(STR_CMP(msg, DBUS_ERROR_FILE_EXISTS)) return EDBUS_ERROR_FILE_EXISTS; if(STR_CMP(msg, DBUS_ERROR_UNKNOWN_METHOD)) return EDBUS_ERROR_UNKNOWN_METHOD; if(STR_CMP(msg, DBUS_ERROR_TIMED_OUT)) return EDBUS_ERROR_TIMED_OUT; if(STR_CMP(msg, DBUS_ERROR_INVALID_SIGNATURE)) return EDBUS_ERROR_INVALID_SIGNATURE; return EDBUS_ERROR_INVALID; }
/* write a single rpc entry to the stream */ static int write_rpc(TFILE *fp, MYLDAP_ENTRY *entry, const char *reqname) { int32_t tmpint32, tmp2int32, tmp3int32; const char *name; const char **aliases; const char **numbers; char *tmp; unsigned long number; int i; /* get the most canonical name */ name = myldap_get_rdn_value(entry, attmap_rpc_cn); /* get the other names for the rpc entries */ aliases = myldap_get_values(entry, attmap_rpc_cn); if ((aliases == NULL) || (aliases[0] == NULL)) { log_log(LOG_WARNING, "%s: %s: missing", myldap_get_dn(entry), attmap_rpc_cn); return 0; } /* if the rpc name is not yet found, get the first entry */ if (name == NULL) name = aliases[0]; /* check case of returned rpc entry */ if ((reqname != NULL) && (STR_CMP(reqname, name) != 0)) { for (i = 0; (aliases[i] != NULL) && (STR_CMP(reqname, aliases[i]) != 0); i++) /* nothing */ ; if (aliases[i] == NULL) return 0; /* neither the name nor any of the aliases matched */ } /* get the rpc number */ numbers = myldap_get_values(entry, attmap_rpc_oncRpcNumber); if ((numbers == NULL) || (numbers[0] == NULL)) { log_log(LOG_WARNING, "%s: %s: missing", myldap_get_dn(entry), attmap_rpc_oncRpcNumber); return 0; } else if (numbers[1] != NULL) { log_log(LOG_WARNING, "%s: %s: multiple values", myldap_get_dn(entry), attmap_rpc_oncRpcNumber); } errno = 0; number = strtol(numbers[0], &tmp, 10); if ((*(numbers[0]) == '\0') || (*tmp != '\0')) { log_log(LOG_WARNING, "%s: %s: non-numeric", myldap_get_dn(entry), attmap_rpc_oncRpcNumber); return 0; } else if ((errno != 0) || (number > UINT32_MAX)) { log_log(LOG_WARNING, "%s: %s: out of range", myldap_get_dn(entry), attmap_rpc_oncRpcNumber); return 0; } /* write the entry */ WRITE_INT32(fp, NSLCD_RESULT_BEGIN); WRITE_STRING(fp, name); WRITE_STRINGLIST_EXCEPT(fp, aliases, name); WRITE_INT32(fp, number); return 0; }