PyObject *MemoryEntryToPython(const GSM_MemoryEntry * entry) { PyObject *v; PyObject *f; PyObject *r; PyObject *d; PyObject *l; int i; int j; Py_UNICODE *s; char *t; const GSM_BinaryPicture *bitmap; const char *bmptype; v = PyList_New(0); if (v == NULL) return NULL; for (i = 0; i < entry->EntriesNum; i++) { f = Py_None; switch (entry->Entries[i].EntryType) { case PBK_Number_General: convert_number("General"); break; case PBK_Number_Mobile: convert_number("Mobile"); break; case PBK_Number_Fax: convert_number("Fax"); break; case PBK_Number_Pager: convert_number("Pager"); break; case PBK_Number_Other: convert_number("Other"); break; case PBK_Text_Note: convert_text("Text_Note"); break; case PBK_Text_Postal: convert_text("Text_Postal"); break; case PBK_Text_Email: convert_text("Text_Email"); break; case PBK_Text_Email2: convert_text("Text_Email2"); break; case PBK_Text_URL: convert_text("Text_URL"); break; case PBK_Date: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "Date", "Value", d); Py_DECREF(d); break; case PBK_LastModified: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "LastModified", "Value", d); Py_DECREF(d); break; case PBK_Caller_Group: f = Py_BuildValue("{s:s,s:i}", "Type", "Caller_Group", "Value", entry->Entries[i].Number); break; case PBK_Text_Name: convert_text("Text_Name"); break; case PBK_Text_LastName: convert_text("Text_LastName"); break; case PBK_Text_FirstName: convert_text("Text_FirstName"); break; case PBK_Text_SecondName: convert_text("Text_SecondName"); break; case PBK_Text_NickName: convert_text("Text_NickName"); break; case PBK_Text_FormalName: convert_text("Text_FormalName"); break; case PBK_Text_NamePrefix: convert_text("Text_NamePrefix"); break; case PBK_Text_NameSuffix: convert_text("Text_NameSuffix"); break; case PBK_Text_Company: convert_text("Text_Company"); break; case PBK_Text_JobTitle: convert_text("Text_JobTitle"); break; case PBK_Category: if (entry->Entries[i].Number == -1) { convert_text("Category"); } else { f = Py_BuildValue("{s:s,s:i}", "Type", "Category", "Value", entry->Entries[i]. Number); } break; case PBK_Private: f = Py_BuildValue("{s:s,s:i}", "Type", "Private", "Value", entry->Entries[i].Number); break; case PBK_Text_StreetAddress: convert_text("Text_StreetAddress"); break; case PBK_Text_City: convert_text("Text_City"); break; case PBK_Text_State: convert_text("Text_State"); break; case PBK_Text_Zip: convert_text("Text_Zip"); break; case PBK_Text_Country: convert_text("Text_Country"); break; case PBK_Text_Custom1: convert_text("Text_Custom1"); break; case PBK_Text_Custom2: convert_text("Text_Custom2"); break; case PBK_Text_Custom3: convert_text("Text_Custom3"); break; case PBK_Text_Custom4: convert_text("Text_Custom4"); break; case PBK_Text_LUID: convert_text("Text_LUID"); break; case PBK_Text_VOIP: convert_text("Text_VOIP"); break; case PBK_Text_SWIS: convert_text("Text_SWIS"); break; case PBK_Text_WVID: convert_text("Text_WVID"); break; case PBK_Text_SIP: convert_text("Text_SIP"); break; case PBK_Text_DTMF: convert_text("Text_DTMF"); break; case PBK_Text_UserID: convert_text("Text_UserID"); break; case PBK_Text_PictureName: convert_text("Text_PictureName"); break; case PBK_RingtoneID: f = Py_BuildValue("{s:s,s:O}", "Type", "RingtoneID", "Value", PyLong_FromUnsignedLong (entry->Entries[i].Number)); break; case PBK_PictureID: f = Py_BuildValue("{s:s,s:O}", "Type", "PictureID", "Value", PyLong_FromUnsignedLong (entry->Entries[i].Number)); break; case PBK_CallLength: f = Py_BuildValue("{s:s,s:i}", "Type", "CallLength", "Value", entry->Entries[i].CallLength); break; case PBK_Number_Messaging: convert_number("Messaging"); break; case PBK_Number_Video: convert_number("Video"); break; case PBK_PushToTalkID: convert_text("PushToTalkID"); break; case PBK_Photo: bitmap = &(entry->Entries[i].Picture); d = PyString_FromStringAndSize((char *)bitmap-> Buffer, bitmap->Length); if (d == NULL) { Py_DECREF(v); return NULL; } bmptype = ""; switch (bitmap->Type) { case PICTURE_BMP: bmptype = "BMP"; break; case PICTURE_GIF: bmptype = "GIF"; break; case PICTURE_JPG: bmptype = "JPG"; break; case PICTURE_ICN: bmptype = "ICN"; break; case PICTURE_PNG: bmptype = "PNG"; break; } f = Py_BuildValue("{s:s,s:O,s:s}", "Type", "Photo", "Value", d, "PictureType", bmptype); Py_DECREF(d); break; } if (f == Py_None) { Py_DECREF(v); PyErr_Format(PyExc_ValueError, "Bad MemoryEntry item type from gammu: %d", entry->Entries[i].EntryType); return NULL; } if (f == NULL) { Py_DECREF(v); return NULL; } if (PyList_Append(v, f) != 0) { Py_DECREF(f); Py_DECREF(v); return NULL; } Py_DECREF(f); } t = MemoryTypeToString(entry->MemoryType); if (t == NULL) { Py_DECREF(v); return NULL; } r = Py_BuildValue("{s:i,s:s,s:O}", "Location", entry->Location, "MemoryType", t, "Entries", v); free(t); Py_DECREF(v); return r; }
PyObject *TodoToPython(const GSM_ToDoEntry * entry) { PyObject *v; PyObject *f; PyObject *r; PyObject *d; int i; Py_UNICODE *s; char *p; char *t; v = PyList_New(0); if (v == NULL) return NULL; for (i = 0; i < entry->EntriesNum; i++) { f = Py_None; switch (entry->Entries[i].EntryType) { case TODO_END_DATETIME: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "END_DATETIME", "Value", d); Py_DECREF(d); break; case TODO_START_DATETIME: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "START_DATETIME", "Value", d); Py_DECREF(d); break; case TODO_COMPLETED_DATETIME: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "COMPLETED_DATETIME", "Value", d); Py_DECREF(d); break; case TODO_ALARM_DATETIME: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "ALARM_DATETIME", "Value", d); Py_DECREF(d); break; case TODO_SILENT_ALARM_DATETIME: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "SILENT_ALARM_DATETIME", "Value", d); Py_DECREF(d); break; case TODO_LAST_MODIFIED: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O}", "Type", "LAST_MODIFIED", "Value", d); Py_DECREF(d); break; case TODO_TEXT: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u}", "Type", "TEXT", "Value", s); free(s); break; case TODO_LOCATION: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u}", "Type", "LOCATION", "Value", s); free(s); break; case TODO_DESCRIPTION: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u}", "Type", "DESCRIPTION", "Value", s); free(s); break; case TODO_LUID: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u}", "Type", "LUID", "Value", s); free(s); break; case TODO_COMPLETED: f = Py_BuildValue("{s:s,s:i}", "Type", "COMPLETED", "Value", entry->Entries[i].Number); break; case TODO_PRIVATE: f = Py_BuildValue("{s:s,s:i}", "Type", "PRIVATE", "Value", entry->Entries[i].Number); break; case TODO_CATEGORY: f = Py_BuildValue("{s:s,s:i}", "Type", "CATEGORY", "Value", entry->Entries[i].Number); break; case TODO_CONTACTID: f = Py_BuildValue("{s:s,s:i}", "Type", "CONTACTID", "Value", entry->Entries[i].Number); break; case TODO_PHONE: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u}", "Type", "PHONE", "Value", s); free(s); break; } if (f == Py_None) { Py_DECREF(v); PyErr_Format(PyExc_ValueError, "Bad ToDo item type from gammu: %d", entry->Entries[i].EntryType); return NULL; } if (f == NULL) { Py_DECREF(v); return NULL; } if (PyList_Append(v, f) != 0) { Py_DECREF(f); Py_DECREF(v); return NULL; } Py_DECREF(f); } p = TodoPriorityToString(entry->Priority); if (p == NULL) { Py_DECREF(v); return NULL; } t = CalendarTypeToString(entry->Type); if (t == NULL) { free(p); Py_DECREF(v); return NULL; } r = Py_BuildValue("{s:i,s:s,s:s,s:O}", "Location", entry->Location, "Type", t, "Priority", p, "Entries", v); free(p); free(t); Py_DECREF(v); return r; }
PyObject *CalendarToPython(const GSM_CalendarEntry * entry) { PyObject *v; PyObject *f; PyObject *r; PyObject *d; int i; Py_UNICODE *s; char *t; GSM_DateTime dt; int ignore; v = PyList_New(0); if (v == NULL) return NULL; for (i = 0; i < entry->EntriesNum; i++) { f = Py_None; ignore = 0; switch (entry->Entries[i].EntryType) { case CAL_START_DATETIME: /* Fixup date */ dt = entry->Entries[i].Date; if (dt.Hour == 255) { dt.Hour = 0; } if (dt.Minute == 255) { dt.Minute = 0; } if (dt.Second == 255) { dt.Second = 0; } d = BuildPythonDateTime(&dt); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O,s:i}", "Type", "START_DATETIME", "Value", d, "AddError", (int)entry->Entries[i]. AddError); Py_DECREF(d); break; case CAL_END_DATETIME: /* Fixup date */ dt = entry->Entries[i].Date; if (dt.Year == 0) { /* Ignore, there can be none end date. */ ignore = 1; break; } if (dt.Hour == 255) { dt.Hour = 23; } if (dt.Minute == 255) { dt.Minute = 59; } if (dt.Second == 255) { dt.Second = 59; } d = BuildPythonDateTime(&dt); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O,s:i}", "Type", "END_DATETIME", "Value", d, "AddError", (int)entry->Entries[i]. AddError); Py_DECREF(d); break; case CAL_TONE_ALARM_DATETIME: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O,s:i}", "Type", "TONE_ALARM_DATETIME", "Value", d, "AddError", (int)entry->Entries[i]. AddError); Py_DECREF(d); break; case CAL_SILENT_ALARM_DATETIME: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O,s:i}", "Type", "SILENT_ALARM_DATETIME", "Value", d, "AddError", (int)entry->Entries[i]. AddError); Py_DECREF(d); break; case CAL_LAST_MODIFIED: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O,s:i}", "Type", "LAST_MODIFIED", "Value", d, "AddError", (int)entry->Entries[i]. AddError); Py_DECREF(d); break; case CAL_REPEAT_STARTDATE: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O,s:i}", "Type", "REPEAT_STARTDATE", "Value", d, "AddError", (int)entry->Entries[i]. AddError); Py_DECREF(d); break; case CAL_REPEAT_STOPDATE: d = BuildPythonDateTime(& (entry->Entries[i]. Date)); if (d == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:O,s:i}", "Type", "REPEAT_STOPDATE", "Value", d, "AddError", (int)entry->Entries[i]. AddError); Py_DECREF(d); break; case CAL_TEXT: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u,s:i}", "Type", "TEXT", "Value", s, "AddError", (int)entry->Entries[i]. AddError); free(s); break; case CAL_DESCRIPTION: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u,s:i}", "Type", "DESCRIPTION", "Value", s, "AddError", (int)entry->Entries[i]. AddError); free(s); break; case CAL_LUID: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u,s:i}", "Type", "LUID", "Value", s, "AddError", (int)entry->Entries[i]. AddError); free(s); break; case CAL_LOCATION: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u,s:i}", "Type", "LOCATION", "Value", s, "AddError", (int)entry->Entries[i]. AddError); free(s); break; case CAL_PHONE: s = strGammuToPython(entry->Entries[i].Text); if (s == NULL) { Py_DECREF(v); return NULL; } f = Py_BuildValue("{s:s,s:u,s:i}", "Type", "PHONE", "Value", s, "AddError", (int)entry->Entries[i]. AddError); free(s); break; case CAL_PRIVATE: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "PRIVATE", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_CONTACTID: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "CONTACTID", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_REPEAT_DAYOFWEEK: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "REPEAT_DAYOFWEEK", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_REPEAT_DAY: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "REPEAT_DAY", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_REPEAT_WEEKOFMONTH: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "REPEAT_WEEKOFMONTH", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_REPEAT_MONTH: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "REPEAT_MONTH", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_REPEAT_FREQUENCY: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "REPEAT_FREQUENCY", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_REPEAT_COUNT: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "REPEAT_COUNT", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; case CAL_REPEAT_DAYOFYEAR: f = Py_BuildValue("{s:s,s:i,s:i}", "Type", "REPEAT_DAYOFYEAR", "Value", entry->Entries[i].Number, "AddError", (int)entry->Entries[i]. AddError); break; } if (ignore) { continue; } if (f == Py_None) { Py_DECREF(v); PyErr_Format(PyExc_ValueError, "Bad Calendar item type from gammu: %d", entry->Entries[i].EntryType); return NULL; } if (f == NULL) { Py_DECREF(v); return NULL; } if (PyList_Append(v, f) != 0) { Py_DECREF(f); Py_DECREF(v); return NULL; } Py_DECREF(f); } t = CalendarTypeToString(entry->Type); if (t == NULL) { Py_DECREF(v); return NULL; } r = Py_BuildValue("{s:i,s:s,s:O}", "Location", entry->Location, "Type", t, "Entries", v); free(t); Py_DECREF(v); return r; }
PyObject *BackupToPython(GSM_Backup * backup) { PyObject *phone; PyObject *sim; PyObject *calendar; PyObject *todo; PyObject *o; PyObject *dt; int i; phone = PyList_New(0); for (i = 0; backup->PhonePhonebook[i] != NULL; i++) { o = MemoryEntryToPython(backup->PhonePhonebook[i]); if (o == NULL) { Py_DECREF(phone); return NULL; } PyList_Append(phone, o); Py_DECREF(o); } sim = PyList_New(0); for (i = 0; backup->SIMPhonebook[i] != NULL; i++) { o = MemoryEntryToPython(backup->SIMPhonebook[i]); if (o == NULL) { Py_DECREF(sim); return NULL; } PyList_Append(sim, o); Py_DECREF(o); } todo = PyList_New(0); for (i = 0; backup->ToDo[i] != NULL; i++) { o = TodoToPython(backup->ToDo[i]); if (o == NULL) { Py_DECREF(todo); return NULL; } PyList_Append(todo, o); Py_DECREF(o); } calendar = PyList_New(0); for (i = 0; backup->Calendar[i] != NULL; i++) { o = CalendarToPython(backup->Calendar[i]); if (o == NULL) { Py_DECREF(calendar); return NULL; } PyList_Append(calendar, o); Py_DECREF(o); } if (backup->DateTimeAvailable) { dt = BuildPythonDateTime(&backup->DateTime); if (dt == NULL) { PyErr_Clear(); Py_INCREF(Py_None); dt = Py_None; } } else { Py_INCREF(Py_None); dt = Py_None; } o = Py_BuildValue( "{s:s,s:s,s:s,s:O,s:O,s:O,s:O,s:O}", "IMEI", backup->IMEI, "Model", backup->Model, "Creator", backup->Creator, "PhonePhonebook", phone, "SIMPhonebook", sim, "Calendar", calendar, "ToDo", todo, "DateTime", dt ); Py_DECREF(phone); Py_DECREF(sim); Py_DECREF(calendar); Py_DECREF(todo); Py_DECREF(dt); return o; }
PyObject *FileToPython(GSM_File * file) { PyObject *name; PyObject *fullname; PyObject *buffer; PyObject *dt; char *type; PyObject *val; name = UnicodeStringToPython(file->Name); if (name == NULL) { return NULL; } type = FileTypeToString(file->Type); if (type == NULL) { Py_DECREF(name); return NULL; } fullname = UnicodeStringToPython(file->ID_FullName); if (fullname == NULL) { Py_DECREF(name); free(type); return NULL; } buffer = PyString_FromStringAndSize((char *)file->Buffer, file->Used); if (buffer == NULL) { Py_DECREF(name); free(type); Py_DECREF(fullname); return NULL; } if (file->ModifiedEmpty) { file->Modified.Year = 0; } dt = BuildPythonDateTime(&(file->Modified)); if (dt == NULL) { Py_DECREF(name); free(type); Py_DECREF(fullname); Py_DECREF(buffer); return NULL; } val = Py_BuildValue("{s:i,s:O,s:i,s:i,s:s,s:O,s:O,s:O,s:i,s:i,s:i,s:i}", "Used", file->Used, "Name", name, "Folder", (int)file->Folder, "Level", file->Level, "Type", type, "ID_FullName", fullname, "Buffer", buffer, "Modified", dt, "Protected", (int)file->Protected, "ReadOnly", (int)file->ReadOnly, "Hidden", (int)file->Hidden, "System", (int)file->System); Py_DECREF(name); free(type); Py_DECREF(fullname); Py_DECREF(buffer); Py_DECREF(dt); return val; }