int MemoryEntryFromPython(PyObject * dict, GSM_MemoryEntry * entry, int needs_location) { PyObject *o; PyObject *item; Py_ssize_t len, data_len; Py_ssize_t i; char *type, *location; char valuetype; const char *bmptype; if (!PyDict_Check(dict)) { PyErr_Format(PyExc_ValueError, "Memory entry is not a dictionary"); return 0; } memset(entry, 0, sizeof(GSM_MemoryEntry)); entry->Location = GetIntFromDict(dict, "Location"); if (entry->Location == INT_INVALID) { if (needs_location) { return 0; } PyErr_Clear(); } entry->MemoryType = GetMemoryTypeFromDict(dict, "MemoryType"); if (entry->MemoryType == ENUM_INVALID) { if (needs_location) { return 0; } PyErr_Clear(); } o = PyDict_GetItemString(dict, "Entries"); if (o == NULL) { PyErr_Format(PyExc_ValueError, "Can not get string value for key Entries"); return 0; } if (!PyList_Check(o)) { PyErr_Format(PyExc_ValueError, "Key Entries doesn't contain list"); return 0; } len = PyList_Size(o); if (len > GSM_PHONEBOOK_ENTRIES) { pyg_warning("Using just %i entries from list!", GSM_PHONEBOOK_ENTRIES); len = GSM_PHONEBOOK_ENTRIES; } entry->EntriesNum = len; for (i = 0; i < len; i++) { item = PyList_GetItem(o, i); if (item == NULL) return 0; if (!PyDict_Check(item)) { PyErr_Format(PyExc_ValueError, "Element %" PY_FORMAT_SIZE_T "d in Entries is not dictionary", i); return 0; } type = GetCharFromDict(item, "Type"); if (type == NULL) return 0; location = GetCharFromDict(item, "Location"); if (location == NULL) { entry->Entries[i].Location = PBK_Location_Unknown; } else { if (strcmp(location, "Home") == 0) { entry->Entries[i].Location = PBK_Location_Home; } else if (strcmp(location, "Work") == 0) { entry->Entries[i].Location = PBK_Location_Work; } else { entry->Entries[i].Location = PBK_Location_Unknown; } } /* Zero everything, just to be sure */ entry->Entries[i].Text[0] = 0; entry->Entries[i].Text[1] = 0; entry->Entries[i].SMSList[0] = 0; entry->Entries[i].Number = 0; /* Get VoiceTag flag */ entry->Entries[i].VoiceTag = GetIntFromDict(item, "VoiceTag"); if (entry->Entries[i].VoiceTag == INT_INVALID) { entry->Entries[i].VoiceTag = 0; PyErr_Clear(); } /* Get AddError flag */ entry->Entries[i].AddError = GetIntFromDict(item, "AddError"); if (entry->Entries[i].AddError == INT_INVALID) { entry->Entries[i].AddError = ERR_NONE; PyErr_Clear(); } if (strcmp("Number_General", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_General; } else if (strcmp("Number_Mobile_Work", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Mobile; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Number_Mobile_Home", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Mobile; entry->Entries[i].Location = PBK_Location_Home; } else if (strcmp("Number_Mobile", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Mobile; } else if (strcmp("Number_Work", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_General; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Number_Fax", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Fax; } else if (strcmp("Number_Home", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_General; entry->Entries[i].Location = PBK_Location_Home; } else if (strcmp("Number_Pager", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Pager; } else if (strcmp("Number_Other", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Other; } else if (strcmp("Number_Messaging", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Messaging; } else if (strcmp("Number_Video", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Number_Video; } else if (strcmp("Text_Note", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Note; } else if (strcmp("Text_Postal", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Postal; } else if (strcmp("Text_WorkPostal", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Postal; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Text_Email", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Email; } else if (strcmp("Text_Email2", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Email2; } else if (strcmp("Text_URL", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_URL; } else if (strcmp("Date", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = PBK_Date; } else if (strcmp("LastModified", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = PBK_LastModified; } else if (strcmp("Caller_Group", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = PBK_Caller_Group; } else if (strcmp("Text_Name", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Name; } else if (strcmp("Text_LastName", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_LastName; } else if (strcmp("Text_FirstName", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_FirstName; } else if (strcmp("Text_SecondName", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_SecondName; } else if (strcmp("Text_NickName", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_NickName; } else if (strcmp("Text_FormalName", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_FormalName; } else if (strcmp("Text_NameSuffix", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_NameSuffix; } else if (strcmp("Text_NamePrefix", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_NamePrefix; } else if (strcmp("Text_Company", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Company; } else if (strcmp("Text_JobTitle", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_JobTitle; } else if (strcmp("Category", type) == 0) { valuetype = 'o'; entry->Entries[i].EntryType = PBK_Category; } else if (strcmp("Private", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = PBK_Private; } else if (strcmp("Text_StreetAddress", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_StreetAddress; } else if (strcmp("Text_City", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_City; } else if (strcmp("Text_State", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_State; } else if (strcmp("Text_Zip", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Zip; } else if (strcmp("Text_Country", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Country; } else if (strcmp("Text_WorkStreetAddress", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_StreetAddress; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Text_WorkCity", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_City; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Text_WorkState", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_State; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Text_WorkZip", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Zip; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Text_WorkCountry", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Country; entry->Entries[i].Location = PBK_Location_Work; } else if (strcmp("Text_Custom1", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Custom1; } else if (strcmp("Text_Custom2", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Custom2; } else if (strcmp("Text_Custom3", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Custom3; } else if (strcmp("Text_Custom4", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_Custom4; } else if (strcmp("Text_LUID", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_LUID; } else if (strcmp("Text_VOIP", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_VOIP; } else if (strcmp("Text_SWIS", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_SWIS; } else if (strcmp("Text_WVID", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_WVID; } else if (strcmp("Text_SIP", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_SIP; } else if (strcmp("Text_DTMF", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_DTMF; } else if (strcmp("Text_UserID", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_UserID; } else if (strcmp("Text_PictureName", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_Text_PictureName; } else if (strcmp("RingtoneID", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = PBK_RingtoneID; } else if (strcmp("PictureID", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = PBK_PictureID; } else if (strcmp("CallLength", type) == 0) { valuetype = 'c'; entry->Entries[i].EntryType = PBK_CallLength; } else if (strcmp("PushToTalkID", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = PBK_PushToTalkID; } else if (strcmp("Photo", type) == 0) { valuetype = 'p'; entry->Entries[i].EntryType = PBK_Photo; } else { PyErr_Format(PyExc_ValueError, "Element %" PY_FORMAT_SIZE_T "d in Entries has bad type: %s", i, type); return 0; } switch (valuetype) { case 'o': entry->Entries[i].Number = GetIntFromDict(item, "Value"); if (entry->Entries[i].Number == INT_INVALID) { PyErr_Clear(); if (!CopyStringFromDict (item, "Value", GSM_PHONEBOOK_TEXT_LENGTH, entry->Entries[i].Text)) return 0; } break; case 'n': entry->Entries[i].Number = GetIntFromDict(item, "Value"); if (entry->Entries[i].Number == INT_INVALID) return 0; break; case 'c': entry->Entries[i].CallLength = GetIntFromDict(item, "Value"); if (entry->Entries[i].CallLength == INT_INVALID) return 0; break; case 't': if (!CopyStringFromDict (item, "Value", GSM_PHONEBOOK_TEXT_LENGTH, entry->Entries[i].Text)) return 0; break; case 'd': entry->Entries[i].Date = GetDateTimeFromDict(item, "Value"); if (entry->Entries[i].Date.Year == -1) return 0; break; case 'p': entry->Entries[i].Picture.Buffer = (unsigned char *) GetCStringLengthFromDict(item, "Value", &data_len); entry->Entries[i].Picture.Length = data_len; if (entry->Entries[i].Picture.Buffer == NULL) { return 0; } bmptype = GetCStringFromDict(item, "PictureType"); if (strcmp(bmptype, "BMP") == 0) { entry->Entries[i].Picture.Type = PICTURE_BMP; } else if (strcmp(bmptype, "GIF") == 0) { entry->Entries[i].Picture.Type = PICTURE_GIF; } else if (strcmp(bmptype, "JPG") == 0) { entry->Entries[i].Picture.Type = PICTURE_JPG; } else if (strcmp(bmptype, "ICN") == 0) { entry->Entries[i].Picture.Type = PICTURE_ICN; } else if (strcmp(bmptype, "PNG") == 0) { entry->Entries[i].Picture.Type = PICTURE_PNG; } else { entry->Entries[i].Picture.Type = 0; } break; } } /* end for */ return 1; }
int CalendarFromPython(PyObject * dict, GSM_CalendarEntry * entry, int needs_location) { PyObject *o; PyObject *item; Py_ssize_t len; Py_ssize_t i; char *t; char *type; char valuetype; if (!PyDict_Check(dict)) { PyErr_Format(PyExc_ValueError, "Calendar entry is not a dictionary"); return 0; } memset(entry, 0, sizeof(GSM_CalendarEntry)); if (needs_location) { entry->Location = GetIntFromDict(dict, "Location"); if (entry->Location == INT_INVALID) return 0; } t = GetCharFromDict(dict, "Type"); if (t == NULL) return 0; entry->Type = StringToCalendarType(t); free(t); if (entry->Type == 0) return 0; o = PyDict_GetItemString(dict, "Entries"); if (o == NULL) { PyErr_Format(PyExc_ValueError, "Can not get string value for key Values"); return 0; } if (!PyList_Check(o)) { PyErr_Format(PyExc_ValueError, "Key Values doesn't contain list"); return 0; } len = PyList_Size(o); if (len > GSM_CALENDAR_ENTRIES) { pyg_warning("Using just %i entries from list!", GSM_CALENDAR_ENTRIES); len = GSM_CALENDAR_ENTRIES; } entry->EntriesNum = len; for (i = 0; i < len; i++) { item = PyList_GetItem(o, i); if (item == NULL) return 0; if (!PyDict_Check(item)) { PyErr_Format(PyExc_ValueError, "Element %" PY_FORMAT_SIZE_T "d in Values is not dictionary", i); return 0; } type = GetCharFromDict(item, "Type"); if (type == NULL) return 0; if (strcmp("START_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = CAL_START_DATETIME; } else if (strcmp("END_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = CAL_END_DATETIME; } else if (strcmp("TONE_ALARM_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = CAL_TONE_ALARM_DATETIME; } else if (strcmp("SILENT_ALARM_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = CAL_SILENT_ALARM_DATETIME; } else if (strcmp("LAST_MODIFIED", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = CAL_LAST_MODIFIED; } else if (strcmp("REPEAT_STARTDATE", type) == 0) { valuetype = 'D'; entry->Entries[i].EntryType = CAL_REPEAT_STARTDATE; } else if (strcmp("REPEAT_STOPDATE", type) == 0) { valuetype = 'D'; entry->Entries[i].EntryType = CAL_REPEAT_STOPDATE; } else if (strcmp("TEXT", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = CAL_TEXT; } else if (strcmp("DESCRIPTION", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = CAL_DESCRIPTION; } else if (strcmp("LUID", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = CAL_LUID; } else if (strcmp("LOCATION", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = CAL_LOCATION; } else if (strcmp("PHONE", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = CAL_PHONE; } else if (strcmp("PRIVATE", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_PRIVATE; } else if (strcmp("CONTACTID", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_CONTACTID; } else if (strcmp("REPEAT_DAYOFWEEK", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_REPEAT_DAYOFWEEK; } else if (strcmp("REPEAT_DAY", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_REPEAT_DAY; } else if (strcmp("REPEAT_WEEKOFMONTH", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_REPEAT_WEEKOFMONTH; } else if (strcmp("REPEAT_MONTH", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_REPEAT_MONTH; } else if (strcmp("REPEAT_FREQUENCY", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_REPEAT_FREQUENCY; } else if (strcmp("REPEAT_COUNT", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_REPEAT_COUNT; } else if (strcmp("REPEAT_DAYOFYEAR", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = CAL_REPEAT_DAYOFYEAR; } else { PyErr_Format(PyExc_ValueError, "Element %" PY_FORMAT_SIZE_T "d in Values has bad type: %s", i, type); free(type); return 0; } free(type); switch (valuetype) { case 'n': entry->Entries[i].Number = GetIntFromDict(item, "Value"); if (entry->Entries[i].Number == INT_INVALID) return 0; break; case 't': if (!CopyStringFromDict (item, "Value", GSM_PHONEBOOK_TEXT_LENGTH, entry->Entries[i].Text)) return 0; break; case 'D': entry->Entries[i].Date = GetDateFromDict(item, "Value"); if (entry->Entries[i].Date.Year == -1) return 0; break; case 'd': entry->Entries[i].Date = GetDateTimeFromDict(item, "Value"); if (entry->Entries[i].Date.Year == -1) return 0; break; } /* Clear AddError flag */ entry->Entries[i].AddError = ERR_NONE; } /* end for */ return 1; }
int TodoFromPython(PyObject * dict, GSM_ToDoEntry * entry, int needs_location) { PyObject *o; PyObject *item; Py_ssize_t len; Py_ssize_t i; char *p; char *t; char *type; char valuetype; if (!PyDict_Check(dict)) { PyErr_Format(PyExc_ValueError, "Todo entry is not a dictionary"); return 0; } memset(entry, 0, sizeof(GSM_ToDoEntry)); if (needs_location) { entry->Location = GetIntFromDict(dict, "Location"); if (entry->Location == INT_INVALID) return 0; } t = GetCharFromDict(dict, "Type"); if (t == NULL) return 0; entry->Type = StringToCalendarType(t); free(t); if (entry->Type == 0) return 0; p = GetCharFromDict(dict, "Priority"); if (p == NULL) return 0; entry->Priority = StringToTodoPriority(p); free(p); if (entry->Priority == GSM_Priority_INVALID) return 0; o = PyDict_GetItemString(dict, "Entries"); if (o == NULL) { PyErr_Format(PyExc_ValueError, "Can not get string value for key Values"); return 0; } if (!PyList_Check(o)) { PyErr_Format(PyExc_ValueError, "Key Values doesn't contain list"); return 0; } len = PyList_Size(o); if (len > GSM_TODO_ENTRIES) { pyg_warning("Using just %i entries from list!", GSM_TODO_ENTRIES); len = GSM_TODO_ENTRIES; } entry->EntriesNum = len; for (i = 0; i < len; i++) { item = PyList_GetItem(o, i); if (item == NULL) return 0; if (!PyDict_Check(item)) { PyErr_Format(PyExc_ValueError, "Element %" PY_FORMAT_SIZE_T "d in Values is not dictionary", i); return 0; } type = GetCharFromDict(item, "Type"); if (type == NULL) return 0; if (strcmp("END_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = TODO_END_DATETIME; } else if (strcmp("START_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = TODO_START_DATETIME; } else if (strcmp("COMPLETED_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = TODO_COMPLETED_DATETIME; } else if (strcmp("COMPLETED", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = TODO_COMPLETED; } else if (strcmp("ALARM_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = TODO_ALARM_DATETIME; } else if (strcmp("SILENT_ALARM_DATETIME", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = TODO_SILENT_ALARM_DATETIME; } else if (strcmp("LAST_MODIFIED", type) == 0) { valuetype = 'd'; entry->Entries[i].EntryType = TODO_LAST_MODIFIED; } else if (strcmp("LUID", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = TODO_LUID; } else if (strcmp("LOCATION", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = TODO_LOCATION; } else if (strcmp("DESCRIPTION", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = TODO_DESCRIPTION; } else if (strcmp("TEXT", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = TODO_TEXT; } else if (strcmp("PRIVATE", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = TODO_PRIVATE; } else if (strcmp("CATEGORY", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = TODO_CATEGORY; } else if (strcmp("CONTACTID", type) == 0) { valuetype = 'n'; entry->Entries[i].EntryType = TODO_CONTACTID; } else if (strcmp("PHONE", type) == 0) { valuetype = 't'; entry->Entries[i].EntryType = TODO_PHONE; } else { PyErr_Format(PyExc_ValueError, "Element %" PY_FORMAT_SIZE_T "d in Values has bad type: %s", i, type); free(type); return 0; } free(type); switch (valuetype) { case 'n': entry->Entries[i].Number = GetIntFromDict(item, "Value"); if (entry->Entries[i].Number == INT_INVALID) return 0; break; case 't': if (!CopyStringFromDict (item, "Value", GSM_PHONEBOOK_TEXT_LENGTH, entry->Entries[i].Text)) return 0; break; case 'd': entry->Entries[i].Date = GetDateTimeFromDict(item, "Value"); if (entry->Entries[i].Date.Year == -1) return 0; break; } } /* end for */ return 1; }
int FileFromPython(PyObject * dict, GSM_File * file, gboolean check) { char *s; GSM_DateTime nulldt = { 0, 0, 0, 0, 0, 0, 0 }; Py_ssize_t i; if (!PyDict_Check(dict)) { PyErr_Format(PyExc_ValueError, "File is not a dictionary"); return 0; } memset(file, 0, sizeof(file)); if ((file->Used = GetIntFromDict(dict, "Used")) == INT_INVALID) { // We don't need Used in all cases, we can get size from buffer PyErr_Clear(); } if (!CopyStringFromDict(dict, "Name", 300, file->Name)) { if (check) { return 0; } else { PyErr_Clear(); } } if ((i = GetIntFromDict(dict, "Folder")) == INT_INVALID) { if (check) { return 0; } else { PyErr_Clear(); } } else { file->Folder = i; } if ((file->Level = GetIntFromDict(dict, "Level")) == INT_INVALID) { if (check) { return 0; } else { PyErr_Clear(); } } s = GetCharFromDict(dict, "Type"); if (s == NULL) { file->Type = 0; if (check) { return 0; } else { PyErr_Clear(); } } else { file->Type = StringToFileType(s); if (file->Type == ENUM_INVALID) return 0; } if (!CopyStringFromDict(dict, "ID_FullName", 800, file->ID_FullName)) { if (check) { return 0; } else { PyErr_Clear(); } } s = GetDataFromDict(dict, "Buffer", &i); if (s == NULL) { file->Buffer = NULL; file->Used = 0; if (check) { return 0; } else { PyErr_Clear(); } } else { if (file->Used == INT_INVALID) { file->Used = i; } else if (file->Used != (size_t) i) { PyErr_Format(PyExc_ValueError, "Used and Buffer size mismatch in File (%li != %" PY_FORMAT_SIZE_T "i)!", (long)file->Used, i); return 0; } file->Buffer = (unsigned char *)malloc(i * sizeof(unsigned char)); if (file->Buffer == NULL) { PyErr_Format(PyExc_MemoryError, "Not enough memory to allocate buffer (wanted %li bytes)", (long)(i * sizeof(unsigned char))); return 0; } memcpy(file->Buffer, s, i); } file->Modified = GetDateTimeFromDict(dict, "Modified"); if (file->Modified.Year == -1) { file->Modified = nulldt; file->ModifiedEmpty = TRUE; PyErr_Clear(); } else { file->ModifiedEmpty = FALSE; } if ((i = GetIntFromDict(dict, "Protected")) == INT_INVALID) { if (check) { free(file->Buffer); file->Buffer = NULL; return 0; } else { PyErr_Clear(); } } else { file->Protected = i; } if ((i = GetIntFromDict(dict, "ReadOnly")) == INT_INVALID) { if (check) { free(file->Buffer); file->Buffer = NULL; return 0; } else { PyErr_Clear(); } } else { file->ReadOnly = i; } if ((i = GetIntFromDict(dict, "Hidden")) == INT_INVALID) { if (check) { free(file->Buffer); file->Buffer = NULL; return 0; } else { PyErr_Clear(); } } else { file->Hidden = i; } if ((i = GetIntFromDict(dict, "System")) == INT_INVALID) { if (check) { free(file->Buffer); file->Buffer = NULL; return 0; } else { PyErr_Clear(); } } else { file->System = i; } return 1; }