| 79 | */ |
| 80 | |
| 81 | mime_type_t * /* O - New (or existing) MIME type */ |
| 82 | mimeAddType(mime_t *mime, /* I - MIME database */ |
| 83 | const char *super, /* I - Super-type name */ |
| 84 | const char *type) /* I - Type name */ |
| 85 | { |
| 86 | mime_type_t *temp; /* New MIME type */ |
| 87 | size_t typelen; /* Length of type name */ |
| 88 | |
| 89 | |
| 90 | DEBUG_printf(("mimeAddType(mime=%p, super=\"%s\", type=\"%s\")", mime, super, |
| 91 | type)); |
| 92 | |
| 93 | /* |
| 94 | * Range check input... |
| 95 | */ |
| 96 | |
| 97 | if (!mime || !super || !type) |
| 98 | { |
| 99 | DEBUG_puts("1mimeAddType: Returning NULL (bad arguments)."); |
| 100 | return (NULL); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * See if the type already exists; if so, return the existing type... |
| 105 | */ |
| 106 | |
| 107 | if ((temp = mimeType(mime, super, type)) != NULL) |
| 108 | { |
| 109 | DEBUG_printf(("1mimeAddType: Returning %p (existing).", temp)); |
| 110 | return (temp); |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * The type doesn't exist; add it... |
| 115 | */ |
| 116 | |
| 117 | if (!mime->types) |
| 118 | mime->types = cupsArrayNew((cups_array_func_t)mime_compare_types, NULL); |
| 119 | |
| 120 | if (!mime->types) |
| 121 | { |
| 122 | DEBUG_puts("1mimeAddType: Returning NULL (no types)."); |
| 123 | return (NULL); |
| 124 | } |
| 125 | |
| 126 | typelen = strlen(type) + 1; |
| 127 | |
| 128 | if ((temp = calloc(1, sizeof(mime_type_t) - MIME_MAX_TYPE + typelen)) == NULL) |
| 129 | { |
| 130 | DEBUG_puts("1mimeAddType: Returning NULL (out of memory)."); |
| 131 | return (NULL); |
| 132 | } |
| 133 | |
| 134 | strlcpy(temp->super, super, sizeof(temp->super)); |
| 135 | memcpy(temp->type, type, typelen); |
| 136 | temp->priority = 100; |
| 137 | |
| 138 | cupsArrayAdd(mime->types, temp); |