static int Command_setattr(twopence_Command *self, char *name, PyObject *v) { if (!strcmp(name, "stdout")) { if (v != Py_None && !PyByteArray_Check(v)) goto bad_attr; assign_object(&self->stdout, v); return 0; } if (!strcmp(name, "stderr")) { if (v != Py_None && !PyByteArray_Check(v)) goto bad_attr; assign_object(&self->stderr, v); return 0; } if (!strcmp(name, "user")) { char *s; if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL) goto bad_attr; assign_string(&self->user, s); return 0; } if (!strcmp(name, "timeout")) { if (PyInt_Check(v)) self->timeout = PyInt_AsLong(v); else if (PyLong_Check(v)) self->timeout = PyLong_AsLongLong(v); else goto bad_attr; return 0; } if (!strcmp(name, "quiet")) { self->quiet = !!(PyObject_IsTrue(v)); return 0; } if (!strcmp(name, "useTty")) { self->useTty = !!(PyObject_IsTrue(v)); return 0; } if (!strcmp(name, "background")) { self->background = !!(PyObject_IsTrue(v)); return 0; } (void) PyErr_Format(PyExc_AttributeError, "Unknown attribute: %s", name); return -1; bad_attr: (void) PyErr_Format(PyExc_AttributeError, "Incompatible value for attribute: %s", name); return -1; }
static int Transfer_setattr(twopence_Transfer *self, char *name, PyObject *v) { if (!strcmp(name, "remotefile")) { char *s; if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL) goto bad_attr; assign_string(&self->remote_filename, s); return 0; } if (!strcmp(name, "localfile")) { char *s; if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL) goto bad_attr; assign_string(&self->local_filename, s); return 0; } if (!strcmp(name, "user")) { char *s; if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL) goto bad_attr; assign_string(&self->user, s); return 0; } if (!strcmp(name, "permissions")) { if (!PyInt_Check(v)) goto bad_attr; self->permissions = PyInt_AsLong(v); return 0; } if (!strcmp(name, "timeout")) { if (!PyInt_Check(v)) goto bad_attr; self->timeout = PyInt_AsLong(v); return 0; } if (!strcmp(name, "data")) { if (v != Py_None && !PyByteArray_Check(v)) goto bad_attr; assign_object(&self->buffer, v); return 0; } (void) PyErr_Format(PyExc_AttributeError, "Unknown attribute: %s", name); return -1; bad_attr: (void) PyErr_Format(PyExc_AttributeError, "Incompatible value for attribute: %s", name); return -1; }
Object * clone(Objid pid) { Object *o; int top; if (pid.server != 0 || pid.id < 0) { return 0; } else { top = dbtop() + 1; set_dbtop(top); o = new_object(); o->id.server = 0; o->id.id = top; sym_init(o); o->parents = list_new(1); o->parents->el[0].type = OBJ; o->parents->el[0].v.obj = pid; assign_object(o->id, o); return o; } }
/* * Returns: -1 nothing, 0 OK, >0 error */ static int nv_split(char *buf, lnode *n, int lineno) { char *ptr, *ptr2; ptr = strtok(buf, " "); if (ptr == NULL) return -1; /* If there's nothing, go to next line */ if (ptr[0] == '#') return -1; /* If there's a comment, go to next line */ // Load decision n->d = dec_name_to_val(ptr); if ((int)n->d == -1) { msg(LOG_ERR, "Invalid decision (%s) in line %d", ptr, lineno); return 1; } while ((ptr = strtok(NULL, " "))) { int type; ptr2 = strchr(ptr, '='); if (ptr2) { *ptr2 = 0; ptr2++; type = subj_name_to_val(ptr); if (type == -1) { type = obj_name_to_val(ptr); if (type == -1) { msg(LOG_ERR, "Field type (%s) is unknown in line %d", ptr, lineno); return 2; } else assign_object(n, type, ptr2, lineno); } else assign_subject(n, type, ptr2, lineno); } else if (strcasecmp(ptr, "all") == 0) { if (n->s_count == 0) { type = ALL_SUBJ; assign_subject(n, type, "", lineno); } else if (n->o_count == 0) { type = ALL_OBJ; assign_object(n, type, "", lineno); } else { msg(LOG_ERR, "All can only be used in place of a subject or object"); return 3; } } else { msg(LOG_ERR, "'=' is missing for field %s, in line %d", ptr, lineno); return 4; } } // do one last sanity check for missing subj or obj if (n->s_count == 0) { msg(LOG_ERR, "Subject is missing in line %d", lineno); return 5; } if (n->o_count == 0) { msg(LOG_ERR, "Object is missing in line %d", lineno); return 6; } return 0; }