| 1459 return field->u.certificate.cert; |
1459 return field->u.certificate.cert; |
| 1460 } |
1460 } |
| 1461 |
1461 |
| 1462 /* -- */ |
1462 /* -- */ |
| 1463 |
1463 |
| |
1464 gboolean |
| |
1465 purple_request_field_email_validator(PurpleRequestField *field, gchar **errmsg, |
| |
1466 void *user_data) |
| |
1467 { |
| |
1468 const char *value; |
| |
1469 |
| |
1470 g_return_val_if_fail(field != NULL, FALSE); |
| |
1471 g_return_val_if_fail(field->type == PURPLE_REQUEST_FIELD_STRING, FALSE); |
| |
1472 |
| |
1473 value = purple_request_field_string_get_value(field); |
| |
1474 |
| |
1475 if (value != NULL && purple_email_is_valid(value)) |
| |
1476 return TRUE; |
| |
1477 |
| |
1478 if (errmsg) |
| |
1479 *errmsg = g_strdup(_("Invalid email address")); |
| |
1480 return FALSE; |
| |
1481 } |
| |
1482 |
| |
1483 gboolean |
| |
1484 purple_request_field_alphanumeric_validator(PurpleRequestField *field, |
| |
1485 gchar **errmsg, void *allowed_characters) |
| |
1486 { |
| |
1487 const char *value; |
| |
1488 gchar invalid_char = '\0'; |
| |
1489 |
| |
1490 g_return_val_if_fail(field != NULL, FALSE); |
| |
1491 g_return_val_if_fail(field->type == PURPLE_REQUEST_FIELD_STRING, FALSE); |
| |
1492 |
| |
1493 value = purple_request_field_string_get_value(field); |
| |
1494 |
| |
1495 g_return_val_if_fail(value != NULL, FALSE); |
| |
1496 |
| |
1497 if (allowed_characters) |
| |
1498 { |
| |
1499 gchar *value_r = g_strdup(value); |
| |
1500 g_strcanon(value_r, allowed_characters, '\0'); |
| |
1501 invalid_char = value[strlen(value_r)]; |
| |
1502 g_free(value_r); |
| |
1503 } |
| |
1504 else |
| |
1505 { |
| |
1506 while (value) |
| |
1507 { |
| |
1508 if (!g_ascii_isalnum(*value)) |
| |
1509 { |
| |
1510 invalid_char = *value; |
| |
1511 break; |
| |
1512 } |
| |
1513 value++; |
| |
1514 } |
| |
1515 } |
| |
1516 if (!invalid_char) |
| |
1517 return TRUE; |
| |
1518 |
| |
1519 if (errmsg) |
| |
1520 *errmsg = g_strdup_printf(_("Invalid character '%c'"), |
| |
1521 invalid_char); |
| |
1522 return FALSE; |
| |
1523 } |
| |
1524 |
| |
1525 gboolean purple_request_field_numeric_validator(PurpleRequestField *field, |
| |
1526 gchar **errmsg, void *range_p) |
| |
1527 { |
| |
1528 gboolean succ = TRUE; |
| |
1529 int value = 0; |
| |
1530 int *range = range_p; |
| |
1531 |
| |
1532 g_return_val_if_fail(field != NULL, FALSE); |
| |
1533 g_return_val_if_fail(field->type == PURPLE_REQUEST_FIELD_STRING || |
| |
1534 field->type == PURPLE_REQUEST_FIELD_INTEGER, FALSE); |
| |
1535 |
| |
1536 if (field->type == PURPLE_REQUEST_FIELD_STRING) |
| |
1537 { |
| |
1538 const gchar *svalue, *it; |
| |
1539 svalue = purple_request_field_string_get_value(field); |
| |
1540 if (svalue == NULL || svalue[0] == '\0') |
| |
1541 succ = FALSE; |
| |
1542 it = svalue; |
| |
1543 if (it[0] == '-') |
| |
1544 it++; |
| |
1545 while (succ && *it) |
| |
1546 { |
| |
1547 if (!g_ascii_isdigit(*it)) |
| |
1548 succ = FALSE; |
| |
1549 it++; |
| |
1550 } |
| |
1551 if (succ) |
| |
1552 { |
| |
1553 char *endptr; |
| |
1554 value = strtol(svalue, &endptr, 10); |
| |
1555 succ = (errno != ERANGE && endptr[0] == '\0'); |
| |
1556 } |
| |
1557 } |
| |
1558 // TODO: integer fields doesn't seems to work, so this one needs testing |
| |
1559 else if (field->type == PURPLE_REQUEST_FIELD_INTEGER) |
| |
1560 value = purple_request_field_int_get_value(field); |
| |
1561 else |
| |
1562 g_return_val_if_reached(FALSE); |
| |
1563 |
| |
1564 if (succ && range) |
| |
1565 succ = (value >= range[0] && value <= range[1]); |
| |
1566 |
| |
1567 if (succ) |
| |
1568 return TRUE; |
| |
1569 |
| |
1570 if (errmsg && !range) |
| |
1571 *errmsg = g_strdup(_("Invalid number")); |
| |
1572 if (errmsg && range) |
| |
1573 *errmsg = g_strdup_printf(_("Value is not between %d and %d"), |
| |
1574 range[0], range[1]); |
| |
1575 return FALSE; |
| |
1576 } |
| |
1577 |
| |
1578 /* -- */ |
| |
1579 |
| 1464 void * |
1580 void * |
| 1465 purple_request_input(void *handle, const char *title, const char *primary, |
1581 purple_request_input(void *handle, const char *title, const char *primary, |
| 1466 const char *secondary, const char *default_value, |
1582 const char *secondary, const char *default_value, |
| 1467 gboolean multiline, gboolean masked, gchar *hint, |
1583 gboolean multiline, gboolean masked, gchar *hint, |
| 1468 const char *ok_text, GCallback ok_cb, |
1584 const char *ok_text, GCallback ok_cb, |