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 *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 *BitmapToPython(GSM_Bitmap * bitmap) { char buffer[1000]; size_t x, y; PyObject *xpmval; PyObject *s; char *t; Py_UNICODE *txt; Py_UNICODE *sendr; PyObject *val; xpmval = PyList_New(0); if (xpmval == NULL) return NULL; #if 0 /* Not needed as BitmapWidth is char */ if (bitmap->BitmapWidth > 999) { PyErr_SetString(PyExc_MemoryError, "Maximal supported bitmap width is 999 for now!"); return NULL; } #endif snprintf(buffer, 99, "%i %i 2 1", (int)bitmap->BitmapWidth, (int)bitmap->BitmapHeight); s = PyString_FromString(buffer); if (s == NULL) return NULL; if (PyList_Append(xpmval, s) != 0) { Py_DECREF(xpmval); Py_DECREF(s); return NULL; } Py_DECREF(s); s = PyString_FromString("# c Black"); if (s == NULL) return NULL; if (PyList_Append(xpmval, s) != 0) { Py_DECREF(xpmval); Py_DECREF(s); return NULL; } Py_DECREF(s); s = PyString_FromString(" c None"); if (s == NULL) return NULL; if (PyList_Append(xpmval, s) != 0) { Py_DECREF(xpmval); Py_DECREF(s); return NULL; } Py_DECREF(s); buffer[bitmap->BitmapWidth] = 0; for (y = 0; y < bitmap->BitmapHeight; y++) { for (x = 0; x < bitmap->BitmapWidth; x++) { buffer[x] = GSM_IsPointBitmap(bitmap, x, y) ? '#' : ' '; } s = PyString_FromString(buffer); if (s == NULL) return NULL; if (PyList_Append(xpmval, s) != 0) { Py_DECREF(xpmval); Py_DECREF(s); return NULL; } Py_DECREF(s); } t = BitmapTypeToString(bitmap->Type); if (t == NULL) { Py_DECREF(xpmval); return NULL; } txt = strGammuToPython(bitmap->Text); if (txt == NULL) { Py_DECREF(xpmval); free(t); return NULL; } sendr = strGammuToPython(bitmap->Sender); if (sendr == NULL) { Py_DECREF(xpmval); free(t); free(txt); return NULL; } val = Py_BuildValue("{s:s,s:i,s:u,s:i,s:i,s:i,s:i,s:i,s:i,s:O,s:u,s:s}", "Type", t, "Location", (int)bitmap->Location, "Text", txt, "Enabled", (int)bitmap->BitmapEnabled, "DefaultName", (int)bitmap->DefaultName, "DefaultBitmap", (int)bitmap->DefaultBitmap, "DefaultRingtone", (int)bitmap->DefaultRingtone, "RingtoneID", (int)bitmap->RingtoneID, "ID", (int)bitmap->ID, "XPM", xpmval, "Sender", sendr, "NetworkCode", bitmap->NetworkCode); Py_DECREF(xpmval); free(t); free(txt); free(sendr); return val; }